Rework new user folder system, make it just read sm64ex-coop if sm64coopdx isn't present, no more copying

This commit is contained in:
Agent X 2024-05-16 17:15:25 -04:00
parent 3b13b06b00
commit f2a6891a08
25 changed files with 97 additions and 105 deletions

View File

@ -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"

View File

@ -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);
}

View File

@ -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í '@'!"

View File

@ -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!"

View File

@ -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 '@'!"

View File

@ -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é '@' !"

View File

@ -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!"

View File

@ -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 '@'!"

View File

@ -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 '@'!"

View File

@ -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!"

View File

@ -31,7 +31,6 @@ LOBBY_HOST = "Создать группу"
UPDATE_AVAILABLE = "Новое обновление!"
LATEST_VERSION = "Последняя версия"
YOUR_VERSION = "Ваша версия"
USER_FOLDER_COPIED = "\\#a0ffa0\\Успех!\n\\#dcdcdc\\Папка пользователя sm64ex-coop была скопирована в новую sm64coopdx."
[CHAT]
KICKING = "'@' выгнан!"

View File

@ -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!"

View File

@ -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) {

View File

@ -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
}

View File

@ -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;

View File

@ -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);

View File

@ -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

View File

@ -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[];

View File

@ -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

View File

@ -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);

View File

@ -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 <SDL2/SDL.h>
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 ".";
}

View File

@ -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);

View File

@ -1,7 +1,7 @@
#include <PR/ultratypes.h>
#include "rom_assets.h"
#include "pc/debuglog.h"
#include "startup.h"
#include "rom_checker.h"
struct RomAsset {
void* ptr;

View File

@ -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;
}

View File

@ -1,6 +1,5 @@
#include "types.h"
extern bool gUserFolderCopied;
extern bool gRomIsValid;
extern char gRomFilename[];