From 8e8e62ac33aa27a268b34d9e16ef141767a5434a Mon Sep 17 00:00:00 2001 From: yellows8 Date: Thu, 1 Nov 2018 21:41:23 -0400 Subject: [PATCH] In menuScan(), don't add an extra '/' to the path when the cwd path already has it at the end, which happens with rootdir. This fixes rootdir support on 1.0.0. Added check for '/' in menuEntryLoad() for the dirlisting code which checks menuGetRootPath(). --- common/menu-entry.c | 5 +++-- common/menu-list.c | 14 +++++++++++++- 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/common/menu-entry.c b/common/menu-entry.c index 41d447d..ab34d3a 100644 --- a/common/menu-entry.c +++ b/common/menu-entry.c @@ -183,7 +183,7 @@ static bool menuEntryLoadEmbeddedNacp(menuEntry_s* me) { }*/ bool menuEntryLoad(menuEntry_s* me, const char* name, bool shortcut) { - int i=0; + int i=0, tmplen; menu_s *menu_fileassoc = menuFileassocGetCurrent(); menuEntry_s* fileassoc_me = NULL; char *strptr = NULL; @@ -203,7 +203,8 @@ bool menuEntryLoad(menuEntry_s* me, const char* name, bool shortcut) { bool fileassoc_flag = 0; //Use the first .nro found in the directory, if there's only 1 NRO in the directory. Only used for paths starting with "sdmc:/switch/". - if (!found && strncmp(me->path, menuGetRootPath(), strlen(menuGetRootPath()))==0) { + tmplen = strlen(menuGetRootPath()); + if (!found && strncmp(me->path, menuGetRootPath(), tmplen)==0 && me->path[tmplen]=='/') { DIR* dir; struct dirent* dp; u32 nro_count=0; diff --git a/common/menu-list.c b/common/menu-list.c index 4341247..d693f54 100644 --- a/common/menu-list.c +++ b/common/menu-list.c @@ -120,10 +120,22 @@ static void menuSort(void) { } int menuScan(const char* target) { + int pos; + char dirsep[8]; + if (chdir(target) < 0) return 1; if (getcwd(s_menu[!s_curMenu].dirname, PATH_MAX+1) == NULL) return 1; + memset(dirsep, 0, sizeof(dirsep)); + dirsep[0] = '/'; + + //While cwd will not have '/' at the end normally, it will have it when cwd is the root dir ("sdmc:/"). Don't add '/' to the path below when it's already present. + pos = strlen(s_menu[!s_curMenu].dirname); + if (pos > 0) { + if (s_menu[!s_curMenu].dirname[pos-1] == '/') dirsep[0] = 0; + } + DIR* dir; struct dirent* dp; char tmp_path[PATH_MAX+1]; @@ -140,7 +152,7 @@ int menuScan(const char* target) { bool entrytype=0; memset(tmp_path, 0, sizeof(tmp_path)); - snprintf(tmp_path, sizeof(tmp_path)-1, "%s/%s", s_menu[!s_curMenu].dirname, dp->d_name); + snprintf(tmp_path, sizeof(tmp_path)-1, "%s%s%s", s_menu[!s_curMenu].dirname, dirsep, dp->d_name); #ifdef __SWITCH__ fsdev_dir_t* dirSt = (fsdev_dir_t*)dir->dirData->dirStruct;