mirror of
https://github.com/OrcaSlicer/OrcaSlicer.git
synced 2026-07-20 01:12:09 +00:00
Handle corrupted files
This commit is contained in:
@@ -145,6 +145,9 @@ Semver get_version_from_json(std::string file_path)
|
||||
return Semver();
|
||||
//throw ConfigurationError(format("Failed loading configuration file \"%1%\": %2%", file_path, err.what()));
|
||||
}
|
||||
catch(...) {
|
||||
return Semver();
|
||||
}
|
||||
}
|
||||
|
||||
//BBS: add a function to load the key-values from xxx.json
|
||||
|
||||
@@ -2202,7 +2202,7 @@ std::pair<PresetsConfigSubstitutions, std::string> PresetBundle::load_system_pre
|
||||
const auto t0 = std::chrono::steady_clock::now();
|
||||
PresetBundleCache::SystemPresetsCache cache;
|
||||
const std::string cache_file = PresetBundleCache::SystemPresetsCache::cache_path();
|
||||
if (cache.load(cache_file)) {
|
||||
if (cache.load(cache_file) && cache.is_plausible()) {
|
||||
std::set<std::string> dirty;
|
||||
if (cache.get_dirty_vendors(dir.string(), dirty)) {
|
||||
if (dirty.empty()) {
|
||||
@@ -2230,7 +2230,7 @@ std::pair<PresetsConfigSubstitutions, std::string> PresetBundle::load_system_pre
|
||||
(boost::filesystem::path(resources_dir()) / "profiles").make_preferred().string();
|
||||
PresetBundleCache::SystemPresetsCache bundled;
|
||||
if (bundled.load(PresetBundleCache::SystemPresetsCache::bundled_cache_path()) &&
|
||||
bundled.is_valid(bundled_dir)) {
|
||||
bundled.is_valid(bundled_dir) && bundled.is_plausible()) {
|
||||
bundled.apply(*this);
|
||||
update_system_maps();
|
||||
// Promote to user cache so subsequent launches skip this check.
|
||||
|
||||
@@ -122,6 +122,13 @@ struct SystemPresetsCache {
|
||||
static std::string cache_path();
|
||||
static std::string bundled_cache_path();
|
||||
bool is_valid(const std::string& system_dir) const;
|
||||
// Rejects caches that loaded structurally but contain no data or are internally inconsistent
|
||||
// (e.g. vendor_versions lists all vendors but vendor_profiles only captured some of them).
|
||||
bool is_plausible() const {
|
||||
return !vendor_profiles.empty() &&
|
||||
!printer_presets.empty() &&
|
||||
vendor_versions.size() == vendor_profiles.size();
|
||||
}
|
||||
// Returns false on structural mismatch (full re-parse required).
|
||||
// On true, populates out_dirty with vendor IDs whose version strings changed.
|
||||
// Empty out_dirty means fully valid (cache hit, no re-parse needed).
|
||||
|
||||
Reference in New Issue
Block a user