FIX: support HMS json for 094

jira: [STUDIO-9512]
Change-Id: I2b9a0d696137367a00850c9dc07ee77a14e3b772
This commit is contained in:
xin.zhang 2025-01-06 15:43:22 +08:00 committed by lane.wei
parent 58f9c7d0b2
commit 34a136b283
5 changed files with 30220 additions and 23 deletions

View File

@ -0,0 +1,775 @@
{
"data": [
{
"actions": [
22
],
"device": "094",
"ecode": "0500806F",
"image": ""
},
{
"actions": [
22
],
"device": "094",
"ecode": "05008071",
"image": ""
},
{
"actions": [
22
],
"device": "094",
"ecode": "05008056",
"image": ""
},
{
"actions": [
21,
22
],
"device": "094",
"ecode": "05008077",
"image": ""
},
{
"actions": [
21,
22
],
"device": "094",
"ecode": "05008078",
"image": ""
},
{
"actions": [
22
],
"device": "094",
"ecode": "05008066",
"image": ""
},
{
"actions": [
22
],
"device": "094",
"ecode": "0500805C",
"image": ""
},
{
"actions": [
22
],
"device": "094",
"ecode": "05008055",
"image": ""
},
{
"actions": [
4,
6
],
"device": "094",
"ecode": "07FFC008",
"image": ""
},
{
"actions": [
22
],
"device": "094",
"ecode": "05008073",
"image": ""
},
{
"actions": [
6
],
"device": "094",
"ecode": "0C004020",
"image": ""
},
{
"actions": [
4,
6
],
"device": "094",
"ecode": "0C00803F",
"image": ""
},
{
"actions": [
22
],
"device": "094",
"ecode": "05008063",
"image": ""
},
{
"actions": [
6
],
"device": "094",
"ecode": "0C004021",
"image": ""
},
{
"actions": [
22
],
"device": "094",
"ecode": "05008074",
"image": ""
},
{
"actions": [
4,
6
],
"device": "094",
"ecode": "07008004",
"image": ""
},
{
"actions": [
4,
6
],
"device": "094",
"ecode": "07FF8011",
"image": ""
},
{
"actions": [
6
],
"device": "094",
"ecode": "0C004022",
"image": ""
},
{
"actions": [
3,
6
],
"device": "094",
"ecode": "0C008040",
"image": ""
},
{
"actions": [
22
],
"device": "094",
"ecode": "05008064",
"image": ""
},
{
"actions": [
21,
22
],
"device": "094",
"ecode": "0500806B",
"image": ""
},
{
"actions": [
21,
22
],
"device": "094",
"ecode": "05008051",
"image": ""
},
{
"actions": [
25,
22
],
"device": "094",
"ecode": "0500806A",
"image": ""
},
{
"actions": [
21,
22
],
"device": "094",
"ecode": "05008061",
"image": ""
},
{
"actions": [
21,
22
],
"device": "094",
"ecode": "0500805B",
"image": ""
},
{
"actions": [
22,
21
],
"device": "094",
"ecode": "05FE8053",
"image": ""
},
{
"actions": [
21,
22
],
"device": "094",
"ecode": "05008072",
"image": ""
},
{
"actions": [
22,
21
],
"device": "094",
"ecode": "05FF8053",
"image": ""
},
{
"actions": [
21,
22
],
"device": "094",
"ecode": "0500806D",
"image": ""
},
{
"actions": [
21,
22
],
"device": "094",
"ecode": "05008062",
"image": ""
},
{
"actions": [
21,
22
],
"device": "094",
"ecode": "0500806C",
"image": ""
},
{
"actions": [
22,
21
],
"device": "094",
"ecode": "05008053",
"image": ""
},
{
"actions": [
23,
24
],
"device": "094",
"ecode": "05FE8069",
"image": ""
},
{
"actions": [
21,
22
],
"device": "094",
"ecode": "05008059",
"image": ""
},
{
"actions": [
23,
24
],
"device": "094",
"ecode": "05FF8069",
"image": ""
},
{
"actions": [
23,
24
],
"device": "094",
"ecode": "05008069",
"image": ""
},
{
"actions": [
21,
22
],
"device": "094",
"ecode": "0500805A",
"image": ""
},
{
"actions": [
25,
22
],
"device": "094",
"ecode": "05FE806A",
"image": ""
},
{
"actions": [
25,
22
],
"device": "094",
"ecode": "05FF806A",
"image": ""
},
{
"actions": [
21,
22
],
"device": "094",
"ecode": "0500806E",
"image": ""
},
{
"actions": [
4,
6
],
"device": "094",
"ecode": "07FEC003",
"image": ""
},
{
"actions": [
9
],
"device": "094",
"ecode": "07FFC006",
"image": ""
},
{
"actions": [
9
],
"device": "094",
"ecode": "07FF8006",
"image": ""
},
{
"actions": [
7,
8
],
"device": "094",
"ecode": "07FF8007",
"image": ""
},
{
"actions": [
9
],
"device": "094",
"ecode": "07FF8003",
"image": ""
},
{
"actions": [
9
],
"device": "094",
"ecode": "07FFC003",
"image": ""
},
{
"actions": [
9
],
"device": "094",
"ecode": "07FEC006",
"image": ""
},
{
"actions": [
9
],
"device": "094",
"ecode": "07FE8003",
"image": ""
},
{
"actions": [
9
],
"device": "094",
"ecode": "07FEC009",
"image": ""
},
{
"actions": [
9
],
"device": "094",
"ecode": "07FFC009",
"image": ""
},
{
"actions": [
9
],
"device": "094",
"ecode": "07FE8006",
"image": ""
},
{
"actions": [
7,
8
],
"device": "094",
"ecode": "07FE8007",
"image": ""
},
{
"actions": [
11
],
"device": "094",
"ecode": "03008047",
"image": ""
},
{
"actions": [
11
],
"device": "094",
"ecode": "03008046",
"image": ""
},
{
"actions": [
4,
6
],
"device": "094",
"ecode": "07FE8002",
"image": ""
},
{
"actions": [
4,
6
],
"device": "094",
"ecode": "03008041",
"image": ""
},
{
"actions": [
18
],
"device": "094",
"ecode": "0500040000020037",
"image": ""
},
{
"actions": [
19
],
"device": "094",
"ecode": "0500040000020031",
"image": ""
},
{
"actions": [
4,
6
],
"device": "094",
"ecode": "03008063",
"image": ""
},
{
"actions": [
4,
6
],
"device": "094",
"ecode": "0C004029",
"image": ""
},
{
"actions": [
4,
6
],
"device": "094",
"ecode": "07FE8011",
"image": ""
},
{
"actions": [
4,
6
],
"device": "094",
"ecode": "07FE8005",
"image": ""
},
{
"actions": [
4,
6
],
"device": "094",
"ecode": "0C00800B",
"image": ""
},
{
"actions": [
17
],
"device": "094",
"ecode": "0500040000020036",
"image": ""
},
{
"actions": [
20
],
"device": "094",
"ecode": "0700550000020001",
"image": ""
},
{
"actions": [
4,
6
],
"device": "094",
"ecode": "07FE8013",
"image": ""
},
{
"actions": [
7,
8
],
"device": "094",
"ecode": "07FEC00A",
"image": ""
},
{
"actions": [
15
],
"device": "094",
"ecode": "0500040000020034",
"image": ""
},
{
"actions": [
11
],
"device": "094",
"ecode": "0500403E",
"image": ""
},
{
"actions": [
4,
6
],
"device": "094",
"ecode": "07FE8010",
"image": ""
},
{
"actions": [
4,
6
],
"device": "094",
"ecode": "03008049",
"image": ""
},
{
"actions": [
16
],
"device": "094",
"ecode": "0500040000020035",
"image": ""
},
{
"actions": [
4,
6
],
"device": "094",
"ecode": "03008042",
"image": ""
},
{
"actions": [
11
],
"device": "094",
"ecode": "03008045",
"image": ""
},
{
"actions": [
4,
6
],
"device": "094",
"ecode": "07FE8004",
"image": ""
},
{
"actions": [
4,
6
],
"device": "094",
"ecode": "07FEC008",
"image": ""
},
{
"actions": [
4,
6
],
"device": "094",
"ecode": "03008064",
"image": ""
},
{
"actions": [
4,
6
],
"device": "094",
"ecode": "0500403D",
"image": ""
},
{
"actions": [
4,
6
],
"device": "094",
"ecode": "0C008033",
"image": ""
},
{
"actions": [
4,
6
],
"device": "094",
"ecode": "03008062",
"image": ""
},
{
"actions": [
6,
4
],
"device": "094",
"ecode": "03008061",
"image": ""
},
{
"actions": [
11
],
"device": "default",
"ecode": "05004003",
"image": ""
},
{
"actions": [
14
],
"device": "default",
"ecode": "05004015",
"image": ""
},
{
"actions": [
11
],
"device": "default",
"ecode": "05024001",
"image": ""
},
{
"actions": [
14
],
"device": "default",
"ecode": "0500402E",
"image": ""
},
{
"actions": [
11
],
"device": "default",
"ecode": "05004004",
"image": ""
},
{
"actions": [
11
],
"device": "default",
"ecode": "05004014",
"image": ""
},
{
"actions": [
14
],
"device": "default",
"ecode": "0500402F",
"image": ""
},
{
"actions": [
2
],
"device": "default",
"ecode": "03008013",
"image": ""
},
{
"actions": [
2,
5
],
"device": "default",
"ecode": "03008007",
"image": ""
}
],
"version": "202412312058"
}

