diff --git a/source/ngc/filebrowser.cpp b/source/ngc/filebrowser.cpp index 091083c..2c1ccc7 100644 --- a/source/ngc/filebrowser.cpp +++ b/source/ngc/filebrowser.cpp @@ -124,6 +124,28 @@ void ResetBrowser() memset(browserList, 0, sizeof(BROWSERENTRY)); } +/**************************************************************************** + * CleanupPath() + * Cleans up the filepath, removing double // and replacing \ with / + ***************************************************************************/ +static void CleanupPath(char * path) +{ + int pathlen = strlen(path); + int j = 0; + for(int i=0; i < pathlen && i < MAXPATHLEN; i++) + { + if(path[i] == '\\') + path[i] = '/'; + + if(j == 0 || !(path[j-1] == '/' && path[i] == '/')) + path[j++] = path[i]; + } + path[j] = 0; + + if(strlen(path) == 0) + sprintf(path, "/"); +} + /**************************************************************************** * UpdateDirName() * Update curent directory name for file browser @@ -168,7 +190,7 @@ int UpdateDirName(int method) if ((strlen(browser.dir)+1+strlen(browserList[browser.selIndex].filename)) < MAXPATHLEN) { /* update current directory name */ - sprintf(browser.dir, "%s/%s",browser.dir, browserList[browser.selIndex].filename); + sprintf(browser.dir, "%s%s/",browser.dir, browserList[browser.selIndex].filename); return 1; } else @@ -197,7 +219,7 @@ bool MakeFilePath(char filepath[], int type, int method, char * filename, int fi } else { - sprintf(temppath, "%s/%s",browser.dir,browserList[browser.selIndex].filename); + sprintf(temppath, "%s%s",browser.dir,browserList[browser.selIndex].filename); } } else @@ -263,10 +285,11 @@ bool MakeFilePath(char filepath[], int type, int method, char * filename, int fi temppath[31] = 0; // truncate filename break; default: - sprintf (temppath, "%s/%s", folder, file); + sprintf (temppath, "/%s/%s", folder, file); break; } } + CleanupPath(temppath); // cleanup path strncpy(filepath, temppath, MAXPATHLEN); return true; } @@ -509,6 +532,8 @@ int BrowserChangeFolder(int method) if(!UpdateDirName(method)) return -1; + CleanupPath(browser.dir); + switch (method) { case METHOD_DVD: @@ -550,7 +575,8 @@ OpenGameList () SwitchDVDFolder(GCSettings.LoadFolder); // switch to ROM folder break; default: - sprintf(browser.dir, "/%s", GCSettings.LoadFolder); + sprintf(browser.dir, "/%s/", GCSettings.LoadFolder); + CleanupPath(browser.dir); ParseDirectory(method); // Parse root directory break; } diff --git a/source/ngc/fileop.cpp b/source/ngc/fileop.cpp index bbf95fb..8120ed0 100644 --- a/source/ngc/fileop.cpp +++ b/source/ngc/fileop.cpp @@ -171,11 +171,11 @@ InitDeviceThread() void UnmountAllFAT() { #ifdef HW_RVL - fatUnmount("sd:/"); - fatUnmount("usb:/"); + fatUnmount("sd:"); + fatUnmount("usb:"); #else - fatUnmount("carda:/"); - fatUnmount("cardb:/"); + fatUnmount("carda:"); + fatUnmount("cardb:"); #endif } @@ -219,7 +219,7 @@ bool MountFAT(int method) return false; // unknown device } - sprintf(rootdir, "%s:/", name); + sprintf(rootdir, "%s:", name); if(unmountRequired[method]) { @@ -282,27 +282,29 @@ bool ChangeInterface(int method, bool silent) } else if(method == METHOD_DVD) { - rootdir[0] = 0; mounted = MountDVD(silent); } #ifdef HW_RVL else if(method == METHOD_SMB) { - sprintf(rootdir, "smb:/"); mounted = ConnectShare(silent); } #endif else if(method == METHOD_MC_SLOTA) { - rootdir[0] = 0; mounted = TestMC(CARD_SLOTA, silent); } else if(method == METHOD_MC_SLOTB) { - rootdir[0] = 0; mounted = TestMC(CARD_SLOTB, silent); } + if(!mounted) + { + sprintf(browser.dir,"/"); + rootdir[0] = 0; + } + return mounted; } @@ -346,7 +348,8 @@ ParseDirectory(int method) if(ChangeInterface(method, SILENT)) { sprintf(browser.dir,"/"); - dir = diropen(rootdir); + sprintf(fulldir, "%s%s", rootdir, browser.dir); + dir = diropen(fulldir); if (dir == NULL) { sprintf(msg, "Error opening %s", rootdir); diff --git a/source/ngc/networkop.cpp b/source/ngc/networkop.cpp index 00984ab..2da73a9 100644 --- a/source/ngc/networkop.cpp +++ b/source/ngc/networkop.cpp @@ -22,6 +22,7 @@ #include "menu.h" #include "fileop.h" #include "http.h" +#include "filebrowser.h" static bool inNetworkInit = false; static bool networkInit = false; @@ -280,6 +281,7 @@ ConnectShare (bool silent) GCSettings.smbshare, GCSettings.smbip)) { networkShareInit = true; + sprintf(rootdir, "smb:"); } if(!silent)