FIX:fixed incorrect HMS content

jira:[STUDIO-5818]

Change-Id: Ia2896d6f0ab1ffedbc850e54168acece8e47bdbb
This commit is contained in:
tao wang 2024-01-05 16:09:26 +08:00 committed by Lane.Wei
parent 5223469c40
commit 9a09930e8f
2 changed files with 22 additions and 15 deletions

View File

@ -17,7 +17,8 @@ int get_hms_info_version(std::string& version)
} }
int result = -1; int result = -1;
version = ""; version = "";
std::string query_params = HMSQuery::build_query_params(); std::string lang;
std::string query_params = HMSQuery::build_query_params(lang);
std::string url = (boost::format("https://%1%/GetVersion.php?%2%") % hms_host % query_params).str(); std::string url = (boost::format("https://%1%/GetVersion.php?%2%") % hms_host % query_params).str();
Slic3r::Http http = Slic3r::Http::get(url); Slic3r::Http http = Slic3r::Http::get(url);
http.timeout_max(10) http.timeout_max(10)
@ -45,13 +46,14 @@ int HMSQuery::download_hms_info()
if (!config) return -1; if (!config) return -1;
std::string hms_host = wxGetApp().app_config->get_hms_host(); std::string hms_host = wxGetApp().app_config->get_hms_host();
std::string query_params = HMSQuery::build_query_params(); std::string lang;
std::string query_params = HMSQuery::build_query_params(lang);
std::string url = (boost::format("https://%1%/query.php?%2%") % hms_host % query_params).str(); std::string url = (boost::format("https://%1%/query.php?%2%") % hms_host % query_params).str();
BOOST_LOG_TRIVIAL(info) << "hms: download url = " << url; BOOST_LOG_TRIVIAL(info) << "hms: download url = " << url;
Slic3r::Http http = Slic3r::Http::get(url); Slic3r::Http http = Slic3r::Http::get(url);
m_hms_json.clear();
http.on_complete([this](std::string body, unsigned status) { http.on_complete([this](std::string body, unsigned status) {
try { try {
json j = json::parse(body); json j = json::parse(body);
@ -74,7 +76,8 @@ int HMSQuery::download_hms_info()
BOOST_LOG_TRIVIAL(error) << "HMSQuery: update hms info error = " << error << ", body = " << body << ", status = " << status; BOOST_LOG_TRIVIAL(error) << "HMSQuery: update hms info error = " << error << ", body = " << body << ", status = " << status;
}).perform_sync(); }).perform_sync();
save_to_local(); if (!m_hms_json.empty())
save_to_local(lang);
return 0; return 0;
} }
@ -85,7 +88,7 @@ int HMSQuery::load_from_local(std::string &version_info)
BOOST_LOG_TRIVIAL(error) << "HMS: load_from_local, data_dir() is empty"; BOOST_LOG_TRIVIAL(error) << "HMS: load_from_local, data_dir() is empty";
return -1; return -1;
} }
std::string filename = get_hms_file(); std::string filename = get_hms_file(HMSQuery::hms_language_code());
auto hms_folder = (boost::filesystem::path(data_dir()) / "hms"); auto hms_folder = (boost::filesystem::path(data_dir()) / "hms");
if (!fs::exists(hms_folder)) if (!fs::exists(hms_folder))
fs::create_directory(hms_folder); fs::create_directory(hms_folder);
@ -112,13 +115,13 @@ int HMSQuery::load_from_local(std::string &version_info)
return 0; return 0;
} }
int HMSQuery::save_to_local() int HMSQuery::save_to_local(std::string lang)
{ {
if (data_dir().empty()) { if (data_dir().empty()) {
BOOST_LOG_TRIVIAL(error) << "HMS: save_to_local, data_dir() is empty"; BOOST_LOG_TRIVIAL(error) << "HMS: save_to_local, data_dir() is empty";
return -1; return -1;
} }
std::string filename = get_hms_file(); std::string filename = get_hms_file(lang);
auto hms_folder = (boost::filesystem::path(data_dir()) / "hms"); auto hms_folder = (boost::filesystem::path(data_dir()) / "hms");
if (!fs::exists(hms_folder)) if (!fs::exists(hms_folder))
fs::create_directory(hms_folder); fs::create_directory(hms_folder);
@ -153,17 +156,18 @@ std::string HMSQuery::hms_language_code()
return lang_code; return lang_code;
} }
std::string HMSQuery::build_query_params() std::string HMSQuery::build_query_params(std::string& lang)
{ {
std::string lang_code = HMSQuery::hms_language_code(); std::string lang_code = HMSQuery::hms_language_code();
lang = lang_code;
std::string query_params = (boost::format("lang=%1%") % lang_code).str(); std::string query_params = (boost::format("lang=%1%") % lang_code).str();
return query_params; return query_params;
} }
std::string HMSQuery::get_hms_file() std::string HMSQuery::get_hms_file(std::string lang)
{ {
std::string lang_code = HMSQuery::hms_language_code(); //std::string lang_code = HMSQuery::hms_language_code();
return (boost::format("hms_%1%.json") % lang_code).str(); return (boost::format("hms_%1%.json") % lang).str();
} }
wxString HMSQuery::query_hms_msg(std::string long_error_code) wxString HMSQuery::query_hms_msg(std::string long_error_code)
@ -271,6 +275,9 @@ int HMSQuery::check_hms_info()
std::string new_version; std::string new_version;
get_hms_info_version(new_version); get_hms_info_version(new_version);
BOOST_LOG_TRIVIAL(info) << "HMS: check_hms_info latest version = " << new_version; BOOST_LOG_TRIVIAL(info) << "HMS: check_hms_info latest version = " << new_version;
if (new_version.empty()) {return 0;}
if (!version.empty() && version == new_version) { if (!version.empty() && version == new_version) {
download_new_hms_info = false; download_new_hms_info = false;
} }
@ -280,7 +287,7 @@ int HMSQuery::check_hms_info()
if (download_new_hms_info) { if (download_new_hms_info) {
download_hms_info(); download_hms_info();
} }
return; return 0;
}); });
return 0; return 0;
} }

View File

@ -22,8 +22,8 @@ protected:
json m_hms_json; json m_hms_json;
int download_hms_info(); int download_hms_info();
int load_from_local(std::string& version_info); int load_from_local(std::string& version_info);
int save_to_local(); int save_to_local(std::string lang);
std::string get_hms_file(); std::string get_hms_file(std::string lang);
wxString _query_hms_msg(std::string long_error_code, std::string lang_code = "en"); wxString _query_hms_msg(std::string long_error_code, std::string lang_code = "en");
wxString _query_error_msg(std::string long_error_code, std::string lang_code = "en"); wxString _query_error_msg(std::string long_error_code, std::string lang_code = "en");
public: public:
@ -32,7 +32,7 @@ public:
wxString query_hms_msg(std::string long_error_code); wxString query_hms_msg(std::string long_error_code);
wxString query_print_error_msg(int print_error); wxString query_print_error_msg(int print_error);
static std::string hms_language_code(); static std::string hms_language_code();
static std::string build_query_params(); static std::string build_query_params(std::string& lang);
}; };
int get_hms_info_version(std::string &version); int get_hms_info_version(std::string &version);