NEW:support displaying new HMS error message
jira:[hms ] Change-Id: I99c2877eba5476f2f5ee25636ebea2923c6aafdb (cherry picked from commit 512ac4b6c18a3623a4197213c8e879b450023cf9)
This commit is contained in:
parent
7dd335f134
commit
d4187d91e7
|
@ -6510,6 +6510,21 @@ bool DeviceManager::set_selected_machine(std::string dev_id, bool need_disconnec
|
|||
auto my_machine_list = get_my_machine_list();
|
||||
auto it = my_machine_list.find(dev_id);
|
||||
|
||||
/*update hms file*/
|
||||
try {
|
||||
Slic3r::GUI::wxGetApp().CallAfter([=] {
|
||||
if (Slic3r::GUI::wxGetApp().get_hms_query()) {
|
||||
std::string dev_type = dev_id.substr(0, 3);
|
||||
if (!Slic3r::GUI::wxGetApp().get_hms_query()->check_local_file(dev_type)) {
|
||||
Slic3r::GUI::wxGetApp().get_hms_query()->check_hms_info(dev_type);
|
||||
}
|
||||
else {
|
||||
Slic3r::GUI::wxGetApp().get_hms_query()->check_hms_info_from_local(dev_type);
|
||||
}
|
||||
};
|
||||
});
|
||||
} catch (...) {}
|
||||
|
||||
// disconnect last
|
||||
auto last_selected = my_machine_list.find(selected_machine);
|
||||
if (last_selected != my_machine_list.end()) {
|
||||
|
|
|
@ -40,10 +40,11 @@ int get_hms_info_version(std::string& version)
|
|||
return result;
|
||||
}
|
||||
|
||||
int HMSQuery::download_hms_related(std::string hms_type, json* receive_json)
|
||||
int HMSQuery::download_hms_related(std::string hms_type, json* receive_json, std::string dev_type)
|
||||
{
|
||||
std::string local_version = "0";
|
||||
load_from_local(local_version, hms_type, receive_json);
|
||||
load_from_local(local_version, hms_type, receive_json, dev_type);
|
||||
|
||||
AppConfig* config = wxGetApp().app_config;
|
||||
if (!config) return -1;
|
||||
|
||||
|
@ -52,10 +53,10 @@ int HMSQuery::download_hms_related(std::string hms_type, json* receive_json)
|
|||
std::string query_params = HMSQuery::build_query_params(lang);
|
||||
std::string url;
|
||||
if (hms_type.compare(QUERY_HMS_INFO) == 0) {
|
||||
url = (boost::format("https://%1%/query.php?%2%&v=%3%") % hms_host % query_params % local_version).str();
|
||||
url = (boost::format("https://%1%/query.php?%2%&v=%3%&d=%4%") % hms_host % query_params % local_version % dev_type).str();
|
||||
}
|
||||
else if (hms_type.compare(QUERY_HMS_ACTION) == 0) {
|
||||
url = (boost::format("https://%1%/hms/GetActionImage.php?v=%2%") % hms_host % local_version).str();
|
||||
url = (boost::format("https://%1%/hms/GetActionImage.php?v=%2%&d=%3%") % hms_host % local_version % dev_type).str();
|
||||
}
|
||||
|
||||
BOOST_LOG_TRIVIAL(info) << "hms: download url = " << url;
|
||||
|
@ -92,20 +93,45 @@ int HMSQuery::download_hms_related(std::string hms_type, json* receive_json)
|
|||
}).perform_sync();
|
||||
|
||||
if (!receive_json->empty() && save_local == true) {
|
||||
save_to_local(lang, hms_type, *receive_json);
|
||||
save_to_local(lang, hms_type, dev_type, *receive_json);
|
||||
save_local = false;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
int HMSQuery::load_from_local(std::string& version_info, std::string hms_type, json* load_json)
|
||||
bool HMSQuery::check_local_file(std::string dev_type)
|
||||
{
|
||||
if (data_dir().empty()) {
|
||||
BOOST_LOG_TRIVIAL(error) << "HMS: load_from_local, data_dir() is empty";
|
||||
return false;
|
||||
}
|
||||
|
||||
std::string filename = get_hms_file(QUERY_HMS_INFO, HMSQuery::hms_language_code(), dev_type);
|
||||
auto hms_folder = (boost::filesystem::path(data_dir()) / "hms");
|
||||
if (!fs::exists(hms_folder)) fs::create_directory(hms_folder);
|
||||
|
||||
std::string dir_str = (hms_folder / filename).make_preferred().string();
|
||||
std::ifstream json_file(encode_path(dir_str.c_str()));
|
||||
try {
|
||||
if (json_file.is_open()) {
|
||||
json_file.close();
|
||||
return true;
|
||||
}
|
||||
} catch (...) {
|
||||
BOOST_LOG_TRIVIAL(error) << "HMS: load_from_local failed";
|
||||
return false;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
int HMSQuery::load_from_local(std::string& version_info, std::string hms_type, json* load_json, std::string dev_type)
|
||||
{
|
||||
if (data_dir().empty()) {
|
||||
version_info = "0";
|
||||
BOOST_LOG_TRIVIAL(error) << "HMS: load_from_local, data_dir() is empty";
|
||||
return -1;
|
||||
}
|
||||
std::string filename = get_hms_file(hms_type, HMSQuery::hms_language_code());
|
||||
std::string filename = get_hms_file(hms_type, HMSQuery::hms_language_code(), dev_type);
|
||||
auto hms_folder = (boost::filesystem::path(data_dir()) / "hms");
|
||||
if (!fs::exists(hms_folder))
|
||||
fs::create_directory(hms_folder);
|
||||
|
@ -132,13 +158,13 @@ int HMSQuery::load_from_local(std::string& version_info, std::string hms_type, j
|
|||
return 0;
|
||||
}
|
||||
|
||||
int HMSQuery::save_to_local(std::string lang, std::string hms_type, json save_json)
|
||||
int HMSQuery::save_to_local(std::string lang, std::string hms_type, std::string dev_type, json save_json)
|
||||
{
|
||||
if (data_dir().empty()) {
|
||||
BOOST_LOG_TRIVIAL(error) << "HMS: save_to_local, data_dir() is empty";
|
||||
return -1;
|
||||
}
|
||||
std::string filename = get_hms_file(hms_type,lang);
|
||||
std::string filename = get_hms_file(hms_type,lang, dev_type);
|
||||
auto hms_folder = (boost::filesystem::path(data_dir()) / "hms");
|
||||
if (!fs::exists(hms_folder))
|
||||
fs::create_directory(hms_folder);
|
||||
|
@ -186,14 +212,14 @@ std::string HMSQuery::build_query_params(std::string& lang)
|
|||
return query_params;
|
||||
}
|
||||
|
||||
std::string HMSQuery::get_hms_file(std::string hms_type, std::string lang)
|
||||
std::string HMSQuery::get_hms_file(std::string hms_type, std::string lang, std::string dev_type)
|
||||
{
|
||||
//return hms action filename
|
||||
if (hms_type.compare(QUERY_HMS_ACTION) == 0) {
|
||||
return (boost::format("hms_action.json")).str();
|
||||
return (boost::format("hms_action_%1%.json") % dev_type).str();
|
||||
}
|
||||
//return hms filename
|
||||
return (boost::format("hms_%1%.json") % lang).str();
|
||||
return (boost::format("hms_%1%_%2%.json") % lang % dev_type).str();
|
||||
}
|
||||
|
||||
wxString HMSQuery::query_hms_msg(std::string long_error_code)
|
||||
|
@ -331,17 +357,23 @@ wxString HMSQuery::query_print_error_url_action(int print_error, std::string dev
|
|||
}
|
||||
|
||||
|
||||
int HMSQuery::check_hms_info()
|
||||
int HMSQuery::check_hms_info(std::string dev_type)
|
||||
{
|
||||
boost::thread check_thread = boost::thread([this] {
|
||||
|
||||
download_hms_related(QUERY_HMS_INFO, &m_hms_info_json);
|
||||
download_hms_related(QUERY_HMS_ACTION, &m_hms_action_json);
|
||||
boost::thread check_thread = boost::thread([this, dev_type] {
|
||||
download_hms_related(QUERY_HMS_INFO, &m_hms_info_json, dev_type);
|
||||
download_hms_related(QUERY_HMS_ACTION, &m_hms_action_json, dev_type);
|
||||
return 0;
|
||||
});
|
||||
return 0;
|
||||
}
|
||||
|
||||
void HMSQuery::check_hms_info_from_local(std::string dev_type)
|
||||
{
|
||||
std::string local_version = "0";
|
||||
load_from_local(local_version, QUERY_HMS_INFO, &m_hms_info_json, dev_type);
|
||||
load_from_local(local_version, QUERY_HMS_ACTION, &m_hms_action_json, dev_type);
|
||||
}
|
||||
|
||||
std::string get_hms_wiki_url(std::string error_code)
|
||||
{
|
||||
AppConfig* config = wxGetApp().app_config;
|
||||
|
|
|
@ -23,22 +23,23 @@ class HMSQuery {
|
|||
protected:
|
||||
json m_hms_info_json;
|
||||
json m_hms_action_json;
|
||||
int download_hms_related(std::string hms_type,json* receive_json);
|
||||
int load_from_local(std::string& version_info, std::string hms_type, json* load_json);
|
||||
int save_to_local(std::string lang, std::string hms_type,json save_json);
|
||||
std::string get_hms_file(std::string hms_type, std::string lang = std::string("en"));
|
||||
int download_hms_related(std::string hms_type, json *receive_json, std::string dev_type);
|
||||
int load_from_local(std::string &version_info, std::string hms_type, json *load_json, std::string dev_type);
|
||||
int save_to_local(std::string lang, std::string hms_type, std::string dev_type, json save_json);
|
||||
std::string get_hms_file(std::string hms_type, std::string lang = std::string("en"), std::string dev_type = "");
|
||||
wxString _query_hms_msg(std::string long_error_code, std::string lang_code = std::string("en"));
|
||||
bool _query_error_msg(wxString &error_msg, std::string long_error_code, std::string lang_code = std::string("en"));
|
||||
wxString _query_error_url_action(std::string long_error_code, std::string dev_id, std::vector<int>& button_action);
|
||||
public:
|
||||
HMSQuery() {}
|
||||
int check_hms_info();
|
||||
wxString query_hms_msg(std::string long_error_code);
|
||||
int check_hms_info(std::string dev_type = "00M");
|
||||
void check_hms_info_from_local(std::string dev_type);
|
||||
wxString query_hms_msg(std::string long_error_code);
|
||||
bool query_print_error_msg(int print_error, wxString &error_msg);
|
||||
wxString query_print_error_url_action(int print_error, std::string dev_id, std::vector<int>& button_action);
|
||||
static std::string hms_language_code();
|
||||
static std::string build_query_params(std::string& lang);
|
||||
|
||||
bool check_local_file(std::string dev_type);
|
||||
bool save_local = false;
|
||||
};
|
||||
|
||||
|
|
Loading…
Reference in New Issue