From f2a6891a08413d4fbb46342d2d646e05017a60ff Mon Sep 17 00:00:00 2001 From: Agent X <44549182+AgentXLP@users.noreply.github.com> Date: Thu, 16 May 2024 17:15:25 -0400 Subject: [PATCH] Rework new user folder system, make it just read sm64ex-coop if sm64coopdx isn't present, no more copying --- data/dynos.h | 2 +- data/dynos_gfx_init.cpp | 2 +- lang/Czech.ini | 1 - lang/Dutch.ini | 1 - lang/English.ini | 2 +- lang/French.ini | 1 - lang/German.ini | 1 - lang/Italian.ini | 1 - lang/Polish.ini | 1 - lang/Portuguese.ini | 1 - lang/Russian.ini | 1 - lang/Spanish.ini | 1 - src/pc/djui/djui.c | 5 --- src/pc/djui/djui_panel_misc.c | 6 +-- src/pc/fs/fs.c | 31 +++++++++++-- src/pc/fs/fs.h | 8 ++-- src/pc/gfx/gfx_sdl2.c | 2 +- src/pc/loading.c | 2 +- src/pc/mods/mod_storage.cpp | 4 +- src/pc/pc_main.c | 37 ++++++++-------- src/pc/platform.c | 58 ++++++++++++------------- src/pc/platform.h | 1 - src/pc/rom_assets.c | 2 +- src/pc/{startup.cpp => rom_checker.cpp} | 30 +++++-------- src/pc/{startup.h => rom_checker.h} | 1 - 25 files changed, 97 insertions(+), 105 deletions(-) rename src/pc/{startup.cpp => rom_checker.cpp} (73%) rename src/pc/{startup.h => rom_checker.h} (85%) diff --git a/data/dynos.h b/data/dynos.h index ec051d5c..d3976732 100644 --- a/data/dynos.h +++ b/data/dynos.h @@ -30,7 +30,7 @@ extern "C" { #define DYNOS_VERSION "1.0" #define DYNOS_EXE_FOLDER sys_exe_path() -#define DYNOS_USER_FOLDER sys_user_path() +#define DYNOS_USER_FOLDER fs_get_write_path("") #define DYNOS_RES_FOLDER "dynos" #define DYNOS_PACKS_FOLDER DYNOS_RES_FOLDER "/packs" #define DYNOS_CONFIG_FILENAME "DynOS." DYNOS_VERSION ".config.txt" diff --git a/data/dynos_gfx_init.cpp b/data/dynos_gfx_init.cpp index a28f8fab..eca9c796 100644 --- a/data/dynos_gfx_init.cpp +++ b/data/dynos_gfx_init.cpp @@ -75,6 +75,6 @@ void DynOS_Gfx_Init() { ScanPacksFolder(_DynosPacksFolder); // Scan the user path folder - SysPath _DynosPacksUserFolder = fstring("%s/%s", DYNOS_USER_FOLDER, DYNOS_PACKS_FOLDER); + SysPath _DynosPacksUserFolder = fstring("%s%s", DYNOS_USER_FOLDER, DYNOS_PACKS_FOLDER); ScanPacksFolder(_DynosPacksUserFolder); } diff --git a/lang/Czech.ini b/lang/Czech.ini index 040c4763..2326f03b 100644 --- a/lang/Czech.ini +++ b/lang/Czech.ini @@ -31,7 +31,6 @@ LOBBY_HOST = "host lobby" UPDATE_AVAILABLE = "Nová aktualizace!" LATEST_VERSION = "Nejnovější verze" YOUR_VERSION = "Vaše verze" -USER_FOLDER_COPIED = "\\#a0ffa0\\Úspěch!\n\\#dcdcdc\\Složka uživatele sm64ex-coop byla zkopírována do nové složky sm64coopdx." [CHAT] KICKING = "Vyhazování '@'!" diff --git a/lang/Dutch.ini b/lang/Dutch.ini index c01cf62d..f054d838 100644 --- a/lang/Dutch.ini +++ b/lang/Dutch.ini @@ -31,7 +31,6 @@ LOBBY_HOST = "De Lobby's organisator." UPDATE_AVAILABLE = "Nieuwe update!" LATEST_VERSION = "Laatste versie" YOUR_VERSION = "Uw versie" -USER_FOLDER_COPIED = "\\#a0ffa0\\Succes!\n\\#dcdcdc\\De gebruikersmap van sm64ex-coop is gekopieerd naar de nieuwe sm64coopdx." [CHAT] KICKING = "'@' eruit schoppen!" diff --git a/lang/English.ini b/lang/English.ini index df818422..e1939b97 100644 --- a/lang/English.ini +++ b/lang/English.ini @@ -31,7 +31,7 @@ LOBBY_HOST = "the lobby's host" UPDATE_AVAILABLE = "A new update is available!" LATEST_VERSION = "Latest version" YOUR_VERSION = "Your version" -USER_FOLDER_COPIED = "\\#a0ffa0\\Success!\n\\#dcdcdc\\The sm64ex-coop user folder has been copied over to the new sm64coopdx one." +USER_FOLDER_RENAMED = "\\#a0ffa0\\Success!\n\\#dcdcdc\\The sm64ex-coop user folder has renamed to sm64coopdx." [CHAT] KICKING = "Kicking '@'!" diff --git a/lang/French.ini b/lang/French.ini index 5e404bb4..f8a1e965 100644 --- a/lang/French.ini +++ b/lang/French.ini @@ -31,7 +31,6 @@ LOBBY_HOST = "l'hôte de la partie" UPDATE_AVAILABLE = "Nouvelle mise à jour !" LATEST_VERSION = "Dernière version" YOUR_VERSION = "Votre version" -USER_FOLDER_COPIED = "\\#a0ffa0\\Succès !\n\\#dcdcdc\\Le dossier utilisateur sm64ex-coop a été copié dans le nouveau sm64coopdx." [CHAT] KICKING = "Vous avez expulsé '@' !" diff --git a/lang/German.ini b/lang/German.ini index 5d503657..52ddc6dc 100644 --- a/lang/German.ini +++ b/lang/German.ini @@ -31,7 +31,6 @@ LOBBY_HOST = "Lobby-Hoster" UPDATE_AVAILABLE = "Neues Update!" LATEST_VERSION = "Aktuellste Version" YOUR_VERSION = "Ihre Version" -USER_FOLDER_COPIED = "\\#a0ffa0\\Erfolg!\n\\#dcdcdc\\Der Benutzerordner sm64ex-coop wurde in den neuen sm64coopdx kopiert." [CHAT] KICKING = "'@' wird hinausgeworfen!" diff --git a/lang/Italian.ini b/lang/Italian.ini index 16f9ed3c..a10478ca 100644 --- a/lang/Italian.ini +++ b/lang/Italian.ini @@ -31,7 +31,6 @@ LOBBY_HOST = "the lobby's host" UPDATE_AVAILABLE = "Nuovo aggiornamento!" LATEST_VERSION = "Ultima versione" YOUR_VERSION = "La tua versione" -USER_FOLDER_COPIED = "\\#a0ffa0\\Successo!\n\\#dcdcdc\\La cartella utente sm64ex-coop è stata copiata nella nuova sm64coopdx." [CHAT] KICKING = "Espulso '@'!" diff --git a/lang/Polish.ini b/lang/Polish.ini index 1e778a3a..e2826f5e 100644 --- a/lang/Polish.ini +++ b/lang/Polish.ini @@ -31,7 +31,6 @@ LOBBY_HOST = "Host lobby" UPDATE_AVAILABLE = "Nowa aktualizacja!" LATEST_VERSION = "Najnowsza wersja" YOUR_VERSION = "Twoja wersja" -USER_FOLDER_COPIED = "\\#a0ffa0\\Sukces!\n\\#dcdcdc\\Folder użytkownika sm64ex-coop został skopiowany do nowego sm64coopdx." [CHAT] KICKING = "Wyrzucanie gracza '@'!" diff --git a/lang/Portuguese.ini b/lang/Portuguese.ini index b3205f5b..d8da48e4 100644 --- a/lang/Portuguese.ini +++ b/lang/Portuguese.ini @@ -31,7 +31,6 @@ LOBBY_HOST = "o criador da partida" UPDATE_AVAILABLE = "Nova atualização!" LATEST_VERSION = "Versão mais recente" YOUR_VERSION = "Sua versão" -USER_FOLDER_COPIED = "\\#a0ffa0\\Sucesso!\n\\#dcdcdc\\A pasta de usuário sm64ex-coop foi copiada para a nova sm64coopdx." [CHAT] KICKING = "'@' foi expulso!" diff --git a/lang/Russian.ini b/lang/Russian.ini index 4d06da0b..25d495d7 100644 --- a/lang/Russian.ini +++ b/lang/Russian.ini @@ -31,7 +31,6 @@ LOBBY_HOST = "Создать группу" UPDATE_AVAILABLE = "Новое обновление!" LATEST_VERSION = "Последняя версия" YOUR_VERSION = "Ваша версия" -USER_FOLDER_COPIED = "\\#a0ffa0\\Успех!\n\\#dcdcdc\\Папка пользователя sm64ex-coop была скопирована в новую sm64coopdx." [CHAT] KICKING = "'@' выгнан!" diff --git a/lang/Spanish.ini b/lang/Spanish.ini index 43243076..42e377b6 100644 --- a/lang/Spanish.ini +++ b/lang/Spanish.ini @@ -31,7 +31,6 @@ LOBBY_HOST = "la partida del anfitrión" UPDATE_AVAILABLE = "¡Nueva actualización!" LATEST_VERSION = "Última versión" YOUR_VERSION = "Su versión" -USER_FOLDER_COPIED = "\\#a0ffa0\\¡Éxito!\n\\#dcdcdc\\La carpeta de usuario sm64ex-coop ha sido copiada a la nueva sm64coopdx." [CHAT] KICKING = "¡'@' ha sido expulsado!" diff --git a/src/pc/djui/djui.c b/src/pc/djui/djui.c index 8fedb3f2..a8febe8d 100644 --- a/src/pc/djui/djui.c +++ b/src/pc/djui/djui.c @@ -15,7 +15,6 @@ #include "djui_hud_utils.h" #include "engine/math_util.h" #include "pc/utils/misc.h" -#include "pc/startup.h" static Gfx* sSavedDisplayListHead = NULL; @@ -110,10 +109,6 @@ void djui_init_late(void) { // djui_panel_debug_create(); djui_cursor_create(); - - if (gUserFolderCopied) { - djui_popup_create(DLANG(NOTIF, USER_FOLDER_COPIED), 4); - } } void djui_connect_menu_open(void) { diff --git a/src/pc/djui/djui_panel_misc.c b/src/pc/djui/djui_panel_misc.c index 3d084e14..8d4d5f1f 100644 --- a/src/pc/djui/djui_panel_misc.c +++ b/src/pc/djui/djui_panel_misc.c @@ -44,16 +44,16 @@ void djui_panel_options_debug_create(struct DjuiBase* caller) { static void djui_panel_options_open_user_folder(UNUSED struct DjuiBase* caller) { #if defined(_WIN32) || defined(_WIN64) // Windows - ShellExecuteA(NULL, "open", sys_user_path(), NULL, NULL, SW_SHOWNORMAL); + ShellExecuteA(NULL, "open", fs_get_write_path(""), NULL, NULL, SW_SHOWNORMAL); #elif __linux__ // Linux char command[512]; - snprintf(command, sizeof(command), "xdg-open %s", sys_user_path()); + snprintf(command, sizeof(command), "xdg-open \"%s\"", fs_get_write_path("")); system(command); #elif __APPLE__ // macOS char command[512]; - snprintf(command, sizeof(command), "open %s", sys_user_path()); + snprintf(command, sizeof(command), "open \"%s\"", fs_get_write_path("")); system(command); #endif } diff --git a/src/pc/fs/fs.c b/src/pc/fs/fs.c index 6aeace2e..04325586 100644 --- a/src/pc/fs/fs.c +++ b/src/pc/fs/fs.c @@ -48,7 +48,7 @@ bool fs_init(const char *writepath) { strncpy(fs_writepath, fs_convert_path(buf, sizeof(buf), writepath), sizeof(fs_writepath)); fs_writepath[sizeof(fs_writepath)-1] = 0; #ifdef DEVELOPMENT - printf("fs: writepath set to `%s`\n", fs_writepath); + printf("FS: writepath set to `%s`\n", fs_writepath); #endif fs_mount(fs_writepath); @@ -77,7 +77,7 @@ bool fs_mount(const char *realpath) { if (!pack || !packer) { if (tried) - fprintf(stderr, "fs: could not mount '%s'\n", realpath); + fprintf(stderr, "FS: could not mount '%s'\n", realpath); return false; } @@ -97,7 +97,7 @@ bool fs_mount(const char *realpath) { fs_searchpaths = dir; #ifdef DEVELOPMENT - printf("fs: mounting '%s'\n", realpath); + printf("FS: mounting '%s'\n", realpath); #endif return true; @@ -274,6 +274,31 @@ bool fs_sys_dir_exists(const char *name) { return (stat(name, &st) == 0 && S_ISDIR(st.st_mode)); } +bool fs_sys_dir_is_empty(const char *name) { + DIR *dir; + struct dirent *ent; + + if (!(dir = opendir(name))) { + fprintf(stderr, "fs_sys_dir_is_empty(): could not open `%s`\n", name); + return true; + } + + bool ret = true; + while ((ent = readdir(dir)) != NULL) { + // skip "." and ".." + if (ent->d_name[0] == '.' && (ent->d_name[1] == '\0' || + (ent->d_name[1] == '.' && ent->d_name[2] == '\0'))) { + continue; + } + + ret = false; + break; + } + + closedir(dir); + return ret; +} + bool fs_sys_walk(const char *base, walk_fn_t walk, void *user, const bool recur) { #ifdef DOCKERBUILD return false; diff --git a/src/pc/fs/fs.h b/src/pc/fs/fs.h index 6a50c1be..fc299f1f 100644 --- a/src/pc/fs/fs.h +++ b/src/pc/fs/fs.h @@ -65,11 +65,8 @@ typedef struct { void (*close)(void *pack, fs_file_t *file); // closes a virtual file previously opened with ->open() } fs_packtype_t; -// takes the supplied NULL-terminated list of read-only directories and mounts all the packs in them, -// then mounts the directories themselves, then mounts all the packs in `gamedir`, then mounts `gamedir` itself, -// then does the same with `userdir` -// initializes the `fs_userdir` variable -bool fs_init(const char *userdir); +// mounts `writepath` +bool fs_init(const char *writepath); // mounts the pack at physical path `realpath` to the root of the filesystem // packs mounted later take priority over packs mounted earlier bool fs_mount(const char *realpath); @@ -105,6 +102,7 @@ const char *fs_convert_path(char *buf, const size_t bufsiz, const char *path); bool fs_sys_walk(const char *base, walk_fn_t walk, void *user, const bool recur); bool fs_sys_file_exists(const char *name); bool fs_sys_dir_exists(const char *name); +bool fs_sys_dir_is_empty(const char *name); bool fs_sys_mkdir(const char *name); // creates with 0777 by default bool fs_sys_copy_file(const char *oldname, const char *newname); diff --git a/src/pc/gfx/gfx_sdl2.c b/src/pc/gfx/gfx_sdl2.c index a15fad88..10a96d37 100644 --- a/src/pc/gfx/gfx_sdl2.c +++ b/src/pc/gfx/gfx_sdl2.c @@ -42,7 +42,7 @@ #include "pc/controller/controller_bind_mapping.h" #include "pc/utils/misc.h" #include "pc/mods/mod_import.h" -#include "pc/startup.h" +#include "pc/rom_checker.h" #ifndef GL_MAX_SAMPLES #define GL_MAX_SAMPLES 0x8D57 diff --git a/src/pc/loading.c b/src/pc/loading.c index 5a37d54d..5dd0d164 100644 --- a/src/pc/loading.c +++ b/src/pc/loading.c @@ -5,7 +5,7 @@ #include "loading.h" #include "pc/utils/misc.h" #include "pc/cliopts.h" -#include "startup.h" +#include "rom_checker.h" extern ALIGNED8 u8 texture_coopdx_logo[]; diff --git a/src/pc/mods/mod_storage.cpp b/src/pc/mods/mod_storage.cpp index 9c49f00c..1e3639b2 100644 --- a/src/pc/mods/mod_storage.cpp +++ b/src/pc/mods/mod_storage.cpp @@ -56,8 +56,8 @@ bool char_valid(char* buffer) { } void mod_storage_get_filename(char* dest) { - const char* path = sys_user_path(); // get user path - snprintf(dest, SYS_MAX_PATH - 1, "%s/sav/%s", path, gLuaActiveMod->relativePath); // append sav folder + const char* path = fs_get_write_path(""); // get user path + snprintf(dest, SYS_MAX_PATH - 1, "%ssav/%s", path, gLuaActiveMod->relativePath); // append sav folder strdelete(dest, (char *)".lua"); // delete ".lua" from sav name strcat(dest, SAVE_EXTENSION); // append SAVE_EXTENSION normalize_path(dest); // fix any out of place slashes diff --git a/src/pc/pc_main.c b/src/pc/pc_main.c index 849dec98..0b0a3353 100644 --- a/src/pc/pc_main.c +++ b/src/pc/pc_main.c @@ -19,7 +19,7 @@ #include "audio/audio_null.h" #include "rom_assets.h" -#include "startup.h" +#include "rom_checker.h" #include "pc_main.h" #include "loading.h" #include "cliopts.h" @@ -360,12 +360,11 @@ void* main_game_init(void* isThreaded) { } int main(int argc, char *argv[]) { - - // Handle terminal arguments + // handle terminal arguments if (!parse_cli_opts(argc, argv)) { return 0; } #if defined(_WIN32) || defined(_WIN64) - // Handle Windows console + // handle Windows console if (!gCLIOpts.console) { FreeConsole(); freopen("NUL", "w", stdout); @@ -373,23 +372,23 @@ int main(int argc, char *argv[]) { #endif - legacy_folder_handler(); - - const char *userpath = gCLIOpts.savePath[0] ? gCLIOpts.savePath : sys_user_path(); - fs_init(userpath); + const char* userPath = gCLIOpts.savePath[0] ? gCLIOpts.savePath : sys_user_path(); + fs_init(userPath); configfile_load(); - // Create the window straight away + legacy_folder_handler(); + + // create the window almost straight away if (!gGfxInited) { gfx_init(&WAPI, &RAPI, TITLE); WAPI.set_keyboard_callbacks(keyboard_on_key_down, keyboard_on_key_up, keyboard_on_all_keys_up, keyboard_on_text_input); } - // Render the rom setup screen + // render the rom setup screen if (!main_rom_handler()) { #ifdef LOADING_SCREEN_SUPPORTED if (!gCLIOpts.hideLoadingScreen) { - render_rom_setup_screen(); // Holds the game load until a valid rom is provided + render_rom_setup_screen(); // holds the game load until a valid rom is provided } else #endif { @@ -398,12 +397,12 @@ int main(int argc, char *argv[]) { } } - // Start the thread for setting up the game + // start the thread for setting up the game #ifdef LOADING_SCREEN_SUPPORTED bool threadSuccess = false; if (!gCLIOpts.hideLoadingScreen && pthread_mutex_init(&gLoadingThreadMutex, NULL) == 0) { if (pthread_create(&gLoadingThreadId, NULL, main_game_init, (void*) 1) == 0) { - render_loading_screen(); // Render the loading screen while the game is setup + render_loading_screen(); // render the loading screen while the game is setup threadSuccess = true; } pthread_mutex_destroy(&gLoadingThreadMutex); @@ -411,19 +410,19 @@ int main(int argc, char *argv[]) { if (!threadSuccess) #endif { - main_game_init(NULL); // Failsafe incase threading doesn't work + main_game_init(NULL); // failsafe incase threading doesn't work } // initialize sm64 data and controllers thread5_game_loop(NULL); - // Initialize sound outside threads + // initialize sound outside threads #if defined(AAPI_SDL1) || defined(AAPI_SDL2) if (!audio_api && audio_sdl.init()) { audio_api = &audio_sdl; } #endif if (!audio_api) { audio_api = &audio_null; } - // Initialize djui + // initialize djui djui_init(); djui_unicode_init(); djui_init_late(); @@ -431,7 +430,7 @@ int main(int argc, char *argv[]) { show_update_popup(); - // Init network + // initialize network if (gCLIOpts.network == NT_CLIENT) { network_set_system(NS_SOCKET); snprintf(gGetHostName, MAX_CONFIG_STRING, "%s", gCLIOpts.joinIp); @@ -442,7 +441,7 @@ int main(int argc, char *argv[]) { configNetworkSystem = NS_SOCKET; configHostPort = gCLIOpts.networkPort; - // Horrible, hacky fix for mods that access marioObj straight away + // horrible, hacky fix for mods that access marioObj straight away // best fix: host with the standard main menu method static struct Object sHackyObject = { 0 }; gMarioStates[0].marioObj = &sHackyObject; @@ -453,7 +452,7 @@ int main(int argc, char *argv[]) { network_init(NT_NONE, false); } - // Main loop + // main loop while (true) { debug_context_reset(); CTX_BEGIN(CTX_FRAME); diff --git a/src/pc/platform.c b/src/pc/platform.c index a48ae146..0c8007ce 100644 --- a/src/pc/platform.c +++ b/src/pc/platform.c @@ -81,45 +81,45 @@ void sys_fatal(const char *fmt, ...) { // we can just ask SDL for most of this shit if we have it #include -const char *sys_user_path(void) { +static const char *sys_old_user_path(void) { static char path[SYS_MAX_PATH] = { 0 }; // get the new pref path from SDL - char *sdlpath = SDL_GetPrefPath("", "sm64coopdx"); - if (sdlpath) { - const unsigned int len = strlen(sdlpath); - strncpy(path, sdlpath, sizeof(path)); + char *sdlPath = SDL_GetPrefPath("", "sm64ex-coop"); + if (sdlPath) { + const unsigned int len = strlen(sdlPath); + strncpy(path, sdlPath, sizeof(path)); path[sizeof(path)-1] = 0; - SDL_free(sdlpath); + SDL_free(sdlPath); - if (path[len-1] == '/' || path[len-1] == '\\') - path[len-1] = 0; // strip the trailing separator - - if (!fs_sys_dir_exists(path) && !fs_sys_mkdir(path)) - path[0] = 0; // somehow failed, we got no user path + // strip the trailing separator + if (path[len-1] == '/' || path[len-1] == '\\') { path[len-1] = 0; } } return path; } -const char *sys_old_user_path(void) { +const char *sys_user_path(void) { static char path[SYS_MAX_PATH] = { 0 }; // get the new pref path from SDL - char *sdlpath = SDL_GetPrefPath("", "sm64ex-coop"); - if (sdlpath) { - const unsigned int len = strlen(sdlpath); - strncpy(path, sdlpath, sizeof(path)); + char *sdlPath = SDL_GetPrefPath("", "sm64coopdx"); + if (sdlPath) { + // redirect to the old user path if the current one is empty (likely just created from SDL_GetPrefPath) + if (fs_sys_dir_is_empty(sdlPath)) { + SDL_free(sdlPath); + return sys_old_user_path(); + } + + const unsigned int len = strlen(sdlPath); + strncpy(path, sdlPath, sizeof(path)); path[sizeof(path)-1] = 0; - SDL_free(sdlpath); + SDL_free(sdlPath); - if (path[len-1] == '/' || path[len-1] == '\\') - path[len-1] = 0; // strip the trailing separator - - if (!fs_sys_dir_exists(path) && !fs_sys_mkdir(path)) - path[0] = 0; // somehow failed, we got no user path + // strip the trailing separator + if (path[len-1] == '/' || path[len-1] == '\\') { path[len-1] = 0; } } return path; @@ -127,13 +127,13 @@ const char *sys_old_user_path(void) { const char *sys_exe_path(void) { static char path[SYS_MAX_PATH] = { 0 }; - char *sdlpath = SDL_GetBasePath(); - if (sdlpath && sdlpath[0]) { + char *sdlPath = SDL_GetBasePath(); + if (sdlPath && sdlPath[0]) { // use the SDL path if it exists - const unsigned int len = strlen(sdlpath); - strncpy(path, sdlpath, sizeof(path)); + const unsigned int len = strlen(sdlPath); + strncpy(path, sdlPath, sizeof(path)); path[sizeof(path)-1] = 0; - SDL_free(sdlpath); + SDL_free(sdlPath); if (path[len-1] == '/' || path[len-1] == '\\') path[len-1] = 0; // strip the trailing separator } @@ -157,10 +157,6 @@ const char *sys_user_path(void) { return "."; } -const char *sys_old_user_path(void) { - return "."; -} - const char *sys_exe_path(void) { return "."; } diff --git a/src/pc/platform.h b/src/pc/platform.h index 3c9801ee..0c49dbea 100644 --- a/src/pc/platform.h +++ b/src/pc/platform.h @@ -16,7 +16,6 @@ int sys_strcasecmp(const char *s1, const char *s2); // path stuff const char *sys_user_path(void); -const char *sys_old_user_path(void); const char *sys_exe_path(void); const char *sys_file_extension(const char *fpath); const char *sys_file_name(const char *fpath); diff --git a/src/pc/rom_assets.c b/src/pc/rom_assets.c index 04db6ef6..0558e0b7 100644 --- a/src/pc/rom_assets.c +++ b/src/pc/rom_assets.c @@ -1,7 +1,7 @@ #include #include "rom_assets.h" #include "pc/debuglog.h" -#include "startup.h" +#include "rom_checker.h" struct RomAsset { void* ptr; diff --git a/src/pc/startup.cpp b/src/pc/rom_checker.cpp similarity index 73% rename from src/pc/startup.cpp rename to src/pc/rom_checker.cpp index 3075f550..07998f74 100644 --- a/src/pc/startup.cpp +++ b/src/pc/rom_checker.cpp @@ -13,13 +13,13 @@ extern "C" { #include "mods/mod_cache.h" // for md5 hashing #include "mods/mods.h" #include "loading.h" +#include "fs/fs.h" } namespace fs = std::filesystem; -bool gUserFolderCopied = false; bool gRomIsValid = false; -char gRomFilename[255] = ""; +char gRomFilename[SYS_MAX_PATH] = ""; struct VanillaMD5 { const char *localizationName; @@ -35,23 +35,14 @@ static struct VanillaMD5 sVanillaMD5[] = { { NULL, NULL }, }; -inline static void copy_old_user_folder() { - std::string userPath = sys_user_path(); - std::string oldPath = sys_old_user_path(); - if (fs::exists(oldPath) && (fs::is_empty(userPath) || !fs::exists(userPath))) { - fs::copy(oldPath, userPath, fs::copy_options::recursive); - gUserFolderCopied = true; - } -} - inline static void rename_tmp_folder() { - std::string userPath = sys_user_path(); - std::string oldPath = userPath + "/tmp"; + std::string userPath = fs_get_write_path(""); + std::string oldPath = userPath + "tmp"; if (fs::exists(oldPath)) { #if defined(_WIN32) || defined(_WIN64) SetFileAttributesA(oldPath.c_str(), FILE_ATTRIBUTE_HIDDEN); #endif - fs::rename(oldPath, userPath + "/" + TMP_DIRECTORY); + fs::rename(oldPath, userPath + TMP_DIRECTORY); } } @@ -65,9 +56,9 @@ static bool is_rom_valid(const std::string romPath) { } bool foundHash = false; - for (struct VanillaMD5 *md5 = sVanillaMD5; md5->localizationName != NULL; md5++) { + for (VanillaMD5 *md5 = sVanillaMD5; md5->localizationName != NULL; md5++) { if (md5->md5 == ss.str()) { - std::string destPath = sys_user_path() + std::string("/baserom.") + md5->localizationName + ".z64"; + std::string destPath = fs_get_write_path("") + std::string("baserom.") + md5->localizationName + ".z64"; // Copy the rom to the user path if (romPath != destPath && !std::filesystem::exists(std::filesystem::path(destPath))) { @@ -77,7 +68,7 @@ static bool is_rom_valid(const std::string romPath) { ); } - snprintf(gRomFilename, 255, "%s", destPath.c_str()); // Load the copied rom + snprintf(gRomFilename, SYS_MAX_PATH, "%s", destPath.c_str()); // Load the copied rom gRomIsValid = true; foundHash = true; break; @@ -99,12 +90,11 @@ inline static bool scan_path_for_rom(const char *dir) { extern "C" { void legacy_folder_handler(void) { - copy_old_user_folder(); - if (gUserFolderCopied) { rename_tmp_folder(); } + rename_tmp_folder(); } bool main_rom_handler(void) { - if (scan_path_for_rom(sys_user_path())) { return true; } + if (scan_path_for_rom(fs_get_write_path(""))) { return true; } scan_path_for_rom(sys_exe_path()); return gRomIsValid; } diff --git a/src/pc/startup.h b/src/pc/rom_checker.h similarity index 85% rename from src/pc/startup.h rename to src/pc/rom_checker.h index dff2bd2b..1234526d 100644 --- a/src/pc/startup.h +++ b/src/pc/rom_checker.h @@ -1,6 +1,5 @@ #include "types.h" -extern bool gUserFolderCopied; extern bool gRomIsValid; extern char gRomFilename[];