mirror of
https://github.com/SoftFever/OrcaSlicer.git
synced 2026-02-23 21:05:31 -07:00
FIX: the json val could be long long or string
jira: [none] Change-Id: Ic06276adf5e7663d57ba1c4b6f9a57e897a9075d (cherry picked from commit edaaa0b70523951aaa0d415ab178a438a7d7b377)
This commit is contained in:
parent
19a6a20b23
commit
9e024d1d4d
4 changed files with 47 additions and 15 deletions
|
|
@ -3637,7 +3637,7 @@ int MachineObject::parse_json(std::string payload, bool key_field_only)
|
|||
}
|
||||
if (jj.contains("job_id")) {
|
||||
is_support_wait_sending_finish = true;
|
||||
this->job_id_ = jj["job_id"].get<std::string>();
|
||||
this->job_id_ = JsonValParser::get_longlong_val(jj["job_id"]);
|
||||
}
|
||||
else {
|
||||
is_support_wait_sending_finish = false;
|
||||
|
|
@ -4682,7 +4682,7 @@ int MachineObject::parse_json(std::string payload, bool key_field_only)
|
|||
BOOST_LOG_TRIVIAL(info) << "parse_json, ack of project_prepare = " << j.dump(4);
|
||||
if (m_agent) {
|
||||
if (jj.contains("job_id")) {
|
||||
this->job_id_ = jj["job_id"].get<std::string>();
|
||||
this->job_id_ = JsonValParser::get_longlong_val(jj["job_id"]);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -7485,4 +7485,28 @@ void change_the_opacity(wxColour& colour)
|
|||
colour = wxColour(colour.Red(), colour.Green(), colour.Blue(), 254);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//************************************
|
||||
// Method: get_longlong_val
|
||||
// FullName: Slic3r::JsonValParser::get_longlong_val
|
||||
// Access: public static
|
||||
// Returns: std::string
|
||||
// Qualifier:
|
||||
// Parameter: const json & j
|
||||
//************************************
|
||||
std::string JsonValParser::get_longlong_val(const json& j)
|
||||
{
|
||||
if (j.is_number())
|
||||
{
|
||||
return std::to_string(j.get<long long>());
|
||||
}
|
||||
else if (j.is_string())
|
||||
{
|
||||
return j.get<std::string>();
|
||||
}
|
||||
|
||||
return string();
|
||||
}
|
||||
|
||||
} // namespace Slic3r
|
||||
|
|
|
|||
|
|
@ -1370,6 +1370,14 @@ public:
|
|||
|
||||
// change the opacity
|
||||
void change_the_opacity(wxColour& colour);
|
||||
} // namespace Slic3r
|
||||
|
||||
|
||||
class JsonValParser
|
||||
{
|
||||
public:
|
||||
static std::string get_longlong_val(const json& j);
|
||||
};
|
||||
|
||||
}; // namespace Slic3r
|
||||
|
||||
#endif // slic3r_DeviceManager_hpp_
|
||||
|
|
|
|||
|
|
@ -34,7 +34,7 @@ int get_hms_info_version(std::string& version)
|
|||
try {
|
||||
json j = json::parse(body);
|
||||
if (j.contains("ver")) {
|
||||
version = std::to_string(j["ver"].get<long long>());
|
||||
version = JsonValParser::get_longlong_val(j["ver"]);
|
||||
}
|
||||
} catch (...) {
|
||||
;
|
||||
|
|
@ -87,7 +87,7 @@ int HMSQuery::download_hms_related(const std::string& hms_type, const std::strin
|
|||
return;
|
||||
}
|
||||
|
||||
const std::string& remote_ver = std::to_string(j["ver"].get<long long>());
|
||||
const std::string& remote_ver = JsonValParser::get_longlong_val(j["ver"]);
|
||||
if (remote_ver <= local_version)
|
||||
{
|
||||
return;
|
||||
|
|
@ -135,12 +135,12 @@ _copy_dir(const fs::path& from_dir, const fs::path& to_dir) /* copy and override
|
|||
{
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
if (!fs::exists(to_dir))
|
||||
{
|
||||
{
|
||||
fs::create_directory(to_dir);
|
||||
}
|
||||
|
||||
|
||||
for (const auto &entry : fs::directory_iterator(from_dir))
|
||||
{
|
||||
const fs::path &source_path = entry.path();
|
||||
|
|
@ -148,7 +148,7 @@ _copy_dir(const fs::path& from_dir, const fs::path& to_dir) /* copy and override
|
|||
const fs::path &dest_path = to_dir / relative_path;
|
||||
|
||||
if (fs::is_regular_file(source_path))
|
||||
{
|
||||
{
|
||||
if (fs::exists(dest_path))
|
||||
{
|
||||
fs::remove(dest_path);
|
||||
|
|
@ -164,7 +164,7 @@ _copy_dir(const fs::path& from_dir, const fs::path& to_dir) /* copy and override
|
|||
}
|
||||
catch (...)
|
||||
{
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -209,8 +209,8 @@ int HMSQuery::load_from_local(const std::string& hms_type, const std::string& de
|
|||
|
||||
if ((*load_json).contains("ver"))
|
||||
{
|
||||
load_version = (*load_json)["ver"].get<std::string>();
|
||||
}
|
||||
load_version = JsonValParser::get_longlong_val((*load_json)["ver"]);
|
||||
}
|
||||
else
|
||||
{
|
||||
BOOST_LOG_TRIVIAL(warning) << "HMS: load_from_local, no version info";
|
||||
|
|
@ -221,7 +221,7 @@ int HMSQuery::load_from_local(const std::string& hms_type, const std::string& de
|
|||
json_file >> (*load_json);
|
||||
if ((*load_json).contains("version"))
|
||||
{
|
||||
load_version = (*load_json)["version"].get<std::string>();
|
||||
load_version = JsonValParser::get_longlong_val((*load_json)["version"]);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
|
@ -529,7 +529,7 @@ wxImage HMSQuery::query_image_from_local(const wxString& image_name)
|
|||
{
|
||||
const fs::path& local_img_dir = fs::path(Slic3r::data_dir()) / HMS_LOCAL_IMG_PATH;
|
||||
if (fs::exists(local_img_dir))
|
||||
{
|
||||
{
|
||||
for (const auto &entry : fs::directory_iterator(local_img_dir))
|
||||
{
|
||||
const fs::path& image_path = entry.path();
|
||||
|
|
|
|||
|
|
@ -457,7 +457,7 @@ void PrintJob::process(Ctl &ctl)
|
|||
try {
|
||||
std::ignore = job_info_j.parse(job_info);
|
||||
if (job_info_j.contains("job_id")) {
|
||||
curr_job_id = job_info_j["job_id"].get<std::string>();
|
||||
curr_job_id = JsonValParser::get_longlong_val(job_info_j["job_id"]);
|
||||
}
|
||||
BOOST_LOG_TRIVIAL(trace) << "print_job: curr_obj_id=" << curr_job_id;
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue