From 03029e1e794b144e4303d62ff8fdcd0ac5d2eca8 Mon Sep 17 00:00:00 2001 From: Shaun Inman Date: Thu, 2 Feb 2023 21:03:24 -0500 Subject: [PATCH] added support for extra, platform-specific paks --- src/common/utils.c | 14 +++++++--- src/minui/main.c | 70 ++-------------------------------------------- 2 files changed, 13 insertions(+), 71 deletions(-) diff --git a/src/common/utils.c b/src/common/utils.c index 34e7cc3..f048d70 100644 --- a/src/common/utils.c +++ b/src/common/utils.c @@ -30,10 +30,17 @@ int hide(char* file_name) { void getDisplayName(const char* in_name, char* out_name) { char* tmp; + char work_name[256]; + strcpy(work_name, in_name); strcpy(out_name, in_name); + if (suffixMatch("/" PLATFORM, work_name)) { // hide platform from Tools path... + tmp = strrchr(work_name, '/'); + tmp[0] = '\0'; + } + // extract just the filename if necessary - tmp = strrchr(in_name, '/'); + tmp = strrchr(work_name, '/'); if (tmp) strcpy(out_name, tmp+1); // remove extension @@ -41,8 +48,7 @@ void getDisplayName(const char* in_name, char* out_name) { if (tmp && strlen(tmp)<=4) tmp[0] = '\0'; // 3 letter extension plus dot // remove trailing parens (round and square) - char safe_name[256]; - strcpy(safe_name,out_name); + strcpy(work_name, out_name); while ((tmp=strrchr(out_name, '('))!=NULL || (tmp=strrchr(out_name, '['))!=NULL) { if (tmp==out_name) break; tmp[0] = '\0'; @@ -50,7 +56,7 @@ void getDisplayName(const char* in_name, char* out_name) { } // make sure we haven't nuked the entire name - if (out_name[0]=='\0') strcpy(out_name, safe_name); + if (out_name[0]=='\0') strcpy(out_name, work_name); // remove trailing whitespace tmp = out_name + strlen(out_name) - 1; diff --git a/src/minui/main.c b/src/minui/main.c index ea0974c..dd939a1 100644 --- a/src/minui/main.c +++ b/src/minui/main.c @@ -120,9 +120,6 @@ typedef struct Entry { char* unique; int type; int alpha; // index in parent Directory's alphas Array, which points to the index of an Entry in its entries Array :sweat_smile: - - int has_alt; - int use_alt; } Entry; static Entry* Entry_new(char* path, int type) { @@ -134,8 +131,6 @@ static Entry* Entry_new(char* path, int type) { self->unique = NULL; self->type = type; self->alpha = 0; - self->has_alt = type!=ENTRY_ROM?0:-1; - self->use_alt = type!=ENTRY_ROM?0:-1; return self; } static void Entry_free(Entry* self) { @@ -411,19 +406,14 @@ static int hasEmu(char* emu_name) { sprintf(pak_path, "%s/Emus/%s.pak/launch.sh", PAKS_PATH, emu_name); if (exists(pak_path)) return 1; - sprintf(pak_path, "%s/Emus/%s.pak/launch.sh", SDCARD_PATH, emu_name); + sprintf(pak_path, "%s/Emus/%s/%s.pak/launch.sh", SDCARD_PATH, PLATFORM, emu_name); return exists(pak_path); } static void getEmuPath(char* emu_name, char* pak_path) { - sprintf(pak_path, "%s/Emus/%s.pak/launch.sh", SDCARD_PATH, emu_name); + sprintf(pak_path, "%s/Emus/%s/%s.pak/launch.sh", SDCARD_PATH, PLATFORM, emu_name); if (exists(pak_path)) return; sprintf(pak_path, "%s/Emus/%s.pak/launch.sh", PAKS_PATH, emu_name); } -static int hasAlt(char* emu_name) { - char pak_path[256]; - sprintf(pak_path, "%s/Emus/%s.pak/has-alt", PAKS_PATH, emu_name); - return exists(pak_path); -} static int hasCue(char* dir_path, char* cue_path) { // NOTE: dir_path not rom_path char* tmp = strrchr(dir_path, '/') + 1; // folder name sprintf(cue_path, "%s/%s.cue", dir_path, tmp); @@ -459,59 +449,6 @@ static int hasM3u(char* rom_path, char* m3u_path) { // NOTE: rom_path not dir_pa return exists(m3u_path); } -static int Entry_hasAlt(Entry* self) { - // has_alt can be set by getEntries() - // but won't be set by getRecents() - // otherwise delayed until selected - if (self->has_alt==-1) { - // check - char emu_name[256]; - getEmuName(self->path, emu_name); - self->has_alt = hasAlt(emu_name); - } - return self->has_alt; -} -static int Entry_useAlt(Entry* self) { - // has to be checked on an individual basis - // but delayed until selected - - if (self->use_alt==-1) { - // check - char emu_name[256]; - getEmuName(self->path, emu_name); - - char rom_name[256]; - char* tmp = strrchr(self->path, '/'); - if (tmp) strcpy(rom_name, tmp+1); - - char use_alt[256]; - sprintf(use_alt, "%s/.minui/%s/%s.use-alt", USERDATA_PATH, emu_name, rom_name); - - self->use_alt = exists(use_alt); - } - return self->use_alt; -} -static int Entry_toggleAlt(Entry* self) { - if (!Entry_hasAlt(self)) return 0; - - self->use_alt = !Entry_useAlt(self); - - char emu_name[256]; - getEmuName(self->path, emu_name); - - char rom_name[256]; - char* tmp = strrchr(self->path, '/'); - if (tmp) strcpy(rom_name, tmp+1); - - char use_alt_path[256]; - sprintf(use_alt_path, "%s/.minui/%s/%s.use-alt", USERDATA_PATH, emu_name, rom_name); - - if (self->use_alt==1) touch(use_alt_path); - else unlink(use_alt_path); - - return 1; -} - static int hasRecents(void) { int has = 0; @@ -691,8 +628,7 @@ static Array* getRoot(void) { } Array_free(entries); // root now owns entries' entries - char tools_path[256]; - sprintf(tools_path, "%s/Tools", SDCARD_PATH); + char* tools_path = SDCARD_PATH "/Tools/" PLATFORM; if (exists(tools_path)) Array_push(root, Entry_new(tools_path, ENTRY_DIR)); return root;