FIX:fixed incorrect HMS content
jira:[STUDIO-5818] Change-Id: Ia2896d6f0ab1ffedbc850e54168acece8e47bdbb
This commit is contained in:
parent
5223469c40
commit
9a09930e8f
|
@ -17,7 +17,8 @@ int get_hms_info_version(std::string& version)
|
|||
}
|
||||
int result = -1;
|
||||
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();
|
||||
Slic3r::Http http = Slic3r::Http::get(url);
|
||||
http.timeout_max(10)
|
||||
|
@ -45,13 +46,14 @@ int HMSQuery::download_hms_info()
|
|||
if (!config) return -1;
|
||||
|
||||
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();
|
||||
|
||||
BOOST_LOG_TRIVIAL(info) << "hms: download url = " << url;
|
||||
|
||||
Slic3r::Http http = Slic3r::Http::get(url);
|
||||
|
||||
m_hms_json.clear();
|
||||
http.on_complete([this](std::string body, unsigned status) {
|
||||
try {
|
||||
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;
|
||||
}).perform_sync();
|
||||
|
||||
save_to_local();
|
||||
if (!m_hms_json.empty())
|
||||
save_to_local(lang);
|
||||
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";
|
||||
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");
|
||||
if (!fs::exists(hms_folder))
|
||||
fs::create_directory(hms_folder);
|
||||
|
@ -112,13 +115,13 @@ int HMSQuery::load_from_local(std::string &version_info)
|
|||
return 0;
|
||||
}
|
||||
|
||||
int HMSQuery::save_to_local()
|
||||
int HMSQuery::save_to_local(std::string lang)
|
||||
{
|
||||
if (data_dir().empty()) {
|
||||
BOOST_LOG_TRIVIAL(error) << "HMS: save_to_local, data_dir() is empty";
|
||||
return -1;
|
||||
}
|
||||
std::string filename = get_hms_file();
|
||||
std::string filename = get_hms_file(lang);
|
||||
auto hms_folder = (boost::filesystem::path(data_dir()) / "hms");
|
||||
if (!fs::exists(hms_folder))
|
||||
fs::create_directory(hms_folder);
|
||||
|
@ -153,17 +156,18 @@ std::string HMSQuery::hms_language_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();
|
||||
lang = lang_code;
|
||||
std::string query_params = (boost::format("lang=%1%") % lang_code).str();
|
||||
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();
|
||||
return (boost::format("hms_%1%.json") % lang_code).str();
|
||||
//std::string lang_code = HMSQuery::hms_language_code();
|
||||
return (boost::format("hms_%1%.json") % lang).str();
|
||||
}
|
||||
|
||||
wxString HMSQuery::query_hms_msg(std::string long_error_code)
|
||||
|
@ -271,6 +275,9 @@ int HMSQuery::check_hms_info()
|
|||
std::string new_version;
|
||||
get_hms_info_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) {
|
||||
download_new_hms_info = false;
|
||||
}
|
||||
|
@ -280,7 +287,7 @@ int HMSQuery::check_hms_info()
|
|||
if (download_new_hms_info) {
|
||||
download_hms_info();
|
||||
}
|
||||
return;
|
||||
return 0;
|
||||
});
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -22,8 +22,8 @@ protected:
|
|||
json m_hms_json;
|
||||
int download_hms_info();
|
||||
int load_from_local(std::string& version_info);
|
||||
int save_to_local();
|
||||
std::string get_hms_file();
|
||||
int save_to_local(std::string lang);
|
||||
std::string get_hms_file(std::string lang);
|
||||
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");
|
||||
public:
|
||||
|
@ -32,7 +32,7 @@ public:
|
|||
wxString query_hms_msg(std::string long_error_code);
|
||||
wxString query_print_error_msg(int print_error);
|
||||
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);
|
||||
|
|
Loading…
Reference in New Issue