From 9a9dae3e7f8f044a351a69a502fb569699efb1d7 Mon Sep 17 00:00:00 2001 From: Sky Date: Sat, 6 Jan 2024 21:40:05 -0300 Subject: [PATCH 1/2] Set gamedir to $XDG_DATA_HOME and copy assets to it on creation --- Main/src/Application.cpp | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/Main/src/Application.cpp b/Main/src/Application.cpp index fad2794dc..d4da2657d 100644 --- a/Main/src/Application.cpp +++ b/Main/src/Application.cpp @@ -992,6 +992,45 @@ bool Application::m_Init() } } + if (Path::gameDir.empty()) { + char* xdgDataDir = std::getenv("XDG_DATA_HOME"); + + if (xdgDataDir) { + String gameDir = Utility::Sprintf("%s%c%s", xdgDataDir, Path::sep, "unnamed-sdvx-clone"); + auto executableDir = Path::RemoveLast(Path::GetExecutablePath()); + + Path::gameDir = gameDir; + + if (!Path::IsDirectory(gameDir)) { + Logf("%s does not yet exist. Creating...", Logger::Severity::Info, *gameDir); + + auto response = Path::CreateDir(gameDir); + if (response == 1) { + Logf("Created: %s", Logger::Severity::Info, *gameDir, response); + } else { + Logf("Failed creating directory %s. The game will probably crash soon.", Logger::Severity::Info, *gameDir, response); + } + + std::list requiredDirectories = { "skins", "fonts", "audio", "LightPlugins" }; + + for (String directory : requiredDirectories) { + auto sourceDir = Utility::Sprintf("%s%c%s", executableDir, Path::sep, directory); + auto destDir = Path::Absolute(directory); + + response = Path::CopyDir(sourceDir, destDir); + if (response == 1) { + Logf("Copied: %s to %s", Logger::Severity::Info, *sourceDir, *destDir, response); + } else { + Logf("Failed copying %s to %s. The game will probably crash soon.", Logger::Severity::Error, *sourceDir, *destDir, response); + } + } + + } else { + Logf("Setting gamedir to $XDG_DATA_HOME (%s). If data is missing, you can either copy the game data in %s to that directory, unset the $XDG_DATA_HOME variable or run the game with -gamedir=%s", Logger::Severity::Warning, *gameDir, *executableDir, *executableDir); + } + } + } + // Set the locale so that functions such as `fopen` use UTF-8. { String prevLocale = setlocale(LC_CTYPE, nullptr); From 861fc14ab013cd88326192d834c523f03d004b32 Mon Sep 17 00:00:00 2001 From: Sky Date: Sat, 6 Jan 2024 21:40:35 -0300 Subject: [PATCH 2/2] Document `-gamedir` flag and asset loading --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index 5ce312102..a681f46de 100644 --- a/README.md +++ b/README.md @@ -68,6 +68,7 @@ Just run 'usc-game' or 'usc-game_Debug' from within the 'bin' folder. - `-autoskip` - Skips beginning of song to the first chart note - `-debug` - Used to show relevant debug info in game such as hit timings, and scoring debug info - `-test` - Runs test scene, for development purposes only +- `-gamedir` - Sets the directory the game loads assets from. If unset, attempts reading from `$XDG_DATA_HOME/unnamed-sdvx-clone`. Finally, uses the executable directory if all else fails. ## How to build: