diff --git a/launcher/src/bootstrap/assets.cpp b/launcher/src/bootstrap/assets.cpp index 8fdda31a0c..d288abaff4 100644 --- a/launcher/src/bootstrap/assets.cpp +++ b/launcher/src/bootstrap/assets.cpp @@ -1,4 +1,4 @@ -#include +#include #include "bootstrap.h" #include "../util/util.h" diff --git a/launcher/src/bootstrap/bootstrap.cpp b/launcher/src/bootstrap/bootstrap.cpp index 29c3c8a236..4e8a403480 100644 --- a/launcher/src/bootstrap/bootstrap.cpp +++ b/launcher/src/bootstrap/bootstrap.cpp @@ -1,7 +1,10 @@ #include #include -#include +#include +#include +#include +#include #include "../util/util.h" #include "bootstrap.h" diff --git a/launcher/src/bootstrap/debug.cpp b/launcher/src/bootstrap/debug.cpp index d87adafbd0..3e6845aed2 100644 --- a/launcher/src/bootstrap/debug.cpp +++ b/launcher/src/bootstrap/debug.cpp @@ -1,4 +1,6 @@ -#include +#include +#include +#include #include "bootstrap.h" diff --git a/launcher/src/bootstrap/mods.cpp b/launcher/src/bootstrap/mods.cpp index b30eb0cc58..3ab6075ecd 100644 --- a/launcher/src/bootstrap/mods.cpp +++ b/launcher/src/bootstrap/mods.cpp @@ -3,9 +3,11 @@ #include #include -#include +#include +#include #include "bootstrap.h" +#include "../util/util.h" // Get All Mods In Folder static void load(std::vector &ld_preload, const std::string &folder, int recursion_limit = 128); @@ -18,10 +20,8 @@ static void handle_file(std::vector &ld_preload, const std::string load(ld_preload, std::string(file) + '/', recursion_limit - 1); } else if (S_ISLNK(file_stat.st_mode)) { // Resolve Symlink - char *resolved_file = realpath(file.c_str(), nullptr); - ALLOC_CHECK(resolved_file); + const std::string resolved_file = safe_realpath(file); handle_file(ld_preload, resolved_file, recursion_limit); - free(resolved_file); } else if (S_ISREG(file_stat.st_mode)) { // Check If File Is Accessible const int result = access(file.c_str(), R_OK); @@ -79,19 +79,13 @@ std::vector bootstrap_mods(const std::string &binary_directory) { // Prepare std::vector preload; - // ~/.minecraft-pi/mods - { - // Get Mods Folder - const std::string mods_folder = std::string(getenv(_MCPI_HOME_ENV)) + get_home_subdirectory_for_game_data() + SUBDIRECTORY_FOR_MODS; - // Load Mods From ./mods - load(preload, mods_folder); - } - - // Built-In Mods - { - // Get Mods Folder - const std::string mods_folder = binary_directory + SUBDIRECTORY_FOR_MODS; - // Load Mods From ./mods + // Load + const std::vector folders = { + home_get(), + binary_directory + }; + for (std::string mods_folder : folders) { + mods_folder += SUBDIRECTORY_FOR_MODS; load(preload, mods_folder); } diff --git a/launcher/src/bootstrap/patchelf.cpp b/launcher/src/bootstrap/patchelf.cpp index b4d3a83820..3f2489da7c 100644 --- a/launcher/src/bootstrap/patchelf.cpp +++ b/launcher/src/bootstrap/patchelf.cpp @@ -4,10 +4,8 @@ #include -#include -#include - -#include +#include +#include #include "bootstrap.h" diff --git a/launcher/src/client/cache.cpp b/launcher/src/client/cache.cpp index 579cf92710..2fb298ad2c 100644 --- a/launcher/src/client/cache.cpp +++ b/launcher/src/client/cache.cpp @@ -6,18 +6,15 @@ #include #include -#include +#include +#include #include "cache.h" #include "configuration.h" // Get Cache Path static std::string get_cache_path() { - const char *home = getenv(_MCPI_HOME_ENV); - if (home == nullptr) { - IMPOSSIBLE(); - } - return std::string(home) + get_home_subdirectory_for_game_data() + "/.launcher-cache"; + return home_get() + "/.launcher-cache"; } // Load diff --git a/launcher/src/client/configuration.cpp b/launcher/src/client/configuration.cpp index 1cb254fa1d..adfe354da3 100644 --- a/launcher/src/client/configuration.cpp +++ b/launcher/src/client/configuration.cpp @@ -3,7 +3,7 @@ #include #include -#include +#include #include "../util/util.h" #include "configuration.h" diff --git a/launcher/src/logger/crash-report.cpp b/launcher/src/logger/crash-report.cpp index 58ee4fc07d..7894c5c87b 100644 --- a/launcher/src/logger/crash-report.cpp +++ b/launcher/src/logger/crash-report.cpp @@ -1,6 +1,8 @@ #include -#include +#include +#include +#include #include "logger.h" #include "../ui/frame.h" diff --git a/launcher/src/logger/logger.cpp b/launcher/src/logger/logger.cpp index a7e2ed2e37..be1ab4a4b9 100644 --- a/launcher/src/logger/logger.cpp +++ b/launcher/src/logger/logger.cpp @@ -4,14 +4,15 @@ #include #include #include -#include #include #include #include #include #include -#include +#include +#include +#include #include "logger.h" @@ -26,7 +27,7 @@ static void exit_handler(__attribute__((unused)) int signal) { static std::string log_filename; static int log_fd; std::string get_logs_folder() { - const std::string home = std::string(getenv(_MCPI_HOME_ENV)) + get_home_subdirectory_for_game_data(); + const std::string home = home_get(); ensure_directory(home.c_str()); const std::string logs = home + "/logs"; ensure_directory(logs.c_str()); @@ -34,8 +35,6 @@ std::string get_logs_folder() { } static void setup_log_file() { // Get Log Directory - const std::string home = std::string(getenv(_MCPI_HOME_ENV)) + get_home_subdirectory_for_game_data(); - ensure_directory(home.c_str()); const std::string logs = get_logs_folder(); // Get Timestamp diff --git a/launcher/src/main.cpp b/launcher/src/main.cpp index fdd60cf978..28037821d8 100644 --- a/launcher/src/main.cpp +++ b/launcher/src/main.cpp @@ -1,5 +1,7 @@ #include -#include + +#include +#include #include "bootstrap/bootstrap.h" #include "options/parser.h" diff --git a/launcher/src/options/parser.cpp b/launcher/src/options/parser.cpp index a98c400e3a..a0315ba872 100644 --- a/launcher/src/options/parser.cpp +++ b/launcher/src/options/parser.cpp @@ -1,5 +1,7 @@ #include +#include +#include #include #include "parser.h" diff --git a/launcher/src/options/parser.h b/launcher/src/options/parser.h index b897c71333..745ace42b2 100644 --- a/launcher/src/options/parser.h +++ b/launcher/src/options/parser.h @@ -1,7 +1,5 @@ #pragma once -#include - #define OPTION(name, ...) bool name; struct options_t { #include "option-list.h" diff --git a/launcher/src/ui/frame.cpp b/launcher/src/ui/frame.cpp index 5fb4bc34f0..60f48e7930 100644 --- a/launcher/src/ui/frame.cpp +++ b/launcher/src/ui/frame.cpp @@ -5,7 +5,9 @@ #include #include -#include +#include +#include +#include // Init/Cleanup Frame::Frame(const char *title, const int width, const int height) { diff --git a/launcher/src/util/env.cpp b/launcher/src/util/env.cpp index e2f2eb3797..fa6a564742 100644 --- a/launcher/src/util/env.cpp +++ b/launcher/src/util/env.cpp @@ -1,6 +1,10 @@ +#include + #include "util.h" -#include +#include +#include +#include // $PATH void setup_path() { diff --git a/launcher/src/util/sdk.cpp b/launcher/src/util/sdk.cpp index e801f310e6..7a89f1393c 100644 --- a/launcher/src/util/sdk.cpp +++ b/launcher/src/util/sdk.cpp @@ -1,4 +1,6 @@ -#include +#include +#include +#include #include "../bootstrap/bootstrap.h" #include "util.h" @@ -14,12 +16,12 @@ } // Copy SDK Into ~/.minecraft-pi -#define HOME_SUBDIRECTORY_FOR_SDK (std::string(get_home_subdirectory_for_game_data()) + "/sdk") +#define HOME_SUBDIRECTORY_FOR_SDK "/sdk" void copy_sdk(const std::string &binary_directory, const bool log_with_debug) { // Ensure SDK Directory std::string sdk_path; { - sdk_path = std::string(getenv(_MCPI_HOME_ENV)) + HOME_SUBDIRECTORY_FOR_SDK; + sdk_path = home_get() + HOME_SUBDIRECTORY_FOR_SDK; const char *const command[] = {"mkdir", "-p", sdk_path.c_str(), nullptr}; run_simple_command(command, "Unable To Create SDK Directory"); } diff --git a/launcher/src/util/util.cpp b/launcher/src/util/util.cpp index cbea1560c0..c4a0b06669 100644 --- a/launcher/src/util/util.cpp +++ b/launcher/src/util/util.cpp @@ -1,4 +1,5 @@ -#include +#include +#include #include "util.h" diff --git a/libreborn/include/libreborn/config.h.in b/libreborn/include/libreborn/config.h.in index 52fc979800..3382cc042d 100644 --- a/libreborn/include/libreborn/config.h.in +++ b/libreborn/include/libreborn/config.h.in @@ -3,7 +3,6 @@ #cmakedefine MCPI_IS_APPIMAGE_BUILD #cmakedefine MCPI_IS_FLATPAK_BUILD #cmakedefine MCPI_USE_PREBUILT_ARMHF_TOOLCHAIN -#cmakedefine MCPI_APP_BASE_TITLE "@MCPI_APP_BASE_TITLE@" #cmakedefine MCPI_APP_TITLE "@MCPI_APP_TITLE@" #cmakedefine MCPI_APP_ID "@MCPI_APP_ID@" #cmakedefine MCPI_VERSION "@MCPI_VERSION@" diff --git a/libreborn/include/libreborn/patch.h b/libreborn/include/libreborn/patch.h index 95606a3734..18b02477f6 100644 --- a/libreborn/include/libreborn/patch.h +++ b/libreborn/include/libreborn/patch.h @@ -1,6 +1,6 @@ #pragma once -#include +#include "log.h" // Patching Functions #ifdef REBORN_HAS_PATCH_CODE diff --git a/libreborn/include/libreborn/util.h b/libreborn/include/libreborn/util.h index 838c0657e6..958cfa5d31 100644 --- a/libreborn/include/libreborn/util.h +++ b/libreborn/include/libreborn/util.h @@ -1,10 +1,8 @@ #pragma once -#include #include -#include #include -#include +#include #include "log.h" @@ -80,3 +78,6 @@ void safe_write(int fd, const void *buf, size_t size); #define EMBEDDED_RESOURCE(name) \ extern unsigned char name[]; \ extern size_t name##_len + +// Profile Directory +std::string home_get(); \ No newline at end of file diff --git a/libreborn/src/util/util.cpp b/libreborn/src/util/util.cpp index 583acdc768..edacace142 100644 --- a/libreborn/src/util/util.cpp +++ b/libreborn/src/util/util.cpp @@ -122,4 +122,13 @@ void safe_write(const int fd, const void *buf, const size_t size) { if (bytes_written < 0) { ERR("Unable To Write Data: %s", strerror(errno)); } +} + +// Get MCPI Home Directory +std::string home_get() { + const char *home = getenv(_MCPI_HOME_ENV); + if (home == nullptr) { + IMPOSSIBLE(); + } + return std::string(home) + std::string(get_home_subdirectory_for_game_data()); } \ No newline at end of file diff --git a/mods/CMakeLists.txt b/mods/CMakeLists.txt index ffd99c00e1..f1e4e95302 100644 --- a/mods/CMakeLists.txt +++ b/mods/CMakeLists.txt @@ -33,6 +33,7 @@ add_library(mods SHARED src/misc/graphics.cpp src/misc/ui.cpp src/misc/tinting.cpp + src/misc/home.cpp # extend src/extend/Screen.cpp src/extend/DynamicTexture.cpp @@ -44,15 +45,11 @@ add_library(mods SHARED src/bucket/bucket.cpp # cake src/cake/cake.cpp - # home - src/home/home.cpp # touch src/touch/touch.cpp # text-input-box src/text-input-box/TextInputBox.cpp src/text-input-box/TextInputScreen.cpp - # test - src/test/test.cpp # sound src/sound/sound.cpp src/sound/repository.cpp diff --git a/mods/include/mods/home/home.h b/mods/include/mods/home/home.h deleted file mode 100644 index 87dfa54605..0000000000 --- a/mods/include/mods/home/home.h +++ /dev/null @@ -1,5 +0,0 @@ -#pragma once - -extern "C" { -const char *home_get(); -} diff --git a/mods/include/mods/init/init.h b/mods/include/mods/init/init.h index 66eff5e353..4e8dad6127 100644 --- a/mods/include/mods/init/init.h +++ b/mods/include/mods/init/init.h @@ -1,7 +1,6 @@ #pragma once extern "C" { -void run_tests(); void init_version(); void init_compat(); void init_server(); @@ -25,7 +24,6 @@ void init_options(); void init_chat(); void init_bucket(); void init_cake(); -void init_home(); void init_override(); void init_screenshot(); void init_f3(); diff --git a/mods/src/home/README.md b/mods/src/home/README.md deleted file mode 100644 index 54102ed40c..0000000000 --- a/mods/src/home/README.md +++ /dev/null @@ -1,4 +0,0 @@ -# `home` Mod -This utility mod handles changing the location where world data is stored. This is so it doesn't conflict with Minecraft: Java Edition. - -Normally, it changes it to `~/.minecraft-pi`, but in server mode it changes it to the launch directory. diff --git a/mods/src/init/init.cpp b/mods/src/init/init.cpp index 8165cca3a5..a819fa200e 100644 --- a/mods/src/init/init.cpp +++ b/mods/src/init/init.cpp @@ -6,7 +6,6 @@ __attribute__((constructor)) static void init() { reborn_init_patch(); thunk_enabler = reborn_thunk_enabler; - run_tests(); init_version(); init_compat(); if (reborn_is_server()) { @@ -38,7 +37,6 @@ __attribute__((constructor)) static void init() { init_chat(); init_bucket(); init_cake(); - init_home(); init_override(); if (!reborn_is_server()) { init_benchmark(); diff --git a/mods/src/misc/README.md b/mods/src/misc/README.md index 9404b5e84f..b8e570947f 100644 --- a/mods/src/misc/README.md +++ b/mods/src/misc/README.md @@ -6,3 +6,4 @@ This mod has several miscellaneous mods that are too small to be their own mod, * Loading the bundled language file. * Printing chat messages to the log. * Implementing crafting remainders. +* Correct the profile directory. \ No newline at end of file diff --git a/mods/src/home/home.cpp b/mods/src/misc/home.cpp similarity index 62% rename from mods/src/home/home.cpp rename to mods/src/misc/home.cpp index d231bb3cf4..72e73c4053 100644 --- a/mods/src/home/home.cpp +++ b/mods/src/misc/home.cpp @@ -1,19 +1,9 @@ -#include +#include +#include +#include #include -#include -#include - -// Get MCPI Home Directory -const char *home_get() { - static std::string dir = ""; - // Load - if (dir.empty()) { - dir = std::string(getenv(_MCPI_HOME_ENV)) + std::string(get_home_subdirectory_for_game_data()); - } - // Return - return dir.c_str(); -} +#include "misc-internal.h" // Use MCPI_HOME static const char *getenv_HOME(__attribute__((unused)) const char *env) { @@ -21,7 +11,7 @@ static const char *getenv_HOME(__attribute__((unused)) const char *env) { } // Init -void init_home() { +void _init_misc_home() { // Store Data In ~/.minecraft-pi Instead Of ~/.minecraft patch_address(&Strings::default_path, (void *) get_home_subdirectory_for_game_data()); // Use MCPI_HOME Instead Of $HOME diff --git a/mods/src/misc/misc-internal.h b/mods/src/misc/misc-internal.h index 25926d3912..750c38f275 100644 --- a/mods/src/misc/misc-internal.h +++ b/mods/src/misc/misc-internal.h @@ -5,6 +5,7 @@ __attribute__((visibility("internal"))) void _init_misc_api(); __attribute__((visibility("internal"))) void _init_misc_graphics(); __attribute__((visibility("internal"))) void _init_misc_ui(); __attribute__((visibility("internal"))) void _init_misc_tinting(); +__attribute__((visibility("internal"))) void _init_misc_home(); template static void nop(__attribute__((unused)) Args... args) { diff --git a/mods/src/misc/misc.cpp b/mods/src/misc/misc.cpp index ec5badcfbc..e7c3d00c94 100644 --- a/mods/src/misc/misc.cpp +++ b/mods/src/misc/misc.cpp @@ -611,4 +611,5 @@ void init_misc() { _init_misc_logging(); _init_misc_api(); _init_misc_graphics(); + _init_misc_home(); } diff --git a/mods/src/multiplayer/multiplayer.cpp b/mods/src/multiplayer/multiplayer.cpp index 9116d5d35c..5c555c5468 100644 --- a/mods/src/multiplayer/multiplayer.cpp +++ b/mods/src/multiplayer/multiplayer.cpp @@ -6,7 +6,6 @@ #include #include -#include #include #include diff --git a/mods/src/options/info.cpp b/mods/src/options/info.cpp index da82b8e4de..922b53f3e2 100644 --- a/mods/src/options/info.cpp +++ b/mods/src/options/info.cpp @@ -2,7 +2,6 @@ #include #include -#include #include #include #include diff --git a/mods/src/options/options.cpp b/mods/src/options/options.cpp index 7117412531..e43054022e 100644 --- a/mods/src/options/options.cpp +++ b/mods/src/options/options.cpp @@ -8,7 +8,6 @@ #include #include -#include #include "options-internal.h" diff --git a/mods/src/override/override.cpp b/mods/src/override/override.cpp index 90bc03346d..5d1c9061cc 100644 --- a/mods/src/override/override.cpp +++ b/mods/src/override/override.cpp @@ -7,7 +7,6 @@ #include #include -#include #include // Hook Functions diff --git a/mods/src/screenshot/screenshot.cpp b/mods/src/screenshot/screenshot.cpp index e2b9764e2d..4671849016 100644 --- a/mods/src/screenshot/screenshot.cpp +++ b/mods/src/screenshot/screenshot.cpp @@ -14,7 +14,6 @@ #include #include -#include #include #include #include diff --git a/mods/src/server/server.cpp b/mods/src/server/server.cpp index 553f169799..4cf75f63b4 100644 --- a/mods/src/server/server.cpp +++ b/mods/src/server/server.cpp @@ -16,7 +16,6 @@ #include #include -#include #include #include #include diff --git a/mods/src/test/README.md b/mods/src/test/README.md deleted file mode 100644 index ad4b1dcdc1..0000000000 --- a/mods/src/test/README.md +++ /dev/null @@ -1,2 +0,0 @@ -# `test` Mod -This utility mod tests that the system is configured correctly before starting. diff --git a/mods/src/test/test.cpp b/mods/src/test/test.cpp deleted file mode 100644 index 7381ac63f3..0000000000 --- a/mods/src/test/test.cpp +++ /dev/null @@ -1,21 +0,0 @@ -#include -#include -#include - -#include - -#include -#include - -void run_tests() { - // Test ~/.minecraft-pi Permissions - { - const char *path = home_get(); - int exists = access(path, F_OK) == 0; - int can_write = exists ? access(path, R_OK | W_OK) == 0 : 1; - if (!can_write) { - // Failure - ERR("Invalid Data Directory Permissions"); - } - } -} diff --git a/mods/src/title-screen/welcome.cpp b/mods/src/title-screen/welcome.cpp index 27e88ceba1..b76a59bdc2 100644 --- a/mods/src/title-screen/welcome.cpp +++ b/mods/src/title-screen/welcome.cpp @@ -3,7 +3,6 @@ #include #include -#include #include #include #include