mirror of
https://github.com/dborth/fceugx.git
synced 2025-01-07 14:28:18 +01:00
better path handling code
This commit is contained in:
parent
574243e93b
commit
5016e4d522
@ -124,6 +124,28 @@ void ResetBrowser()
|
|||||||
memset(browserList, 0, sizeof(BROWSERENTRY));
|
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()
|
* UpdateDirName()
|
||||||
* Update curent directory name for file browser
|
* 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)
|
if ((strlen(browser.dir)+1+strlen(browserList[browser.selIndex].filename)) < MAXPATHLEN)
|
||||||
{
|
{
|
||||||
/* update current directory name */
|
/* 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;
|
return 1;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@ -197,7 +219,7 @@ bool MakeFilePath(char filepath[], int type, int method, char * filename, int fi
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
sprintf(temppath, "%s/%s",browser.dir,browserList[browser.selIndex].filename);
|
sprintf(temppath, "%s%s",browser.dir,browserList[browser.selIndex].filename);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@ -263,10 +285,11 @@ bool MakeFilePath(char filepath[], int type, int method, char * filename, int fi
|
|||||||
temppath[31] = 0; // truncate filename
|
temppath[31] = 0; // truncate filename
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
sprintf (temppath, "%s/%s", folder, file);
|
sprintf (temppath, "/%s/%s", folder, file);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
CleanupPath(temppath); // cleanup path
|
||||||
strncpy(filepath, temppath, MAXPATHLEN);
|
strncpy(filepath, temppath, MAXPATHLEN);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@ -509,6 +532,8 @@ int BrowserChangeFolder(int method)
|
|||||||
if(!UpdateDirName(method))
|
if(!UpdateDirName(method))
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
|
CleanupPath(browser.dir);
|
||||||
|
|
||||||
switch (method)
|
switch (method)
|
||||||
{
|
{
|
||||||
case METHOD_DVD:
|
case METHOD_DVD:
|
||||||
@ -550,7 +575,8 @@ OpenGameList ()
|
|||||||
SwitchDVDFolder(GCSettings.LoadFolder); // switch to ROM folder
|
SwitchDVDFolder(GCSettings.LoadFolder); // switch to ROM folder
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
sprintf(browser.dir, "/%s", GCSettings.LoadFolder);
|
sprintf(browser.dir, "/%s/", GCSettings.LoadFolder);
|
||||||
|
CleanupPath(browser.dir);
|
||||||
ParseDirectory(method); // Parse root directory
|
ParseDirectory(method); // Parse root directory
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -171,11 +171,11 @@ InitDeviceThread()
|
|||||||
void UnmountAllFAT()
|
void UnmountAllFAT()
|
||||||
{
|
{
|
||||||
#ifdef HW_RVL
|
#ifdef HW_RVL
|
||||||
fatUnmount("sd:/");
|
fatUnmount("sd:");
|
||||||
fatUnmount("usb:/");
|
fatUnmount("usb:");
|
||||||
#else
|
#else
|
||||||
fatUnmount("carda:/");
|
fatUnmount("carda:");
|
||||||
fatUnmount("cardb:/");
|
fatUnmount("cardb:");
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -219,7 +219,7 @@ bool MountFAT(int method)
|
|||||||
return false; // unknown device
|
return false; // unknown device
|
||||||
}
|
}
|
||||||
|
|
||||||
sprintf(rootdir, "%s:/", name);
|
sprintf(rootdir, "%s:", name);
|
||||||
|
|
||||||
if(unmountRequired[method])
|
if(unmountRequired[method])
|
||||||
{
|
{
|
||||||
@ -282,27 +282,29 @@ bool ChangeInterface(int method, bool silent)
|
|||||||
}
|
}
|
||||||
else if(method == METHOD_DVD)
|
else if(method == METHOD_DVD)
|
||||||
{
|
{
|
||||||
rootdir[0] = 0;
|
|
||||||
mounted = MountDVD(silent);
|
mounted = MountDVD(silent);
|
||||||
}
|
}
|
||||||
#ifdef HW_RVL
|
#ifdef HW_RVL
|
||||||
else if(method == METHOD_SMB)
|
else if(method == METHOD_SMB)
|
||||||
{
|
{
|
||||||
sprintf(rootdir, "smb:/");
|
|
||||||
mounted = ConnectShare(silent);
|
mounted = ConnectShare(silent);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
else if(method == METHOD_MC_SLOTA)
|
else if(method == METHOD_MC_SLOTA)
|
||||||
{
|
{
|
||||||
rootdir[0] = 0;
|
|
||||||
mounted = TestMC(CARD_SLOTA, silent);
|
mounted = TestMC(CARD_SLOTA, silent);
|
||||||
}
|
}
|
||||||
else if(method == METHOD_MC_SLOTB)
|
else if(method == METHOD_MC_SLOTB)
|
||||||
{
|
{
|
||||||
rootdir[0] = 0;
|
|
||||||
mounted = TestMC(CARD_SLOTB, silent);
|
mounted = TestMC(CARD_SLOTB, silent);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(!mounted)
|
||||||
|
{
|
||||||
|
sprintf(browser.dir,"/");
|
||||||
|
rootdir[0] = 0;
|
||||||
|
}
|
||||||
|
|
||||||
return mounted;
|
return mounted;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -346,7 +348,8 @@ ParseDirectory(int method)
|
|||||||
if(ChangeInterface(method, SILENT))
|
if(ChangeInterface(method, SILENT))
|
||||||
{
|
{
|
||||||
sprintf(browser.dir,"/");
|
sprintf(browser.dir,"/");
|
||||||
dir = diropen(rootdir);
|
sprintf(fulldir, "%s%s", rootdir, browser.dir);
|
||||||
|
dir = diropen(fulldir);
|
||||||
if (dir == NULL)
|
if (dir == NULL)
|
||||||
{
|
{
|
||||||
sprintf(msg, "Error opening %s", rootdir);
|
sprintf(msg, "Error opening %s", rootdir);
|
||||||
|
@ -22,6 +22,7 @@
|
|||||||
#include "menu.h"
|
#include "menu.h"
|
||||||
#include "fileop.h"
|
#include "fileop.h"
|
||||||
#include "http.h"
|
#include "http.h"
|
||||||
|
#include "filebrowser.h"
|
||||||
|
|
||||||
static bool inNetworkInit = false;
|
static bool inNetworkInit = false;
|
||||||
static bool networkInit = false;
|
static bool networkInit = false;
|
||||||
@ -280,6 +281,7 @@ ConnectShare (bool silent)
|
|||||||
GCSettings.smbshare, GCSettings.smbip))
|
GCSettings.smbshare, GCSettings.smbip))
|
||||||
{
|
{
|
||||||
networkShareInit = true;
|
networkShareInit = true;
|
||||||
|
sprintf(rootdir, "smb:");
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!silent)
|
if(!silent)
|
||||||
|
Loading…
Reference in New Issue
Block a user