feature update json data for safe read server res.

This commit is contained in:
alves
2026-01-06 14:35:27 +08:00
parent 5d611bad08
commit 3d2d7f556b
2 changed files with 53 additions and 29 deletions

View File

@@ -4773,22 +4773,35 @@ void GUI_App::check_new_version_sf(bool show_tips, bool by_user)
return;
}
try {
json jsonData = json::parse(body);
auto errCode = jsonData["code"];
json jsonObj = json::parse(body);
auto errCode = jsonObj["code"];
if (errCode != 200)
return;
auto isFullUpgrade = jsonData["data"]["is_full_upgrade"];
auto isForceUpgrade = jsonData["data"]["is_force_upgrade"];
auto versionType = jsonData["data"]["stable"];
auto softPlatform = jsonData["data"]["platform_type"];
version_info.version_str = jsonData["data"]["version"];
auto fileSize = jsonData["data"]["full"]["file_size"];
auto fileMd5 = jsonData["data"]["full"]["file_md5"];
auto fileSha256 = jsonData["data"]["full"]["file_sha256"];
//windows x86_x64, mac arm/x86_x64 universal
version_info.url = jsonData["data"]["full"]["file_url"];
version_info.description = jsonData["data"]["full"]["file_describe"];
auto dataObj = jsonObj.value("data", json::object());
auto isFullUpgrade = dataObj.value("is_full_upgrade", true);
auto isForceUpgrade = dataObj.value("is_force_upgrade", false);
version_info.version_str = dataObj.value("version", "");
auto releaseType = dataObj.value("release_type", "");
auto platformType = dataObj.value("platform_type", "");
int fileSize = 0;
std::string fileMd5 = "";
std::string fileSha256 = "";
std::string reservedData = "";
std::string reservedData2 = "";
auto fullObj = dataObj.value("full", json::object());
fileSize = fullObj.value("file_size", 0);
fileMd5 = fullObj.value("file_md5", "");
fileSha256 = fullObj.value("file_sha256", "");
// windows x86_x64, mac arm/x86_x64 universal
version_info.url = fullObj.value("file_url", "");
version_info.description = fullObj.value("file_describe", "");
reservedData = fullObj.value("reserved_1", "");
reservedData2 = fullObj.value("reserved_2", "");
version_info.force_upgrade = isForceUpgrade;
std::regex matcher("[0-9]+\\.[0-9]+(\\.[0-9]+)*(-[A-Za-z0-9]+)?(\\+[A-Za-z0-9]+)?");

View File

@@ -727,7 +727,6 @@ void PresetUpdater::priv::sync_update_flutter_resource(bool isAuto_check)
wxString errorMsg = wxString::Format(_L("request to server update web resource fail with body:%s,error:%s,status:%d"), body, error, http_status);
evt->SetString(errorMsg);
GUI::wxGetApp().QueueEvent(evt);
GUI::wxGetApp().QueueEvent(evt);
BOOST_LOG_TRIVIAL(info) << format("Error getting: `%1%`: HTTP %2%, %3%", "sync_update_flutter_resource", http_status, error);
})
.timeout_connect(TIMEOUT_CONNECT)
@@ -753,8 +752,8 @@ void PresetUpdater::priv::sync_update_flutter_resource(bool isAuto_check)
auto fileSha256 = dataObj.value("file_sha256", "");
auto fileUrl = dataObj.value("file_url", "");
auto description = dataObj.value("file_describe", "");
auto reserveData = dataObj.value("reserve_1", "");
auto reserveData2 = dataObj.value("reserve_2", "");
auto reservedData = dataObj.value("reserved_1", "");
auto reservedData2 = dataObj.value("reserved_2", "");
auto localProfilesjson = cache_path / "flutter_web/version.json";
std::string json_path = data_dir() + "/web/flutter_web/version.json";
@@ -834,22 +833,24 @@ void PresetUpdater::priv::sync_config(bool isAuto_check)
if (http_status != 200)
return;
try {
json jsonData = json::parse(body);
auto errCode = jsonData["code"];
json jsonObj = json::parse(body);
auto errCode = jsonObj["code"];
if (errCode != 200)
return;
auto isForceUpgrade = jsonData["data"]["is_force_upgrade"];
auto minSupportPcVersion = jsonData["data"]["min_support_pc_version"];
auto maxSupportPcVersion = jsonData["data"]["max_support_pc_version"];
auto fileVersion = jsonData["data"]["file_version"];
auto fileSize = jsonData["data"]["file_size"];
auto fileMd5 = jsonData["data"]["file_md5"];
auto fileSha256 = jsonData["data"]["file_sha256"];
auto fileUrl = jsonData["data"]["file_url"];
auto description = jsonData["data"]["file_describe"];
auto reserverData = jsonData["data"]["reserver_1"];
auto reserverData2 = jsonData["data"]["reserver_2"];
auto dataObj = jsonObj.value("data", json::object());
auto isForceUpgrade = dataObj.value("is_force_upgrade", false);
auto minSupportPcVersion = dataObj.value("min_support_pc_version", "");
auto maxSupportPcVersion = dataObj.value("max_support_pc_version", "");
auto fileVersion = dataObj.value("file_version", "");
auto fileSize = dataObj.value("file_size", 0);
auto fileMd5 = dataObj.value("file_md5", "");
auto fileSha256 = dataObj.value("file_sha256", "");
auto fileUrl = dataObj.value("file_url", "");
auto description = dataObj.value("file_describe", "");
auto reservedData = dataObj.value("reserved_1", "");
auto reservedData2 = dataObj.value("reserved_2", "");
auto localProfilesjson = cache_path / "profiles/Snapmaker.json";
std::string json_path = data_dir() + "/system/Snapmaker.json";
@@ -857,6 +858,16 @@ void PresetUpdater::priv::sync_config(bool isAuto_check)
Semver currentPresetVersion = get_version_from_json(json_path);
Semver remoteVersion(fileVersion);
if (fileVersion.empty()) {
if (!isAuto_check) {
wxCommandEvent* evt = new wxCommandEvent(EVT_NO_PRESET_UPDATE);
GUI::wxGetApp().QueueEvent(evt);
BOOST_LOG_TRIVIAL(info) << format("use check the web update.");
}
return;
}
std::string localOtaPresetVersion = "";
if (fs::exists(localProfilesjson)) {
Semver localOtaVersion = get_version_from_json(localProfilesjson.string());