FIX: Fixup possible data lost in user presets
Change-Id: I345f770a14d674dd5e48c94505470ead3487b745 Jira: none (cherry picked from commit c1e9cf4e233bfc1132a9ffc16d8e875f142be4f6)
This commit is contained in:
parent
dd666a6313
commit
b9898d1cf5
|
@ -1599,13 +1599,6 @@ bool PresetCollection::load_user_preset(std::string name, std::map<std::string,
|
|||
}
|
||||
std::string cloud_setting_id = preset_values[BBL_JSON_KEY_SETTING_ID];
|
||||
|
||||
//base_id
|
||||
if (preset_values.find(BBL_JSON_KEY_BASE_ID) == preset_values.end()) {
|
||||
BOOST_LOG_TRIVIAL(warning) << __FUNCTION__ << boost::format("can not find base_id, not loading for user preset %1%")%name;
|
||||
return false;
|
||||
}
|
||||
std::string cloud_base_id = preset_values[BBL_JSON_KEY_BASE_ID];
|
||||
|
||||
//update_time
|
||||
long long cloud_update_time = 0;
|
||||
if (preset_values.find(BBL_JSON_KEY_UPDATE_TIME) != preset_values.end()) {
|
||||
|
@ -1619,12 +1612,6 @@ bool PresetCollection::load_user_preset(std::string name, std::map<std::string,
|
|||
}
|
||||
std::string cloud_user_id = preset_values[BBL_JSON_KEY_USER_ID];
|
||||
|
||||
//filament_id
|
||||
std::string cloud_filament_id;
|
||||
if ((m_type == Preset::TYPE_FILAMENT) && preset_values.find(BBL_JSON_KEY_FILAMENT_ID) != preset_values.end()) {
|
||||
cloud_filament_id = preset_values[BBL_JSON_KEY_FILAMENT_ID];
|
||||
}
|
||||
|
||||
lock();
|
||||
//std::string name = preset->name;
|
||||
auto iter = this->find_preset_internal(name);
|
||||
|
@ -1637,6 +1624,11 @@ bool PresetCollection::load_user_preset(std::string name, std::map<std::string,
|
|||
iter->sync_info = "update";
|
||||
else
|
||||
iter->sync_info.clear();
|
||||
// Fixup possible data lost
|
||||
iter->setting_id = cloud_setting_id;
|
||||
fs::path idx_file(iter->file);
|
||||
idx_file.replace_extension(".info");
|
||||
iter->save_info(idx_file.string());
|
||||
BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << boost::format("preset %1%'s update_time is eqaul or newer, cloud update_time %2%, local update_time %3%")%name %cloud_update_time %iter->updated_time;
|
||||
unlock();
|
||||
return false;
|
||||
|
@ -1647,7 +1639,20 @@ bool PresetCollection::load_user_preset(std::string name, std::map<std::string,
|
|||
}
|
||||
}
|
||||
|
||||
DynamicPrintConfig new_config, cloud_config;
|
||||
// base_id
|
||||
if (preset_values.find(BBL_JSON_KEY_BASE_ID) == preset_values.end()) {
|
||||
BOOST_LOG_TRIVIAL(warning) << __FUNCTION__ << boost::format("can not find base_id, not loading for user preset %1%") % name;
|
||||
return false;
|
||||
}
|
||||
std::string cloud_base_id = preset_values[BBL_JSON_KEY_BASE_ID];
|
||||
|
||||
//filament_id
|
||||
std::string cloud_filament_id;
|
||||
if ((m_type == Preset::TYPE_FILAMENT) && preset_values.find(BBL_JSON_KEY_FILAMENT_ID) != preset_values.end()) {
|
||||
cloud_filament_id = preset_values[BBL_JSON_KEY_FILAMENT_ID];
|
||||
}
|
||||
|
||||
DynamicPrintConfig new_config, cloud_config;
|
||||
try {
|
||||
ConfigSubstitutions config_substitutions = cloud_config.load_string_map(preset_values, rule);
|
||||
if (! config_substitutions.empty())
|
||||
|
|
|
@ -4544,6 +4544,7 @@ void GUI_App::sync_preset(Preset* preset)
|
|||
result = 0;
|
||||
updated_info = "hold";
|
||||
BOOST_LOG_TRIVIAL(error) << "[sync_preset] put setting_id = " << setting_id << " failed, http_code = " << http_code;
|
||||
} else {
|
||||
auto update_time_str = values_map[BBL_JSON_KEY_UPDATE_TIME];
|
||||
if (!update_time_str.empty())
|
||||
update_time = std::atoll(update_time_str.c_str());
|
||||
|
@ -4638,7 +4639,7 @@ void GUI_App::start_sync_user_preset(bool with_progress_dlg)
|
|||
update_time = std::atoll(update_time_str.c_str());
|
||||
if (type == "filament") {
|
||||
return preset_bundle->filaments.need_sync(name, setting_id, update_time);
|
||||
} else if (type == "machine") {
|
||||
} else if (type == "print") {
|
||||
return preset_bundle->prints.need_sync(name, setting_id, update_time);
|
||||
} else if (type == "printer") {
|
||||
return preset_bundle->printers.need_sync(name, setting_id, update_time);
|
||||
|
@ -4664,6 +4665,7 @@ void GUI_App::start_sync_user_preset(bool with_progress_dlg)
|
|||
if (sync_count > 0) {
|
||||
for (Preset& preset : presets_to_sync) {
|
||||
sync_preset(&preset);
|
||||
boost::this_thread::sleep_for(boost::chrono::milliseconds(100));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -4671,6 +4673,7 @@ void GUI_App::start_sync_user_preset(bool with_progress_dlg)
|
|||
if (sync_count > 0) {
|
||||
for (Preset& preset : presets_to_sync) {
|
||||
sync_preset(&preset);
|
||||
boost::this_thread::sleep_for(boost::chrono::milliseconds(100));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -4678,6 +4681,7 @@ void GUI_App::start_sync_user_preset(bool with_progress_dlg)
|
|||
if (sync_count > 0) {
|
||||
for (Preset& preset : presets_to_sync) {
|
||||
sync_preset(&preset);
|
||||
boost::this_thread::sleep_for(boost::chrono::milliseconds(100));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue