change the way paths are generated for roms contained in subdirectories of archives so that the battery data etc. doesnt get lost

This commit is contained in:
zeromus 2013-06-08 02:29:53 +00:00
parent 60d899b335
commit fa5d62b740
2 changed files with 31 additions and 2 deletions

View File

@ -28,6 +28,10 @@ static const char InvalidPathChars[] = {
'\x08', '\x09', '\x0A', '\x0B', '\x0C', '\x0D', '\x0E', '\x0F', '\x10', '\x11', '\x12',
'\x13', '\x14', '\x15', '\x16', '\x17', '\x18', '\x19', '\x1A', '\x1B', '\x1C', '\x1D',
'\x1E', '\x1F'
//but I added this
#ifdef _WINDOWS
,'\x2F'
#endif
};
//but it is sort of windows-specific. Does it work in linux? Maybe we'll have to make it smarter
@ -58,7 +62,7 @@ std::string Path::GetFileDirectoryPath(std::string filePath)
return "";
}
size_t i = filePath.find_last_of(DIRECTORY_DELIMITER_CHAR);
size_t i = filePath.find_last_of(ALL_DIRECTORY_DELIMITER_STRING);
if (i == std::string::npos) {
return filePath;
}
@ -72,7 +76,7 @@ std::string Path::GetFileNameFromPath(std::string filePath)
return "";
}
size_t i = filePath.find_last_of(DIRECTORY_DELIMITER_CHAR);
size_t i = filePath.find_last_of(ALL_DIRECTORY_DELIMITER_STRING);
if (i == std::string::npos) {
return filePath;
}
@ -94,6 +98,27 @@ std::string Path::GetFileNameWithoutExt(std::string fileName)
return fileName.substr(0, i);
}
std::string Path::ScrubInvalid(std::string str)
{
for (std::string::iterator it(str.begin()); it != str.end(); ++it)
{
bool ok = true;
for(int i=0;i<ARRAY_SIZE(InvalidPathChars);i++)
{
if(InvalidPathChars[i] == *it)
{
ok = false;
break;
}
}
if(!ok)
*it = '*';
}
return str;
}
std::string Path::GetFileNameFromPathWithoutExt(std::string filePath)
{
if (filePath.empty()) {

View File

@ -42,9 +42,11 @@
#ifdef _WINDOWS
#define FILE_EXT_DELIMITER_CHAR '.'
#define DIRECTORY_DELIMITER_CHAR '\\'
#define ALL_DIRECTORY_DELIMITER_STRING "/\\"
#else
#define FILE_EXT_DELIMITER_CHAR '.'
#define DIRECTORY_DELIMITER_CHAR '/'
#define ALL_DIRECTORY_DELIMITER_STRING "/"
#endif
#ifdef _WINDOWS
@ -57,6 +59,7 @@ public:
static bool IsPathRooted (const std::string &path);
static std::string GetFileDirectoryPath(std::string filePath);
static std::string GetFileNameFromPath(std::string filePath);
static std::string ScrubInvalid(std::string str);
static std::string GetFileNameWithoutExt(std::string fileName);
static std::string GetFileNameFromPathWithoutExt(std::string filePath);
static std::string GetFileExt(std::string fileName);
@ -412,6 +415,7 @@ public:
std::string romPath = filename;
RomName = Path::GetFileNameFromPath(romPath);
RomName = Path::ScrubInvalid(RomName);
RomDirectory = Path::GetFileDirectoryPath(romPath);
}