18std::vector<std::pair<std::string, std::filesystem::path>> ProtonCache::cachedVersions_;
21std::chrono::system_clock::time_point ProtonCache::cacheTime_;
22std::mutex ProtonCache::cacheMutex_;
23bool ProtonCache::cacheInitialized_ =
false;
31 std::lock_guard<std::mutex> lock(cacheMutex_);
34 if (!cacheInitialized_ || isCacheExpired())
39 return cachedVersions_;
46 std::vector<std::string> names;
47 names.reserve(versions.size());
49 for (
const auto& [name, path] : versions)
51 names.push_back(name);
55 std::sort(names.begin(), names.end(),
56 [](
const std::string& a,
const std::string& b)
58 bool aCachy = (a.find(
"cachyos") != std::string::npos ||
59 a.find(
"CachyOS") != std::string::npos);
60 bool bCachy = (b.find(
"cachyos") != std::string::npos ||
61 b.find(
"CachyOS") != std::string::npos);
62 bool aExperimental = (a.find(
"Experimental") != std::string::npos);
63 bool bExperimental = (b.find(
"Experimental") != std::string::npos);
66 if (aCachy && !bCachy)
68 if (!aCachy && bCachy)
72 if (aExperimental && !bExperimental)
74 if (!aExperimental && bExperimental)
90 std::lock_guard<std::mutex> lock(cacheMutex_);
91 cacheInitialized_ =
false;
92 cachedVersions_.clear();
98 std::lock_guard<std::mutex> lock(cacheMutex_);
99 return cacheInitialized_ && !isCacheExpired();
104 std::lock_guard<std::mutex> lock(cacheMutex_);
106 if (!cacheInitialized_)
111 auto now = std::chrono::system_clock::now();
112 auto age = std::chrono::duration_cast<std::chrono::seconds>(now - cacheTime_);
113 return static_cast<int>(age.count());
120void ProtonCache::updateCache()
122 Logger::info(
"[ProtonCache] Scanning for Proton versions...");
128 cacheTime_ = std::chrono::system_clock::now();
129 cacheInitialized_ =
true;
131 Logger::info(
"[ProtonCache] Found {} Proton versions (cached for {} seconds)",
135bool ProtonCache::isCacheExpired()
137 if (!cacheInitialized_)
142 auto now = std::chrono::system_clock::now();
143 auto age = std::chrono::duration_cast<std::chrono::seconds>(now - cacheTime_);
static void info(const std::string &message, Args &&... args)
Log info message (general information).
static int getCacheAge()
Get cache age in seconds.
static std::vector< std::string > getSortedVersionNames()
Get sorted Proton version names only.
static std::vector< std::pair< std::string, std::filesystem::path > > getVersions()
Get cached Proton versions.
static void invalidate()
Invalidate the cache.
static bool isValid()
Check if cache is currently valid.
static std::vector< std::pair< std::string, std::filesystem::path > > scanProtonVersions()
Scan for all installed Proton versions.
constexpr int PROTON_CACHE_VALIDITY_SEC
Validity period for Proton version cache (seconds).