From 12aff40090c30eb7f88b8114648f62bba863133f Mon Sep 17 00:00:00 2001 From: Agent X <44549182+AgentXLP@users.noreply.github.com> Date: Sun, 12 May 2024 14:04:12 -0400 Subject: [PATCH] Make user folder sm64coopdx instead of sm64ex-coop, add auto folder copy --- lang/Czech.ini | 1 + lang/Dutch.ini | 1 + lang/English.ini | 1 + 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/gfx/gfx_sdl2.c | 2 +- src/pc/loading.c | 2 +- src/pc/pc_main.c | 4 +++- src/pc/platform.c | 26 +++++++++++++++++++++++++ src/pc/platform.h | 1 + src/pc/rom_assets.c | 2 +- src/pc/{rom_checker.cpp => startup.cpp} | 18 ++++++++++++++++- src/pc/{rom_checker.h => startup.h} | 3 +++ 19 files changed, 68 insertions(+), 5 deletions(-) rename src/pc/{rom_checker.cpp => startup.cpp} (86%) rename src/pc/{rom_checker.h => startup.h} (67%) diff --git a/lang/Czech.ini b/lang/Czech.ini index 2326f03b..040c4763 100644 --- a/lang/Czech.ini +++ b/lang/Czech.ini @@ -31,6 +31,7 @@ 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 f054d838..c01cf62d 100644 --- a/lang/Dutch.ini +++ b/lang/Dutch.ini @@ -31,6 +31,7 @@ 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 e546fdb9..df818422 100644 --- a/lang/English.ini +++ b/lang/English.ini @@ -31,6 +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." [CHAT] KICKING = "Kicking '@'!" diff --git a/lang/French.ini b/lang/French.ini index f8a1e965..5e404bb4 100644 --- a/lang/French.ini +++ b/lang/French.ini @@ -31,6 +31,7 @@ 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 52ddc6dc..5d503657 100644 --- a/lang/German.ini +++ b/lang/German.ini @@ -31,6 +31,7 @@ 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 a10478ca..16f9ed3c 100644 --- a/lang/Italian.ini +++ b/lang/Italian.ini @@ -31,6 +31,7 @@ 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 e2826f5e..1e778a3a 100644 --- a/lang/Polish.ini +++ b/lang/Polish.ini @@ -31,6 +31,7 @@ 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 d8da48e4..b3205f5b 100644 --- a/lang/Portuguese.ini +++ b/lang/Portuguese.ini @@ -31,6 +31,7 @@ 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 25d495d7..4d06da0b 100644 --- a/lang/Russian.ini +++ b/lang/Russian.ini @@ -31,6 +31,7 @@ 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 42e377b6..43243076 100644 --- a/lang/Spanish.ini +++ b/lang/Spanish.ini @@ -31,6 +31,7 @@ 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 a8febe8d..8fedb3f2 100644 --- a/src/pc/djui/djui.c +++ b/src/pc/djui/djui.c @@ -15,6 +15,7 @@ #include "djui_hud_utils.h" #include "engine/math_util.h" #include "pc/utils/misc.h" +#include "pc/startup.h" static Gfx* sSavedDisplayListHead = NULL; @@ -109,6 +110,10 @@ 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/gfx/gfx_sdl2.c b/src/pc/gfx/gfx_sdl2.c index 10a96d37..a15fad88 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/rom_checker.h" +#include "pc/startup.h" #ifndef GL_MAX_SAMPLES #define GL_MAX_SAMPLES 0x8D57 diff --git a/src/pc/loading.c b/src/pc/loading.c index 5dd0d164..5a37d54d 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 "rom_checker.h" +#include "startup.h" extern ALIGNED8 u8 texture_coopdx_logo[]; diff --git a/src/pc/pc_main.c b/src/pc/pc_main.c index 9c1d9ff4..bf774188 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 "rom_checker.h" +#include "startup.h" #include "pc_main.h" #include "loading.h" #include "cliopts.h" @@ -373,6 +373,8 @@ int main(int argc, char *argv[]) { #endif + old_user_folder_handler(); + const char *userpath = gCLIOpts.savePath[0] ? gCLIOpts.savePath : sys_user_path(); fs_init(userpath); configfile_load(); diff --git a/src/pc/platform.c b/src/pc/platform.c index 9906793a..a48ae146 100644 --- a/src/pc/platform.c +++ b/src/pc/platform.c @@ -84,6 +84,28 @@ void sys_fatal(const char *fmt, ...) { const char *sys_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)); + path[sizeof(path)-1] = 0; + + 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 + } + + return path; +} + +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("", "sm64ex-coop"); if (sdlpath) { @@ -135,6 +157,10 @@ 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 47694f40..e9923623 100644 --- a/src/pc/platform.h +++ b/src/pc/platform.h @@ -16,6 +16,7 @@ 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 0558e0b7..04db6ef6 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 "rom_checker.h" +#include "startup.h" struct RomAsset { void* ptr; diff --git a/src/pc/rom_checker.cpp b/src/pc/startup.cpp similarity index 86% rename from src/pc/rom_checker.cpp rename to src/pc/startup.cpp index fa7c2187..1ffea3c4 100644 --- a/src/pc/rom_checker.cpp +++ b/src/pc/startup.cpp @@ -7,10 +7,12 @@ extern "C" { #include "platform.h" #include "mods/mods_utils.h" // for str_ends_with #include "mods/mod_cache.h" // for md5 hashing +#include "loading.h" } -#include "loading.h" +namespace fs = std::filesystem; +bool gUserFolderCopied = false; bool gRomIsValid = false; char gRomFilename[255] = ""; @@ -28,6 +30,16 @@ static struct VanillaMD5 sVanillaMD5[] = { { NULL, NULL }, }; +static void copy_old_user_folder() { + char* oldpath = (char*)sys_old_user_path(); + char* newpath = (char*)sys_user_path(); + + if (fs::exists(oldpath) && (fs::is_empty(newpath) || !fs::exists(newpath))) { + fs::copy(oldpath, newpath); + gUserFolderCopied = true; + } +} + static bool is_rom_valid(const std::string romPath) { u8 dataHash[16] = { 0 }; mod_cache_md5(romPath.c_str(), dataHash); @@ -71,6 +83,10 @@ inline static bool scan_path_for_rom(const char *dir) { } extern "C" { +void old_user_folder_handler(void) { + copy_old_user_folder(); +} + bool main_rom_handler(void) { if (scan_path_for_rom(sys_user_path())) { return true; } scan_path_for_rom(sys_exe_path()); diff --git a/src/pc/rom_checker.h b/src/pc/startup.h similarity index 67% rename from src/pc/rom_checker.h rename to src/pc/startup.h index c053f8a3..fcb12b86 100644 --- a/src/pc/rom_checker.h +++ b/src/pc/startup.h @@ -1,7 +1,10 @@ #include "types.h" +extern bool gUserFolderCopied; extern bool gRomIsValid; extern char gRomFilename[]; +void old_user_folder_handler(void); + bool main_rom_handler(void); void rom_on_drop_file(const char *path);