diff --git a/src/libslic3r/AppConfig.cpp b/src/libslic3r/AppConfig.cpp index e96faec66..50920a54c 100644 --- a/src/libslic3r/AppConfig.cpp +++ b/src/libslic3r/AppConfig.cpp @@ -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 diff --git a/src/libslic3r/Config.cpp b/src/libslic3r/Config.cpp index 188a2e7ea..c9ffbff18 100644 --- a/src/libslic3r/Config.cpp +++ b/src/libslic3r/Config.cpp @@ -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& 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 different_settings_append; std::string new_support_style; diff --git a/src/libslic3r/PresetBundle.cpp b/src/libslic3r/PresetBundle.cpp index 0fb3b6e23..7cc50e3c8 100644 --- a/src/libslic3r/PresetBundle.cpp +++ b/src/libslic3r/PresetBundle.cpp @@ -3676,6 +3676,10 @@ std::pair 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 { diff --git a/src/slic3r/GUI/GUI_App.cpp b/src/slic3r/GUI/GUI_App.cpp index 8192080ce..500533e61 100644 --- a/src/slic3r/GUI/GUI_App.cpp +++ b/src/slic3r/GUI/GUI_App.cpp @@ -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.