Add XDG Games desktop shortcut, hicolor icons, and installable asset lookup

This commit is contained in:
Luxferre committed 2026-12-01 09:51:29 +02:00
1 parent 554958db9a
commit d001f214aa
12 files changed
+445 -35

No files matched your search

+65
View File
@@ -10,9 +10,12 @@
#include "core/config.hpp"
#include "core/vfs.hpp"
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <filesystem>
#include <iostream>
#include <optional>
using namespace top_octane;
using namespace top_octane::assets;
@@ -236,5 +239,67 @@ int main() {
CHECK(sf_bank.find_preset(0, 0) != nullptr);
std::cout << "[PASS] MUSIC.DAT (20 XMI tracks), SAMPLE.OPL (162 timbres), BULLFROG.SBK (17 presets) validated\n";
// 8. VFS relocatable prefix & XDG Base Directory search path order
{
auto find_idx = [](const std::vector<std::filesystem::path>& list, const std::filesystem::path& target) -> ptrdiff_t {
auto it = std::find(list.begin(), list.end(), target);
return (it == list.end()) ? -1 : std::distance(list.begin(), it);
};
#ifndef _WIN32
struct ScopedEnv {
const char* key;
std::optional<std::string> prev;
ScopedEnv(const char* k, const char* val) : key(k) {
if (const char* old = std::getenv(k)) prev = std::string(old);
if (val) setenv(k, val, 1);
else unsetenv(k);
}
~ScopedEnv() {
if (prev.has_value()) setenv(key, prev->c_str(), 1);
else unsetenv(key);
}
};
ScopedEnv env_ho("HIOCTANE_DATA", nullptr);
ScopedEnv env_xdh("XDG_DATA_HOME", "/tmp/top-octane-xdg-home/");
ScopedEnv env_xdd("XDG_DATA_DIRS", "/tmp/top-octane-xdg1:/tmp/top-octane-xdg2/");
#endif
auto paths = Vfs::build_search_paths(
"/explicit/data",
std::filesystem::path("/work/dir/"),
std::filesystem::path("/opt/test-prefix/bin/"),
std::filesystem::path("/tmp/pref/"));
CHECK(!paths.empty());
CHECK(paths.front() == std::filesystem::path("/explicit/data"));
const ptrdiff_t prefix_idx = find_idx(paths, std::filesystem::path("/opt/test-prefix/share/top-octane/data"));
const ptrdiff_t pref_idx = find_idx(paths, std::filesystem::path("/tmp/pref/data"));
CHECK(prefix_idx >= 0);
CHECK(pref_idx > prefix_idx);
#ifndef _WIN32
const ptrdiff_t xdh_idx = find_idx(paths, std::filesystem::path("/tmp/top-octane-xdg-home/top-octane/data"));
const ptrdiff_t xdd1_idx = find_idx(paths, std::filesystem::path("/tmp/top-octane-xdg1/top-octane/data"));
const ptrdiff_t xdd2_idx = find_idx(paths, std::filesystem::path("/tmp/top-octane-xdg2/top-octane/data"));
CHECK(xdh_idx > prefix_idx);
CHECK(xdd1_idx > xdh_idx);
CHECK(xdd2_idx > xdd1_idx);
CHECK(pref_idx > xdd2_idx);
ScopedEnv env_ho_set("HIOCTANE_DATA", "/env/hioctane");
auto prio_paths = Vfs::build_search_paths(
"/cli/data",
std::filesystem::path("/work/dir"),
std::filesystem::path("/opt/test-prefix/bin/"),
std::filesystem::path());
CHECK(prio_paths.size() >= 2);
CHECK(prio_paths[0] == std::filesystem::path("/cli/data"));
CHECK(prio_paths[1] == std::filesystem::path("/env/hioctane"));
#endif
std::cout << "[PASS] Vfs relocatable & XDG data directory lookup validated\n";
}
return 0;
}