FIX:add "read fail" deal for bambuStudio.conf

jira: STUDIO-10215?
Change-Id: Ib6dca514a43f3c91948df56195ba323aa9ce308e
This commit is contained in:
zhou.xu 2025-02-06 17:30:04 +08:00 committed by lane.wei
parent 751aece03e
commit 62fff9dadf
4 changed files with 31 additions and 14 deletions

View File

@ -482,23 +482,33 @@ std::string AppConfig::load()
std::string error_message;
try {
ifs.open(AppConfig::loading_path());
auto path = AppConfig::loading_path();
ifs.open(path);
if (!ifs.is_open()) {
BOOST_LOG_TRIVIAL(info) << "AppConfig::load() open fail:" << AppConfig::loading_path();
return "Line break format may be incorrect.";
}
#ifdef WIN32
std::stringstream input_stream;
input_stream << ifs.rdbuf();
std::string total_string = input_stream.str();
size_t last_pos = total_string.find_last_of('}');
std::string left_string = total_string.substr(0, last_pos+1);
//skip the "\n"
std::string right_string = total_string.substr(last_pos+2);
if (total_string.empty()) {
BOOST_LOG_TRIVIAL(info) << "AppConfig::load() read fail:" << AppConfig::loading_path();
return "read fail.";
} else {
size_t last_pos = total_string.find_last_of('}');
std::string left_string = total_string.substr(0, last_pos + 1);
// skip the "\n"
std::string right_string = total_string.substr(last_pos + 2);
std::string md5_str = appconfig_md5_hash_line({left_string.data()});
// Verify the checksum of the config file without taking just for debugging purpose.
if (md5_str != right_string)
BOOST_LOG_TRIVIAL(info) << "The configuration file " << AppConfig::loading_path() <<
" has a wrong MD5 checksum or the checksum is missing. This may indicate a file corruption or a harmless user edit.";
j = json::parse(left_string);
std::string md5_str = appconfig_md5_hash_line({left_string.data()});
// Verify the checksum of the config file without taking just for debugging purpose.
if (md5_str != right_string) {
BOOST_LOG_TRIVIAL(info) << "The configuration file " << AppConfig::loading_path()
<< " has a wrong MD5 checksum or the checksum is missing. This may indicate a file corruption or a harmless user edit.";
}
j = json::parse(left_string);
}
#else
ifs >> j;
#endif

View File

@ -794,6 +794,10 @@ ConfigSubstitutions ConfigBase::load_from_json(const std::string &file, ForwardC
int ConfigBase::load_from_json(const std::string &file, ConfigSubstitutionContext& substitution_context, bool load_inherits_to_config, std::map<std::string, std::string>& key_values, std::string& reason)
{
if (!boost::filesystem::exists(file)) {
BOOST_LOG_TRIVIAL(error) << __FUNCTION__ << boost::format("%1% file not exist.") % file;
return -1;
}
json j;
std::list<std::string> different_settings_append;
std::string new_support_style;

View File

@ -3676,6 +3676,10 @@ std::pair<PresetsConfigSubstitutions, size_t> PresetBundle::load_vendor_configs_
for (auto& machine_model : machine_model_subfiles)
{
std::string subfile = path + "/" + vendor_name + "/" + machine_model.second;
if (!boost::filesystem::exists(subfile)) {
BOOST_LOG_TRIVIAL(error) << __FUNCTION__ << boost::format("%1% file not exist.") % subfile;
continue;
}
VendorProfile::PrinterModel model;
model.id = machine_model.first;
try {

View File

@ -2372,8 +2372,7 @@ void GUI_App::init_app_config()
BOOST_LOG_TRIVIAL(error) << __FUNCTION__
<< "Configuration file may be corrupted and is not able to be parsed.Please delete the file and try again.";
throw Slic3r::RuntimeError(
_u8L("BambuStudio configuration file may be corrupted and is not able to be parsed."
"Please delete the file and try again.") +
_u8L("BambuStudio configuration file read failed. Please manually backup and delete it, and then restart BambuStudio software.") +
"\n\n" + app_config->config_path() + "\n\n" + error);
}
// Save orig_version here, so its empty if no app_config existed before this run.