26#include <linux/limits.h>
29#include <nlohmann/json.hpp>
30#include <openssl/crypto.h>
31#include <openssl/evp.h>
39using json = nlohmann::json;
40namespace fs = std::filesystem;
51 [](
const std::shared_ptr<std::future<void>>& fu)
53 return fu->wait_for(std::chrono::seconds(0)) ==
54 std::future_status::ready;
99 return dir /
"github_release_etags.json";
104 using namespace std::chrono;
105 auto now = system_clock::now();
106 auto t = system_clock::to_time_t(now);
110 std::strftime(buf,
sizeof(buf),
"%Y-%m-%dT%H:%M:%SZ", &tm);
119 std::map<std::string, GitHubCacheEntry> out;
122 if (!std::filesystem::exists(path, ec) || ec)
127 std::ifstream f(path);
138 for (
auto it = j.begin(); it != j.end(); ++it)
140 const auto& v = it.value();
144 entry.
etag = v.value(
"etag",
"");
146 entry.
body = v.value(
"body",
"");
147 entry.
fetchedAt = v.value(
"fetched_at",
"");
148 out.emplace(it.key(), std::move(entry));
151 catch (
const std::exception& e)
153 Logger::warn(
"[RunnerDownload] github_release_etags.json is malformed "
154 "({}); ignoring cache.",
171 std::filesystem::create_directories(path.parent_path(), ec);
174 Logger::warn(
"[RunnerDownload] Cannot create cache dir {}: {}", path.parent_path().string(),
179 json j = json::object();
180 for (
const auto& [key, e] : cache)
184 {
"last_modified", e.lastModified},
186 {
"fetched_at", e.fetchedAt},
193 Logger::warn(
"[RunnerDownload] Failed to persist {}: {}", path.string(), err);
209 size_t total = size * nitems;
210 if (total == 0 || !ctx)
213 std::string line(buffer, total);
214 while (!line.empty() && (line.back() ==
'\n' || line.back() ==
'\r'))
218 auto colon = line.find(
':');
219 if (colon == std::string::npos)
222 std::string name = line.substr(0, colon);
223 std::string value = line.substr(colon + 1);
226 std::transform(name.begin(), name.end(), name.begin(),
227 [](
unsigned char c) { return static_cast<char>(::tolower(c)); });
229 size_t firstNonSpace = value.find_first_not_of(
" \t");
230 if (firstNonSpace != std::string::npos)
231 value.erase(0, firstNonSpace);
237 else if (name ==
"last-modified")
239 ctx->lastModified = value;
264 return "VKD3D-Proton";
299 return "manual-only";
311 constexpr int64_t kKB = 1024;
312 constexpr int64_t kMB = kKB * kKB;
313 constexpr int64_t kGB = kMB * kKB;
316 return std::to_string(
size) +
" B";
318 return std::to_string(
size / kKB) +
" KB";
320 return std::to_string(
size / kMB) +
" MB";
321 return std::to_string(
size / kGB) +
" GB";
331 return "Downloading";
388 size_t realsize = size * nmemb;
394 if (ctx->cancelled && ctx->cancelled->load(std::memory_order_acquire))
401 ctx->file->write(
static_cast<char*
>(contents),
static_cast<std::streamsize
>(realsize));
406 if (!ctx->file->good())
408 ctx->writeFailed =
true;
412 else if (ctx->buffer)
414 ctx->buffer->append(
static_cast<char*
>(contents), realsize);
419 if (ctx->callback && ctx->totalBytes > 0)
426 std::min(
static_cast<int64_t
>(100), (ctx->downloadedBytes * 100) / ctx->totalBytes));
427 ctx->callback(progress);
440 if (ctx->cancelled && ctx->cancelled->load(std::memory_order_acquire))
447 ctx->totalBytes = dltotal;
468 static std::once_flag curlInitFlag;
469 std::call_once(curlInitFlag,
472 if (curl_global_init(CURL_GLOBAL_DEFAULT) == CURLE_OK)
474 std::atexit([]() { curl_global_cleanup(); });
483 for (
auto& [type, flag] : impl_->cancelFlags)
485 flag.store(
true, std::memory_order_release);
493std::string RunnerDownloadService::getGitHubOwner(
RunnerType type)
499 return "GloriousEggroll";
501 return "Frogging-Family";
503 return "luxtorpeda-dev";
507 return "HansKristian-Work";
509 return "Open-Wine-Components";
515std::string RunnerDownloadService::getGitHubRepo(
RunnerType type)
520 return "proton-ge-custom";
522 return "wine-ge-custom";
524 return "wine-tkg-git";
530 return "vkd3d-proton";
532 return "umu-launcher";
538std::vector<RunnerRelease>
539RunnerDownloadService::fetchGitHubReleases(
const std::string& owner,
const std::string& repo,
540 RunnerType type,
bool includePrerelease,
int maxResults)
542 std::vector<RunnerRelease> releases;
544 std::string url =
"https://api.github.com/repos/" + owner +
"/" + repo +
545 "/releases?per_page=" + std::to_string(maxResults);
558 const std::string cacheKey = owner +
"/" + repo +
"?per_page=" + std::to_string(maxResults);
559 GitHubCacheEntry cached;
560 bool haveCachedEntry =
false;
562 std::lock_guard<std::mutex> lock(gitHubCacheMutex_);
564 auto it = allCache.find(cacheKey);
565 if (it != allCache.end())
569 !cached.body.empty() && (!cached.etag.empty() || !cached.lastModified.empty());
573 CURL* curl = curl_easy_init();
580 std::string response;
582 ctx.buffer = &response;
584 HeaderCaptureCtx hctx;
586 curl_easy_setopt(curl, CURLOPT_URL, url.c_str());
587 curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, writeCallback);
588 curl_easy_setopt(curl, CURLOPT_WRITEDATA, &ctx);
589 curl_easy_setopt(curl, CURLOPT_HEADERFUNCTION, headerCaptureCallback);
590 curl_easy_setopt(curl, CURLOPT_HEADERDATA, &hctx);
591 curl_easy_setopt(curl, CURLOPT_USERAGENT,
"GameLauncher/1.0");
592 curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1L);
593 curl_easy_setopt(curl, CURLOPT_TIMEOUT, 30L);
598 curl_easy_setopt(curl, CURLOPT_CONNECTTIMEOUT, 10L);
599 curl_easy_setopt(curl, CURLOPT_MAXREDIRS, 10L);
600#if CURL_AT_LEAST_VERSION(7, 85, 0)
601 curl_easy_setopt(curl, CURLOPT_PROTOCOLS_STR,
"https");
602 curl_easy_setopt(curl, CURLOPT_REDIR_PROTOCOLS_STR,
"https");
604 curl_easy_setopt(curl, CURLOPT_PROTOCOLS, CURLPROTO_HTTPS);
605 curl_easy_setopt(curl, CURLOPT_REDIR_PROTOCOLS, CURLPROTO_HTTPS);
607 curl_easy_setopt(curl, CURLOPT_SSL_VERIFYPEER, 1L);
608 curl_easy_setopt(curl, CURLOPT_SSL_VERIFYHOST, 2L);
614 struct curl_slist* headers =
nullptr;
615 headers = curl_slist_append(headers,
"Accept: application/vnd.github+json");
616 headers = curl_slist_append(headers,
"X-GitHub-Api-Version: 2022-11-28");
620 if (!cached.etag.empty())
622 std::string h =
"If-None-Match: " + cached.etag;
623 headers = curl_slist_append(headers, h.c_str());
625 if (!cached.lastModified.empty())
627 std::string h =
"If-Modified-Since: " + cached.lastModified;
628 headers = curl_slist_append(headers, h.c_str());
635 const char* tokenEnv = std::getenv(
"GITHUB_TOKEN");
636 if (!tokenEnv || tokenEnv[0] ==
'\0')
638 tokenEnv = std::getenv(
"GH_TOKEN");
640 if (tokenEnv && tokenEnv[0] !=
'\0')
642 std::string h = std::string(
"Authorization: Bearer ") + tokenEnv;
643 headers = curl_slist_append(headers, h.c_str());
646 curl_easy_setopt(curl, CURLOPT_HTTPHEADER, headers);
648 CURLcode res = curl_easy_perform(curl);
650 curl_easy_getinfo(curl, CURLINFO_RESPONSE_CODE, &httpStatus);
651 curl_slist_free_all(headers);
652 curl_easy_cleanup(curl);
656 Logger::error(
"[RunnerDownload] GitHub API request failed: {}", curl_easy_strerror(res));
661 Logger::info(
"[RunnerDownload] Falling back to disk-cached releases for {}", cacheKey);
662 response = cached.body;
669 else if (httpStatus == 304)
673 Logger::debug(
"[RunnerDownload] 304 Not Modified for {} — serving cached releases",
675 response = cached.body;
676 std::lock_guard<std::mutex> lock(gitHubCacheMutex_);
678 auto it = all.find(cacheKey);
685 else if (httpStatus >= 200 && httpStatus < 300)
691 if (!hctx.etag.empty() || !hctx.lastModified.empty())
693 std::lock_guard<std::mutex> lock(gitHubCacheMutex_);
695 GitHubCacheEntry entry;
696 entry.etag = hctx.etag;
697 entry.lastModified = hctx.lastModified;
698 entry.body = response;
700 all[cacheKey] = std::move(entry);
707 Logger::warn(
"[RunnerDownload] GitHub API returned HTTP {} for {}", httpStatus, cacheKey);
708 if (httpStatus == 403 || httpStatus == 429)
710 Logger::warn(
"[RunnerDownload] Likely rate-limit; set GITHUB_TOKEN to lift "
711 "the cap from 60/hr to 5000/hr.");
715 response = cached.body;
726 auto jsonReleases = json::parse(response);
728 for (
const auto& release : jsonReleases)
730 bool isPrerelease = release.value(
"prerelease",
false);
731 if (isPrerelease && !includePrerelease)
738 rel.
tag = release.value(
"tag_name",
"");
740 rel.
releaseDate = release.value(
"published_at",
"");
749 for (
const auto& asset : release.value(
"assets", nlohmann::json::array()))
751 std::string name = asset.value(
"name",
"");
752 std::string assetUrl = asset.value(
"browser_download_url",
"");
755 bool isMainAsset =
false;
760 isMainAsset = (name.find(
".tar.gz") != std::string::npos &&
761 name.find(
"sha512sum") == std::string::npos);
764 isMainAsset = (name.find(
".tar.xz") != std::string::npos &&
765 name.find(
"sha512sum") == std::string::npos);
769 isMainAsset = (name.find(
".tar.gz") != std::string::npos ||
770 name.find(
".tar.zst") != std::string::npos);
773 isMainAsset = (name.find(
".tar.") != std::string::npos &&
774 name.find(
"sum") == std::string::npos);
781 rel.
size = asset.value(
"size", 0);
785 if (name.find(
"sha512sum") != std::string::npos ||
786 name.find(
".sha512") != std::string::npos)
796 auto installPath = getInstallDir(type) / rel.
version;
803 releases.push_back(rel);
807 catch (
const json::exception& e)
809 Logger::error(
"[RunnerDownload] Failed to parse GitHub API response: {}", e.what());
819std::vector<RunnerRelease>
828 Logger::info(
"[RunnerDownload] {} is manual-only (no GitHub release polling); "
829 "install via distro packaging (e.g. AUR).",
834 std::lock_guard<std::mutex> lock(impl_->mutex);
837 auto now = std::chrono::system_clock::now();
838 auto age = std::chrono::duration_cast<std::chrono::seconds>(now - impl_->cacheTime).count();
842 return impl_->releaseCache[type];
846 std::string owner = getGitHubOwner(type);
847 std::string repo = getGitHubRepo(type);
849 if (owner.empty() || repo.empty())
855 auto releases = fetchGitHubReleases(owner, repo, type, includePrerelease, maxResults);
862 for (
auto& rel : releases)
866 if (!releases.empty())
868 Logger::info(
"[RunnerDownload] {} upstream is archived — final release is {}",
874 impl_->releaseCache[type] = releases;
875 impl_->cacheTime = now;
884 bool includePrerelease)
886 auto future = std::make_shared<std::future<void>>(
887 std::async(std::launch::async,
888 [
this, type, callback, includePrerelease]()
894 storeFuture(std::move(future));
898 bool includePrerelease)
901 if (releases.empty())
912bool RunnerDownloadService::downloadFile(
const std::string& url,
const fs::path& dest,
913 ProgressCallback callback, std::atomic<bool>& cancelled)
919 fs::create_directories(dest.parent_path(), ec);
922 Logger::error(
"[RunnerDownload] Cannot create parent directory {}: {}",
923 dest.parent_path().string(), ec.message());
927 std::ofstream file(dest, std::ios::binary);
930 Logger::error(
"[RunnerDownload] Failed to open file for writing: {}", dest.string());
937 using CurlHandle = std::unique_ptr<CURL,
decltype(&curl_easy_cleanup)>;
938 CurlHandle curl(curl_easy_init(), &curl_easy_cleanup);
947 ctx.callback = std::move(callback);
948 ctx.cancelled = &cancelled;
950 curl_easy_setopt(curl.get(), CURLOPT_URL, url.c_str());
951 curl_easy_setopt(curl.get(), CURLOPT_WRITEFUNCTION, writeCallback);
952 curl_easy_setopt(curl.get(), CURLOPT_WRITEDATA, &ctx);
953 curl_easy_setopt(curl.get(), CURLOPT_XFERINFOFUNCTION, progressCallback);
954 curl_easy_setopt(curl.get(), CURLOPT_XFERINFODATA, &ctx);
955 curl_easy_setopt(curl.get(), CURLOPT_NOPROGRESS, 0L);
956 curl_easy_setopt(curl.get(), CURLOPT_USERAGENT,
"GameLauncher/1.0");
957 curl_easy_setopt(curl.get(), CURLOPT_FOLLOWLOCATION, 1L);
958 curl_easy_setopt(curl.get(), CURLOPT_TIMEOUT, 3600L);
977#if CURL_AT_LEAST_VERSION(7, 85, 0)
978 curl_easy_setopt(curl.get(), CURLOPT_PROTOCOLS_STR,
"https");
979 curl_easy_setopt(curl.get(), CURLOPT_REDIR_PROTOCOLS_STR,
"https");
981 curl_easy_setopt(curl.get(), CURLOPT_PROTOCOLS, CURLPROTO_HTTPS);
982 curl_easy_setopt(curl.get(), CURLOPT_REDIR_PROTOCOLS, CURLPROTO_HTTPS);
984 curl_easy_setopt(curl.get(), CURLOPT_MAXREDIRS, 10L);
985 curl_easy_setopt(curl.get(), CURLOPT_SSL_VERIFYPEER, 1L);
986 curl_easy_setopt(curl.get(), CURLOPT_SSL_VERIFYHOST, 2L);
988 CURLcode res = curl_easy_perform(curl.get());
991 if (cancelled.load(std::memory_order_acquire))
993 fs::remove(dest, ec);
1003 fs::remove(dest, ec);
1004 Logger::error(
"[RunnerDownload] Write failed mid-transfer for {} "
1005 "(likely disk-full or I/O error)",
1010 if (res != CURLE_OK)
1012 fs::remove(dest, ec);
1013 Logger::error(
"[RunnerDownload] Download failed: {}", curl_easy_strerror(res));
1020bool RunnerDownloadService::verifyChecksum(
const fs::path& file,
const std::string& expected,
1021 const std::string& type)
1023 if (expected.empty())
1028 std::ifstream ifs(file, std::ios::binary);
1034 EVP_MD_CTX* ctx = EVP_MD_CTX_new();
1040 const EVP_MD* md =
nullptr;
1041 if (type ==
"sha512")
1045 else if (type ==
"sha256")
1051 EVP_MD_CTX_free(ctx);
1052 Logger::error(
"[RunnerDownload] Unknown checksum type '{}' — verification failed", type);
1056 EVP_DigestInit_ex(ctx, md,
nullptr);
1059 while (ifs.read(buffer,
sizeof(buffer)) || ifs.gcount() > 0)
1061 EVP_DigestUpdate(ctx, buffer,
static_cast<size_t>(ifs.gcount()));
1064 unsigned char hash[EVP_MAX_MD_SIZE];
1065 unsigned int hashLen = 0;
1066 EVP_DigestFinal_ex(ctx, hash, &hashLen);
1067 EVP_MD_CTX_free(ctx);
1070 std::stringstream ss;
1071 for (
unsigned int i = 0; i < hashLen; i++)
1073 ss << std::hex << std::setfill('0') << std::setw(2) << static_cast<int>(hash[i]);
1076 std::string computed = ss.str();
1082 if (computed.size() != expected.size())
1084 return CRYPTO_memcmp(computed.data(), expected.data(), computed.size()) == 0;
1088static bool endsWith(
const std::string& str,
const std::string& suffix)
1090 if (suffix.size() > str.size())
1092 return str.compare(str.size() - suffix.size(), suffix.size(), suffix) == 0;
1095bool RunnerDownloadService::extractArchive(
const fs::path& archive,
const fs::path& dest,
1096 const ProgressCallback& callback)
1099 fs::create_directories(dest);
1103 std::string archiveStr = archive.string();
1110 else if (
endsWith(archiveStr,
".tar.xz"))
1115 else if (
endsWith(archiveStr,
".tar.zst"))
1122 Logger::error(
"[RunnerDownload] Unsupported archive format: {}", archiveStr);
1128 DownloadProgress progress;
1130 progress.
currentFile = archive.filename().string();
1134 int result = std::system(cmd.c_str());
1136 if (result == -1 || !WIFEXITED(result) || WEXITSTATUS(result) != 0)
1138 Logger::error(
"[RunnerDownload] Extraction failed with code {}", result);
1144 DownloadProgress progress;
1162 std::atomic<bool>* cancelledPtr;
1164 std::lock_guard<std::mutex> lock(impl_->mutex);
1167 impl_->cancelFlags[release.
type].store(
false, std::memory_order_relaxed);
1168 cancelledPtr = &impl_->cancelFlags[release.
type];
1169 impl_->activeDownloads.insert(release.
type);
1171 auto& cancelled = *cancelledPtr;
1179 std::lock_guard<std::mutex> lock(impl->
mutex);
1182 } activeGuard{impl_.get(), release.
type};
1186 std::string tmplPath = (fs::temp_directory_path() /
"gamelauncher_dl_XXXXXX").
string();
1187 char tmplBuf[PATH_MAX];
1188 std::snprintf(tmplBuf,
sizeof(tmplBuf),
"%s", tmplPath.c_str());
1189 if (mkdtemp(tmplBuf) ==
nullptr)
1191 Logger::error(
"[RunnerDownload] Failed to create temp directory: {}", strerror(errno));
1194 fs::path tempDir(tmplBuf);
1197 std::string filename;
1199 size_t slashPos = release.
downloadUrl.find_last_of(
'/');
1200 filename = (slashPos != std::string::npos) ? release.
downloadUrl.substr(slashPos + 1)
1203 fs::path downloadPath = tempDir / filename;
1206 if (progressCallback)
1212 progressCallback(progress);
1216 if (!downloadFile(release.
downloadUrl, downloadPath, progressCallback, cancelled))
1218 std::error_code cleanEc;
1219 fs::remove_all(tempDir, cleanEc);
1221 if (cancelled.load(std::memory_order_acquire))
1223 if (progressCallback)
1227 progressCallback(progress);
1232 if (progressCallback)
1237 progressCallback(progress);
1245 if (progressCallback)
1250 progressCallback(progress);
1255 Logger::error(
"[RunnerDownload] Checksum verification failed");
1256 std::error_code cleanEc;
1257 fs::remove_all(tempDir, cleanEc);
1259 if (progressCallback)
1263 progress.
errorMessage =
"Checksum verification failed";
1264 progressCallback(progress);
1272 fs::path installDir = getInstallDir(release.
type);
1273 fs::path tempExtractDir = installDir / (
"_extract_tmp_" + release.
version);
1275 std::error_code mkdirEc;
1276 fs::create_directories(tempExtractDir, mkdirEc);
1279 fs::remove(downloadPath);
1280 Logger::error(
"[RunnerDownload] Failed to create temp extract dir: {}", mkdirEc.message());
1281 if (progressCallback)
1285 progress.
errorMessage =
"Failed to create temp directory";
1286 progressCallback(progress);
1291 if (!extractArchive(downloadPath, tempExtractDir, progressCallback))
1293 std::error_code rmEc;
1294 fs::remove(downloadPath);
1295 fs::remove_all(tempExtractDir, rmEc);
1296 fs::remove_all(tempDir, rmEc);
1298 if (progressCallback)
1303 progressCallback(progress);
1309 std::error_code moveEc;
1310 for (
const auto& entry : fs::directory_iterator(tempExtractDir, moveEc))
1312 fs::path dest = installDir / entry.path().filename();
1313 std::error_code renameEc;
1314 fs::rename(entry.path(), dest, renameEc);
1317 Logger::warn(
"[RunnerDownload] Failed to move {} to {}: {}", entry.path().string(),
1318 dest.string(), renameEc.message());
1321 fs::remove_all(tempExtractDir, moveEc);
1324 fs::remove(downloadPath);
1328 std::lock_guard<std::mutex> lock(impl_->mutex);
1329 impl_->installedCacheValid =
false;
1336 if (progressCallback)
1341 progressCallback(progress);
1351 return std::async(std::launch::async, [
this, release, progressCallback]()
1357 std::lock_guard<std::mutex> lock(impl_->mutex);
1358 if (impl_->cancelFlags.count(type) > 0)
1365 impl_->cancelFlags[type].store(
true, std::memory_order_release);
1372 std::lock_guard<std::mutex> lock(impl_->mutex);
1373 return impl_->activeDownloads.count(type) > 0;
1382 const char* homeEnv = std::getenv(
"HOME");
1385 Logger::error(
"[RunnerDownload] HOME environment variable not set");
1388 fs::path home = homeEnv;
1399 return home /
".steam/root/compatibilitytools.d";
1401 return home /
".local/share/lutris/runners/wine";
1403 return home /
".local/share/dxvk";
1405 return home /
".local/share/vkd3d-proton";
1407 return home /
".local/share/umu";
1409 return home /
".local/share/gamelauncher/runners";
1413fs::path RunnerDownloadService::getInstallDir(
RunnerType type)
const
1415 std::lock_guard<std::mutex> lock(impl_->mutex);
1417 if (impl_->customPaths.count(type) > 0)
1419 return impl_->customPaths.at(type);
1426 std::lock_guard<std::mutex> lock(impl_->mutex);
1427 impl_->customPaths[type] = path;
1428 impl_->installedCacheValid =
false;
1433 std::vector<InstalledRunner> all;
1441 all.insert(all.end(), runners.begin(), runners.end());
1449 std::vector<InstalledRunner> runners;
1450 fs::path installDir = getInstallDir(type);
1452 if (!fs::exists(installDir))
1459 for (
const auto& entry : fs::directory_iterator(installDir))
1461 if (!entry.is_directory())
1466 std::string name = entry.path().filename().string();
1469 bool isValid =
false;
1474 isValid = fs::exists(entry.path() /
"proton");
1477 isValid = fs::exists(entry.path() /
"bin" /
"wine");
1484 isValid = fs::exists(entry.path() /
"x64");
1497 runner.
path = entry.path();
1501 auto ftime = fs::last_write_time(entry.path());
1502 auto sctp = std::chrono::time_point_cast<std::chrono::system_clock::duration>(
1503 ftime - fs::file_time_type::clock::now() + std::chrono::system_clock::now());
1508 for (
const auto& file : fs::recursive_directory_iterator(entry.path()))
1510 if (file.is_regular_file())
1512 runner.
sizeBytes +=
static_cast<int64_t
>(file.file_size());
1516 runners.push_back(runner);
1520 catch (
const fs::filesystem_error& e)
1522 Logger::error(
"[RunnerDownload] Error scanning {}: {}", installDir.string(), e.what());
1527 { return a.version > b.version; });
1535 return std::any_of(runners.begin(), runners.end(),
1536 [&version](
const InstalledRunner& r) { return r.version == version; });
1541 fs::path installDir = getInstallDir(type);
1542 fs::path runnerPath = installDir / version;
1547 std::error_code ec1, ec2;
1548 fs::path canonical = fs::weakly_canonical(runnerPath, ec1);
1549 fs::path canonicalInstall = fs::weakly_canonical(installDir, ec2);
1552 Logger::error(
"[RunnerDownload] Refused to uninstall '{}': cannot canonicalize path",
1558 std::error_code relEc;
1559 fs::path rel = fs::relative(canonical, canonicalInstall, relEc);
1560 if (relEc || rel.empty() || rel.string().find(
"..") == 0)
1562 Logger::error(
"[RunnerDownload] Refused to uninstall '{}': path outside install dir",
1567 if (!fs::exists(runnerPath))
1569 Logger::error(
"[RunnerDownload] Runner not found: {}", runnerPath.string());
1575 fs::remove_all(runnerPath);
1580 std::lock_guard<std::mutex> lock(impl_->mutex);
1581 impl_->installedCacheValid =
false;
1587 catch (
const fs::filesystem_error& e)
1589 Logger::error(
"[RunnerDownload] Failed to uninstall {}: {}", version, e.what());
1598 if (
static_cast<int>(runners.size()) <= keepCount)
1604 for (
size_t i =
static_cast<size_t>(keepCount); i < runners.size(); i++)
1617 std::lock_guard<std::mutex> lock(impl_->mutex);
1618 impl_->releaseCache.clear();
1619 impl_->installedCacheValid =
false;
1624 std::lock_guard<std::mutex> lock(impl_->mutex);
1625 impl_->installedCacheValid =
false;
static void info(const std::string &message, Args &&... args)
Log info message (general information).
static void debug(const std::string &message, Args &&... args)
Log debug message (verbose development info).
static void error(const std::string &message, Args &&... args)
Log error message (recoverable failure).
static void warn(const std::string &message, Args &&... args)
Log warning message (non-critical issue).
static void invalidate()
Invalidate the cache.
std::function< void(const DownloadProgress &)> ProgressCallback
bool uninstallRunner(RunnerType type, const std::string &version)
Uninstall a runner version.
bool isInstalled(RunnerType type, const std::string &version) const
Check if a specific version is installed.
bool downloadRunner(const RunnerRelease &release, const ProgressCallback &progressCallback=nullptr)
Download and install a runner.
std::function< void(const std::vector< RunnerRelease > &)> ReleaseCallback
void setInstallPath(RunnerType type, const std::filesystem::path &path)
Set custom installation directory.
void refreshInstalled()
Refresh installed runners list.
std::future< bool > downloadRunnerAsync(const RunnerRelease &release, const ProgressCallback &progressCallback=nullptr)
Download and install a runner asynchronously.
std::vector< RunnerRelease > getAvailableReleases(RunnerType type, bool includePrerelease=false, int maxResults=20)
Get available releases for a runner type.
bool isDownloading(RunnerType type) const
Check if a download is in progress.
void clearCache()
Clear the releases cache.
void getAvailableReleasesAsync(RunnerType type, const ReleaseCallback &callback, bool includePrerelease=false)
Get available releases asynchronously.
static std::filesystem::path getDefaultInstallPath(RunnerType type)
Get default installation directory for a runner type.
int cleanupOldVersions(RunnerType type, int keepCount=3)
Clean up old versions, keeping newest N.
void cancelDownload(RunnerType type)
Cancel an ongoing download.
std::optional< RunnerRelease > getLatestRelease(RunnerType type, bool includePrerelease=false)
Get the latest release for a runner type.
std::vector< InstalledRunner > getInstalledRunners() const
Get all installed runners.
static std::string escapeArg(const std::string &arg)
Escape a string for safe use as a shell argument.
std::map< std::string, GitHubCacheEntry > loadGitHubCache()
void saveGitHubCache(const std::map< std::string, GitHubCacheEntry > &cache)
std::mutex gitHubCacheMutex_
std::filesystem::path gitHubCacheFilePath()
void storeFuture(std::shared_ptr< std::future< void > > f)
int progressCallback(void *userp, curl_off_t dltotal, curl_off_t, curl_off_t, curl_off_t)
size_t writeCallback(void *contents, size_t size, size_t nmemb, void *userp)
size_t headerCaptureCallback(char *buffer, size_t size, size_t nitems, void *userdata)
std::vector< std::shared_ptr< std::future< void > > > activeFutures_
bool atomicWriteFile(const std::filesystem::path &targetPath, std::string_view contents, std::string *errOut=nullptr)
Atomically and durably write contents to targetPath.
std::string runnerStatusName(RunnerStatus status)
Convenience: human-readable status string ("active" / "archived" / "manual-only").
std::string runnerTypeName(RunnerType type)
Get human-readable name for runner type.
RunnerStatus runnerStatus(RunnerType type)
Get the upstream maintenance status for a runner type.
static bool endsWith(const std::string &str, const std::string &suffix)
RunnerType
Types of compatibility tools that can be downloaded.
@ UMU
Unified Proton Runner.
@ ProtonGE
GloriousEggroll Proton builds (active).
@ Luxtorpeda
Native game engine replacements.
@ ProtonTKG
TkGlitch custom Proton builds (no usable GitHub releases — AUR / PKGBUILD only).
@ WineGE
GloriousEggroll Wine builds for Lutris (archived 2025-07; final tag GE-Proton8-26).
@ DXVK
DirectX 9/10/11 to Vulkan.
@ VKD3DProton
DirectX 12 to Vulkan.
std::string runnerTypeName(RunnerType type)
Get human-readable name for runner type.
RunnerStatus runnerStatus(RunnerType type)
Get the upstream maintenance status for a runner type.
RunnerStatus
Upstream maintenance status of a runner type.
@ Active
Repo actively publishes releases on GitHub.
@ Archived
Repo is archived but the final release is still usable.
@ ManualOnly
No usable GitHub releases — install via distro packaging.
Progress information for downloads.
std::string getStateStr() const
std::string currentFile
Current file being processed.
std::string errorMessage
Error message if failed.
Information about an installed runner.
std::filesystem::path path
Installation path.
std::chrono::system_clock::time_point installDate
std::string version
Version string.
std::string name
Display name.
int64_t sizeBytes
Size on disk.
std::chrono::system_clock::time_point cacheTime
static constexpr int CACHE_VALIDITY_SEC
std::map< RunnerType, std::vector< RunnerRelease > > releaseCache
std::map< RunnerType, fs::path > customPaths
std::vector< InstalledRunner > installedCache
std::set< RunnerType > activeDownloads
std::map< RunnerType, std::atomic< bool > > cancelFlags
Information about an available runner release.
std::string releaseDate
Release date ISO string.
std::string checksum
SHA512 or SHA256 checksum if available.
bool isInstalled
Whether this version is currently installed.
int64_t size
Download size in bytes.
bool isArchived
True when sourced from an archived upstream repo (Wine-GE).
std::string releaseNotes
Release notes/changelog.
std::string checksumType
"sha512" or "sha256"
std::string tag
GitHub release tag.
std::string downloadUrl
Direct download URL.
bool isPrerelease
Whether this is a pre-release.
std::string getSizeStr() const
std::string version
Version string (e.g., "GE-Proton9-20").
std::filesystem::path installPath
Path if installed.
std::atomic< bool > * cancelled
RunnerDownloadService::ProgressCallback callback
std::string etag
Value of the response ETag header.
std::string body
Last successful response body (JSON array).
std::string lastModified
Value of the response Last-Modified header.
std::string fetchedAt
ISO-8601 UTC timestamp of last 200/304.