14709
resources/hms/hms_en_094.json Normal file

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -2,6 +2,8 @@
#include <boost/log/trivial.hpp>
static const char* HMS_PATH = "hms";
namespace Slic3r {
namespace GUI {
@ -40,10 +42,11 @@ int get_hms_info_version(std::string& version)
return result;
}
int HMSQuery::download_hms_related(std::string hms_type, json* receive_json, std::string dev_type)
// Note: Download the hms into receive_json
int HMSQuery::download_hms_related(const std::string& hms_type, const std::string& dev_type, json* receive_json)
{
std::string local_version = "0";
load_from_local(local_version, hms_type, receive_json, dev_type);
load_from_local(hms_type, dev_type, receive_json, local_version);
AppConfig* config = wxGetApp().app_config;
if (!config) return -1;
@ -64,27 +67,40 @@ int HMSQuery::download_hms_related(std::string hms_type, json* receive_json, std
if (!dev_type.empty()) { url += (url.find('?') != std::string::npos ? "&" : "?") + (boost::format("d=%1%") % dev_type).str(); }
bool to_save_local = false;
BOOST_LOG_TRIVIAL(info) << "hms: download url = " << url;
Slic3r::Http http = Slic3r::Http::get(url);
http.on_complete([this, receive_json, hms_type](std::string body, unsigned status) {
http.on_complete([this, receive_json, hms_type, &to_save_local, &local_version](std::string body, unsigned status) {
try {
json j = json::parse(body);
if (j.contains("result")) {
if (j["result"] == 0 && j.contains("data")) {
if (hms_type.compare(QUERY_HMS_INFO) == 0) {
if (!j.contains("ver"))
{
return;
}
const std::string& remote_ver = std::to_string(j["ver"].get<long long>());
if (remote_ver <= local_version)
{
return;
}
(*receive_json)["version"] = remote_ver;
if (hms_type.compare(QUERY_HMS_INFO) == 0)
{
(*receive_json) = j["data"];
this->save_local = true;
to_save_local = true;
}
else if (hms_type.compare(QUERY_HMS_ACTION) == 0) {
else if (hms_type.compare(QUERY_HMS_ACTION) == 0)
{
(*receive_json)["data"] = j["data"];
this->save_local = true;
to_save_local = true;
}
if (j.contains("ver"))
(*receive_json)["version"] = std::to_string(j["ver"].get<long long>());
} else if (j["result"] == 201){
BOOST_LOG_TRIVIAL(info) << "HMSQuery: HMS info is the latest version";
}else{
receive_json->clear();
BOOST_LOG_TRIVIAL(info) << "HMSQuery: update hms info error = " << j["result"].get<int>();
}
}
@ -97,9 +113,8 @@ int HMSQuery::download_hms_related(std::string hms_type, json* receive_json, std
BOOST_LOG_TRIVIAL(error) << "HMSQuery: update hms info error = " << error << ", body = " << body << ", status = " << status;
}).perform_sync();
if (!receive_json->empty() && save_local == true) {
if (to_save_local && !receive_json->empty()) {
save_to_local(lang, hms_type, dev_type, *receive_json);
save_local = false;
}
return 0;
}
@ -129,10 +144,31 @@ bool HMSQuery::check_local_file(std::string dev_type)
return false;
}
int HMSQuery::load_from_local(std::string& version_info, std::string hms_type, json* load_json, std::string dev_type)
void HMSQuery::copy_from_data_dir_to_local()
{
const fs::path& from_dir = fs::path(Slic3r::resources_dir()) / HMS_PATH;
const fs::path& to_dir = fs::path(Slic3r::data_dir()) / HMS_PATH;
for (const auto& entry : fs::directory_iterator(from_dir))
{
const fs::path& source_path = entry.path();
const fs::path& relative_path = fs::relative(source_path, from_dir);
const fs::path& dest_path = to_dir / relative_path;
if (fs::exists(dest_path))
{
continue;
}
if (fs::is_regular_file(source_path))
{
copy_file(source_path, dest_path);
}
}
}
int HMSQuery::load_from_local(const std::string& hms_type, const std::string& dev_type, json* load_json, std::string& load_version)
{
if (data_dir().empty()) {
version_info = "0";
load_version = "0";
BOOST_LOG_TRIVIAL(error) << "HMS: load_from_local, data_dir() is empty";
return -1;
}
@ -147,7 +183,7 @@ int HMSQuery::load_from_local(std::string& version_info, std::string hms_type, j
if (json_file.is_open()) {
json_file >> (*load_json);
if ((*load_json).contains("version")) {
version_info = (*load_json)["version"].get<std::string>();
load_version = (*load_json)["version"].get<std::string>();
return 0;
} else {
BOOST_LOG_TRIVIAL(warning) << "HMS: load_from_local, no version info";
@ -155,11 +191,11 @@ int HMSQuery::load_from_local(std::string& version_info, std::string hms_type, j
}
}
} catch(...) {
version_info = "0";
load_version = "0";
BOOST_LOG_TRIVIAL(error) << "HMS: load_from_local failed";
return -1;
}
version_info = "0";
load_version = "0";
return 0;
}
@ -388,6 +424,8 @@ wxString HMSQuery::query_print_error_url_action(int print_error, std::string dev
int HMSQuery::check_hms_info(std::string dev_type)
{
copy_from_data_dir_to_local();// STUDIO-9512
std::vector<std::string> dev_sn;
dev_sn.push_back("00M");
dev_sn.push_back("00W");
@ -396,14 +434,14 @@ int HMSQuery::check_hms_info(std::string dev_type)
dev_sn.push_back("01S");
dev_sn.push_back("030");
dev_sn.push_back("039");
dev_sn.push_back("094");
// dev_sn.push_back("094"); // there are 094 files in local
boost::thread check_thread = boost::thread([this, dev_type, dev_sn] {
std::unique_lock unique_lock(m_hms_mutex);
for (auto sn : dev_sn) {
download_hms_related(QUERY_HMS_INFO, &m_hms_info_json, sn);
download_hms_related(QUERY_HMS_ACTION, &m_hms_action_json, sn);
download_hms_related(QUERY_HMS_INFO, sn, &m_hms_info_json);
download_hms_related(QUERY_HMS_ACTION, sn, &m_hms_action_json);
}
return 0;
});

View File

@ -27,8 +27,8 @@ protected:
json m_hms_action_json;
mutable std::mutex m_hms_mutex;
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 download_hms_related(const std::string& hms_type, const std::string& dev_type, json *receive_json);
int load_from_local(const std::string& hms_type, const std::string& dev_type, json * receive_json, std::string& version_info);
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")) const;
@ -44,7 +44,9 @@ public:
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;
private:
void copy_from_data_dir_to_local();
};
int get_hms_info_version(std::string &version);