added support for extra, platform-specific paks

This commit is contained in:
Shaun Inman 2023-02-02 21:03:24 -05:00
parent 67f4cd5322
commit 03029e1e79
2 changed files with 13 additions and 71 deletions

View file

@ -30,10 +30,17 @@ int hide(char* file_name) {
void getDisplayName(const char* in_name, char* out_name) { void getDisplayName(const char* in_name, char* out_name) {
char* tmp; char* tmp;
char work_name[256];
strcpy(work_name, in_name);
strcpy(out_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 // extract just the filename if necessary
tmp = strrchr(in_name, '/'); tmp = strrchr(work_name, '/');
if (tmp) strcpy(out_name, tmp+1); if (tmp) strcpy(out_name, tmp+1);
// remove extension // 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 if (tmp && strlen(tmp)<=4) tmp[0] = '\0'; // 3 letter extension plus dot
// remove trailing parens (round and square) // remove trailing parens (round and square)
char safe_name[256]; strcpy(work_name, out_name);
strcpy(safe_name,out_name);
while ((tmp=strrchr(out_name, '('))!=NULL || (tmp=strrchr(out_name, '['))!=NULL) { while ((tmp=strrchr(out_name, '('))!=NULL || (tmp=strrchr(out_name, '['))!=NULL) {
if (tmp==out_name) break; if (tmp==out_name) break;
tmp[0] = '\0'; 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 // 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 // remove trailing whitespace
tmp = out_name + strlen(out_name) - 1; tmp = out_name + strlen(out_name) - 1;

View file

@ -120,9 +120,6 @@ typedef struct Entry {
char* unique; char* unique;
int type; 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 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; } Entry;
static Entry* Entry_new(char* path, int type) { static Entry* Entry_new(char* path, int type) {
@ -134,8 +131,6 @@ static Entry* Entry_new(char* path, int type) {
self->unique = NULL; self->unique = NULL;
self->type = type; self->type = type;
self->alpha = 0; self->alpha = 0;
self->has_alt = type!=ENTRY_ROM?0:-1;
self->use_alt = type!=ENTRY_ROM?0:-1;
return self; return self;
} }
static void Entry_free(Entry* 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); sprintf(pak_path, "%s/Emus/%s.pak/launch.sh", PAKS_PATH, emu_name);
if (exists(pak_path)) return 1; 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); return exists(pak_path);
} }
static void getEmuPath(char* emu_name, char* 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; if (exists(pak_path)) return;
sprintf(pak_path, "%s/Emus/%s.pak/launch.sh", PAKS_PATH, emu_name); 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 static int hasCue(char* dir_path, char* cue_path) { // NOTE: dir_path not rom_path
char* tmp = strrchr(dir_path, '/') + 1; // folder name char* tmp = strrchr(dir_path, '/') + 1; // folder name
sprintf(cue_path, "%s/%s.cue", dir_path, tmp); 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); 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) { static int hasRecents(void) {
int has = 0; int has = 0;
@ -691,8 +628,7 @@ static Array* getRoot(void) {
} }
Array_free(entries); // root now owns entries' entries Array_free(entries); // root now owns entries' entries
char tools_path[256]; char* tools_path = SDCARD_PATH "/Tools/" PLATFORM;
sprintf(tools_path, "%s/Tools", SDCARD_PATH);
if (exists(tools_path)) Array_push(root, Entry_new(tools_path, ENTRY_DIR)); if (exists(tools_path)) Array_push(root, Entry_new(tools_path, ENTRY_DIR));
return root; return root;