Skip to content

Commit

Permalink
FIX:fixed incorrect HMS content
Browse files Browse the repository at this point in the history
jira:[STUDIO-5818]

Change-Id: Ia2896d6f0ab1ffedbc850e54168acece8e47bdbb
  • Loading branch information
walterwongbbl authored and lanewei120 committed Mar 25, 2024
1 parent 5223469 commit 9a09930
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 15 deletions.
31 changes: 19 additions & 12 deletions src/slic3r/GUI/HMS.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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);
Expand All @@ -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;
}

Expand All @@ -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);
Expand All @@ -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);
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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;
}
Expand All @@ -280,7 +287,7 @@ int HMSQuery::check_hms_info()
if (download_new_hms_info) {
download_hms_info();
}
return;
return 0;
});
return 0;
}
Expand Down
6 changes: 3 additions & 3 deletions src/slic3r/GUI/HMS.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ class HMSQuery {
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:
Expand All @@ -32,7 +32,7 @@ class HMSQuery {
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);
Expand Down

0 comments on commit 9a09930

Please sign in to comment.