FIX:crash while using HMSQuery::query_hms_msg
jira: [STUDIO-9380] Change-Id: I317a10b101fa0e7df471e04245778bdc3984212d
This commit is contained in:
parent
622e31ff35
commit
5edc01e8d1
|
@ -227,54 +227,73 @@ std::string HMSQuery::get_hms_file(std::string hms_type, std::string lang, std::
|
||||||
return (boost::format("hms_%1%_%2%.json") % lang % dev_type).str();
|
return (boost::format("hms_%1%_%2%.json") % lang % dev_type).str();
|
||||||
}
|
}
|
||||||
|
|
||||||
wxString HMSQuery::query_hms_msg(std::string long_error_code)
|
wxString HMSQuery::query_hms_msg(std::string long_error_code) const
|
||||||
{
|
{
|
||||||
AppConfig* config = wxGetApp().app_config;
|
AppConfig* config = wxGetApp().app_config;
|
||||||
if (!config) return wxEmptyString;
|
if (!config) return wxEmptyString;
|
||||||
std::string lang_code = HMSQuery::hms_language_code();
|
const std::string& lang_code = HMSQuery::hms_language_code();
|
||||||
return _query_hms_msg(long_error_code, lang_code);
|
return _query_hms_msg(long_error_code, lang_code);
|
||||||
}
|
}
|
||||||
|
|
||||||
wxString HMSQuery::_query_hms_msg(std::string long_error_code, std::string lang_code)
|
wxString HMSQuery::_query_hms_msg(std::string long_error_code, std::string lang_code) const
|
||||||
{
|
{
|
||||||
if (long_error_code.empty())
|
if (long_error_code.empty())
|
||||||
|
{
|
||||||
return wxEmptyString;
|
return wxEmptyString;
|
||||||
|
}
|
||||||
|
|
||||||
if (m_hms_info_json.contains("device_hms")) {
|
if (!m_hms_info_json.is_object())
|
||||||
if (m_hms_info_json["device_hms"].contains(lang_code)) {
|
{
|
||||||
for (auto item = m_hms_info_json["device_hms"][lang_code].begin(); item != m_hms_info_json["device_hms"][lang_code].end(); item++) {
|
BOOST_LOG_TRIVIAL(error) << "the hms info is not a valid json object";
|
||||||
if (item->contains("ecode")) {
|
return wxEmptyString;
|
||||||
std::string temp_string = (*item)["ecode"].get<std::string>();
|
}
|
||||||
if (boost::to_upper_copy(temp_string) == long_error_code) {
|
|
||||||
if (item->contains("intro")) {
|
const json& device_hms_json = m_hms_info_json.value("device_hms", json());
|
||||||
return wxString::FromUTF8((*item)["intro"].get<std::string>());
|
if (device_hms_json.is_null() || !device_hms_json.is_object())
|
||||||
}
|
{
|
||||||
}
|
BOOST_LOG_TRIVIAL(error) << "there are no valid json object named device_hms";
|
||||||
}
|
return wxEmptyString;
|
||||||
}
|
}
|
||||||
BOOST_LOG_TRIVIAL(info) << "hms: query_hms_msg, not found error_code = " << long_error_code;
|
|
||||||
} else {
|
const json& device_hms_msg_json = device_hms_json.value(lang_code, json());
|
||||||
BOOST_LOG_TRIVIAL(error) << "hms: query_hms_msg, do not contains lang_code = " << lang_code;
|
if (device_hms_msg_json.is_null())
|
||||||
// return first language
|
{
|
||||||
if (!m_hms_info_json["device_hms"].empty()) {
|
BOOST_LOG_TRIVIAL(error) << "hms: query_hms_msg, do not contains lang_code = " << lang_code;
|
||||||
for (auto lang : m_hms_info_json["device_hms"]) {
|
if (lang_code.empty()) /*traverse all if lang_code is empty*/
|
||||||
for (auto item = lang.begin(); item != lang.end(); item++) {
|
{
|
||||||
if (item->contains("ecode")) {
|
for (const auto& lang_item : device_hms_json)
|
||||||
std::string temp_string = (*item)["ecode"].get<std::string>();
|
{
|
||||||
if (boost::to_upper_copy(temp_string) == long_error_code) {
|
for (const auto& msg_item : lang_item)
|
||||||
if (item->contains("intro")) {
|
{
|
||||||
return wxString::FromUTF8((*item)["intro"].get<std::string>());
|
if (msg_item.is_object())
|
||||||
}
|
{
|
||||||
}
|
const std::string& error_code = msg_item.value("ecode", json()).get<std::string>();
|
||||||
|
if (boost::to_upper_copy(error_code) == long_error_code && msg_item.contains("intro"))
|
||||||
|
{
|
||||||
|
BOOST_LOG_TRIVIAL(info) << "retry without lang_code successed.";
|
||||||
|
return msg_item["intro"].get<std::string>();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
BOOST_LOG_TRIVIAL(info) << "device_hms is not exists";
|
|
||||||
return wxEmptyString;
|
return wxEmptyString;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
for (const auto& item : device_hms_msg_json)
|
||||||
|
{
|
||||||
|
if (item.is_object())
|
||||||
|
{
|
||||||
|
const std::string& error_code = item.value("ecode", json()).get<std::string>();
|
||||||
|
if (boost::to_upper_copy(error_code) == long_error_code && item.contains("intro"))
|
||||||
|
{
|
||||||
|
return item["intro"].get<std::string>();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
BOOST_LOG_TRIVIAL(error) << "hms: query_hms_msg, do not contains valid message, lang_code = " << lang_code << " long_error_code = " << long_error_code;
|
||||||
return wxEmptyString;
|
return wxEmptyString;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -27,13 +27,13 @@ protected:
|
||||||
int load_from_local(std::string &version_info, std::string hms_type, json *load_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);
|
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 = "");
|
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"));
|
wxString _query_hms_msg(std::string long_error_code, std::string lang_code = std::string("en")) const;
|
||||||
bool _query_error_msg(wxString &error_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);
|
wxString _query_error_url_action(std::string long_error_code, std::string dev_id, std::vector<int>& button_action);
|
||||||
public:
|
public:
|
||||||
HMSQuery() {}
|
HMSQuery() {}
|
||||||
int check_hms_info(std::string dev_type = "00M");
|
int check_hms_info(std::string dev_type = "00M");
|
||||||
wxString query_hms_msg(std::string long_error_code);
|
wxString query_hms_msg(std::string long_error_code) const;
|
||||||
bool query_print_error_msg(int print_error, wxString &error_msg);
|
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);
|
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 hms_language_code();
|
||||||
|
|
Loading…
Reference in New Issue