Skip to content

Commit

Permalink
In menuScan(), don't add an extra '/' to the path when the cwd path a…
Browse files Browse the repository at this point in the history
…lready 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().
  • Loading branch information
yellows8 committed Nov 2, 2018
1 parent d2bb1da commit 8e8e62a
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
5 changes: 3 additions & 2 deletions common/menu-entry.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down
14 changes: 13 additions & 1 deletion common/menu-list.c
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Expand All @@ -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;
Expand Down

0 comments on commit 8e8e62a

Please sign in to comment.