mirror of
https://github.com/OrcaSlicer/OrcaSlicer.git
synced 2026-07-18 08:22:06 +00:00
Remove leftover cache file
This commit is contained in:
@@ -347,20 +347,12 @@ void GuideFrame::OnNavigationComplete(wxWebViewEvent &evt)
|
||||
if (!bFirstComplete) {
|
||||
bFirstComplete = true;
|
||||
try {
|
||||
// Steps 1 and 2 run on the main thread: safe to access preset_bundle and
|
||||
// filesystem. Only fall through to the background thread for slow paths.
|
||||
init_guide_paths();
|
||||
const bool cache_hit = try_load_guide_cache();
|
||||
if (cache_hit) {
|
||||
if (BuildProfileDataFromPresetBundle()) {
|
||||
if (!m_destroy)
|
||||
on_profile_loaded();
|
||||
} else if (BuildProfileDataFromPresetBundle()) {
|
||||
if (!m_destroy) {
|
||||
save_guide_cache();
|
||||
on_profile_loaded();
|
||||
}
|
||||
} else {
|
||||
// Steps 3+4 are slow — delegate to background thread.
|
||||
// Presets not yet in memory — delegate to background thread.
|
||||
m_load_task = std::make_unique<boost::thread>(boost::bind(&GuideFrame::LoadProfileData, this));
|
||||
}
|
||||
} catch (const std::exception& e) {
|
||||
@@ -1319,62 +1311,6 @@ bool GuideFrame::BuildProfileDataFromPresetBundle()
|
||||
}
|
||||
}
|
||||
|
||||
static std::string guide_cache_path()
|
||||
{
|
||||
// Keep this out of data_dir/system/ — that directory is scanned for vendor JSONs
|
||||
// and a non-vendor JSON there crashes get_version_from_json() on startup.
|
||||
return (boost::filesystem::path(Slic3r::data_dir()) / "guide_profile_cache.json")
|
||||
.make_preferred().string();
|
||||
}
|
||||
|
||||
// Tries to load the user-side guide profile JSON cache.
|
||||
// Returns true and populates m_ProfileJson on cache hit.
|
||||
bool GuideFrame::try_load_guide_cache()
|
||||
{
|
||||
const std::string path = guide_cache_path();
|
||||
if (!boost::filesystem::exists(path))
|
||||
return false;
|
||||
try {
|
||||
std::string contents;
|
||||
if (!LoadFile(path, contents))
|
||||
return false;
|
||||
const json cache = json::parse(contents);
|
||||
if (!cache.contains("vendor_versions") || !cache.contains("profile_data"))
|
||||
return false;
|
||||
|
||||
const json& vv = cache["vendor_versions"];
|
||||
|
||||
// Every vendor in the cache must still have the same version.
|
||||
for (const auto& [filename, cached_ver] : vv.items()) {
|
||||
boost::filesystem::path fp = rsrc_vendor_dir / filename;
|
||||
if (!boost::filesystem::exists(fp))
|
||||
fp = vendor_dir / filename;
|
||||
if (!boost::filesystem::exists(fp))
|
||||
return false;
|
||||
const Semver disk_ver = get_version_from_json(fp.string());
|
||||
const std::string disk_ver_str = disk_ver.valid() ? disk_ver.to_string() : "";
|
||||
if (disk_ver_str != cached_ver.get<std::string>())
|
||||
return false;
|
||||
}
|
||||
|
||||
// No new vendor JSONs must have appeared since the cache was built.
|
||||
for (const auto* dir_ptr : {&rsrc_vendor_dir, &vendor_dir}) {
|
||||
for (const auto& e : boost::filesystem::directory_iterator(*dir_ptr)) {
|
||||
if (e.path().extension().string() != ".json") continue;
|
||||
if (!vv.contains(e.path().filename().string()))
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
m_ProfileJson = cache["profile_data"];
|
||||
BOOST_LOG_TRIVIAL(info) << "GuideFrame: guide profile cache hit: " << path;
|
||||
return true;
|
||||
} catch (const std::exception& ex) {
|
||||
BOOST_LOG_TRIVIAL(warning) << "GuideFrame: guide cache load failed: " << ex.what();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
// Builds guide profile JSON from the per-vendor bundled caches
|
||||
// (resources/profiles/<vendor>.cache, generated by CI).
|
||||
// This avoids the 90-second LoadProfileFamily fallback on first launch.
|
||||
@@ -1399,8 +1335,7 @@ bool GuideFrame::BuildProfileDataFromBundledCache()
|
||||
const std::string vendor_id = cache_path.stem().string();
|
||||
// Validate against the version in the corresponding vendor JSON.
|
||||
const boost::filesystem::path json_path = rsrc_vendor_dir / (vendor_id + ".json");
|
||||
const Semver ver = get_version_from_json(json_path.string());
|
||||
const std::string ver_str = ver.valid() ? ver.to_string() : "";
|
||||
const std::string ver_str = get_vendor_cache_key(json_path.string());
|
||||
|
||||
PresetBundle::VendorCache vc;
|
||||
if (!vc.load(cache_path.string()) || !vc.is_valid(ver_str))
|
||||
@@ -1505,43 +1440,15 @@ bool GuideFrame::BuildProfileDataFromBundledCache()
|
||||
}
|
||||
}
|
||||
|
||||
void GuideFrame::save_guide_cache() const
|
||||
{
|
||||
try {
|
||||
json cache;
|
||||
// Record version strings (not mtimes) so the cache is portable
|
||||
// across machines and survives file extraction timestamp changes.
|
||||
for (const auto* dir_ptr : {&rsrc_vendor_dir, &vendor_dir}) {
|
||||
for (const auto& e : boost::filesystem::directory_iterator(*dir_ptr)) {
|
||||
if (e.path().extension().string() != ".json") continue;
|
||||
// Store version for all files, including version-less ones (empty string).
|
||||
// try_load_guide_cache checks ALL json files, so blacklist.json etc. must be present.
|
||||
const Semver ver = get_version_from_json(e.path().string());
|
||||
cache["vendor_versions"][e.path().filename().string()] =
|
||||
ver.valid() ? ver.to_string() : "";
|
||||
}
|
||||
}
|
||||
cache["profile_data"] = m_ProfileJson;
|
||||
|
||||
boost::filesystem::create_directories(
|
||||
boost::filesystem::path(guide_cache_path()).parent_path());
|
||||
boost::nowide::ofstream ofs(guide_cache_path());
|
||||
ofs << cache.dump(-1, ' ', false, json::error_handler_t::ignore);
|
||||
BOOST_LOG_TRIVIAL(info) << "GuideFrame: guide profile cache saved to " << guide_cache_path();
|
||||
} catch (const std::exception& e) {
|
||||
BOOST_LOG_TRIVIAL(warning) << "GuideFrame: guide cache save failed: " << e.what();
|
||||
}
|
||||
}
|
||||
|
||||
int GuideFrame::LoadProfileData()
|
||||
{
|
||||
// Background thread: Steps 1+2 already ran on the main thread in OnNavigationComplete
|
||||
// and both failed. This function handles only Steps 3 (bundled cache) and 4 (slow JSON walk).
|
||||
// Background thread: the fast path in OnNavigationComplete failed (presets not yet loaded).
|
||||
// Try bundled per-vendor caches first, then fall back to reading all vendor JSONs.
|
||||
try {
|
||||
// Step 3: bundled system preset cache (CI-generated, ~1-2s)
|
||||
// Bundled system preset cache (CI-generated, ~1-2s)
|
||||
bool slow_path = !BuildProfileDataFromBundledCache();
|
||||
if (slow_path) {
|
||||
// Step 4: last resort — read all vendor JSONs (~90s)
|
||||
// Last resort — read all vendor JSONs (~90s)
|
||||
std::set<std::string> loaded_vendors;
|
||||
auto filament_library_name = boost::filesystem::path(PresetBundle::ORCA_FILAMENT_LIBRARY).replace_extension(".json");
|
||||
if (boost::filesystem::exists(vendor_dir / filament_library_name))
|
||||
@@ -1581,10 +1488,6 @@ int GuideFrame::LoadProfileData()
|
||||
}
|
||||
}
|
||||
|
||||
// Promote to user guide cache so every subsequent open takes ~50ms.
|
||||
if (!m_destroy)
|
||||
save_guide_cache();
|
||||
|
||||
// Capture the cancel token by value (shared_ptr) so the lambda doesn't
|
||||
// touch `this` if GuideFrame is destroyed before the event fires.
|
||||
auto tok = m_cancel_token;
|
||||
|
||||
Reference in New Issue
Block a user