From 34ef2d51aa202b131c40c0fda9be834d88a21a4a Mon Sep 17 00:00:00 2001 From: TheBrokenRail Date: Thu, 22 Sep 2022 18:08:12 -0400 Subject: [PATCH] Small Fixes To The Launcher --- launcher/src/bootstrap.c | 2 +- launcher/src/bootstrap.h | 2 ++ launcher/src/client/cache.cpp | 10 +++++++--- launcher/src/client/launcher.cpp | 17 +++-------------- 4 files changed, 13 insertions(+), 18 deletions(-) diff --git a/launcher/src/bootstrap.c b/launcher/src/bootstrap.c index 319c9e84..3325a3c7 100644 --- a/launcher/src/bootstrap.c +++ b/launcher/src/bootstrap.c @@ -183,7 +183,7 @@ void pre_bootstrap(int argc, char *argv[]) { } // Copy SDK Into ~/.minecraft-pi -static void run_simple_command(const char *const command[], const char *error) { +void run_simple_command(const char *const command[], const char *error) { int status = 0; char *output = run_command(command, &status); if (output != NULL) { diff --git a/launcher/src/bootstrap.h b/launcher/src/bootstrap.h index 6afe6372..27a7950a 100644 --- a/launcher/src/bootstrap.h +++ b/launcher/src/bootstrap.h @@ -4,6 +4,8 @@ extern "C" { #endif +void run_simple_command(const char *const command[], const char *error); + void pre_bootstrap(int argc, char *argv[]); void bootstrap(int argc, char *argv[]); diff --git a/launcher/src/client/cache.cpp b/launcher/src/client/cache.cpp index ec257436..9af5764a 100644 --- a/launcher/src/client/cache.cpp +++ b/launcher/src/client/cache.cpp @@ -16,7 +16,7 @@ static std::string get_cache_path() { if (home == NULL) { IMPOSSIBLE(); } - return std::string(home) + "/.minecraft-pi/.launcher-cache"; + return std::string(home) + HOME_SUBDIRECTORY_FOR_GAME_DATA "/.launcher-cache"; } // Load @@ -44,7 +44,11 @@ launcher_cache load_cache() { unsigned char cache_version; stream.read((char *) &cache_version, 1); if (stream.eof() || cache_version != (unsigned char) CACHE_VERSION) { - WARN("Invalid Launcher Cache Version"); + if (!stream.eof()) { + WARN("Invalid Launcher Cache Version (Expected: %i, Actual: %i)", CACHE_VERSION, cache_version); + } else { + WARN("Unable To Read Launcher Cache Version"); + } stream.close(); return empty_cache; } @@ -68,7 +72,7 @@ launcher_cache load_cache() { // Finish stream.close(); if (!stream) { - WARN("Failure While Loading Launcher Cache: %s", strerror(errno)); + WARN("Failure While Loading Launcher Cache"); return empty_cache; } diff --git a/launcher/src/client/launcher.cpp b/launcher/src/client/launcher.cpp index c9458450..1807aec4 100644 --- a/launcher/src/client/launcher.cpp +++ b/launcher/src/client/launcher.cpp @@ -205,22 +205,11 @@ int main(int argc, char *argv[]) { } // Create ~/.minecraft-pi If Needed - // Minecraft Folder { char *minecraft_folder = NULL; - safe_asprintf(&minecraft_folder, "%s/.minecraft-pi", getenv("HOME")); - { - // Check Minecraft Folder - struct stat obj; - if (stat(minecraft_folder, &obj) != 0 || !S_ISDIR(obj.st_mode)) { - // Create Minecraft Folder - int ret = mkdir(minecraft_folder, S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH); - if (ret != 0) { - // Unable To Create Folder - ERR("Error Creating Directory: %s: %s", minecraft_folder, strerror(errno)); - } - } - } + safe_asprintf(&minecraft_folder, "%s" HOME_SUBDIRECTORY_FOR_GAME_DATA, getenv("HOME")); + const char *const command[] = {"mkdir", "-p", minecraft_folder, NULL}; + run_simple_command(command, "Unable To Create Data Directory"); free(minecraft_folder); }