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:
parent
60d899b335
commit
fa5d62b740
|
@ -28,6 +28,10 @@ static const char InvalidPathChars[] = {
|
||||||
'\x08', '\x09', '\x0A', '\x0B', '\x0C', '\x0D', '\x0E', '\x0F', '\x10', '\x11', '\x12',
|
'\x08', '\x09', '\x0A', '\x0B', '\x0C', '\x0D', '\x0E', '\x0F', '\x10', '\x11', '\x12',
|
||||||
'\x13', '\x14', '\x15', '\x16', '\x17', '\x18', '\x19', '\x1A', '\x1B', '\x1C', '\x1D',
|
'\x13', '\x14', '\x15', '\x16', '\x17', '\x18', '\x19', '\x1A', '\x1B', '\x1C', '\x1D',
|
||||||
'\x1E', '\x1F'
|
'\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
|
//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 "";
|
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) {
|
if (i == std::string::npos) {
|
||||||
return filePath;
|
return filePath;
|
||||||
}
|
}
|
||||||
|
@ -72,7 +76,7 @@ std::string Path::GetFileNameFromPath(std::string filePath)
|
||||||
return "";
|
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) {
|
if (i == std::string::npos) {
|
||||||
return filePath;
|
return filePath;
|
||||||
}
|
}
|
||||||
|
@ -94,6 +98,27 @@ std::string Path::GetFileNameWithoutExt(std::string fileName)
|
||||||
return fileName.substr(0, i);
|
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)
|
std::string Path::GetFileNameFromPathWithoutExt(std::string filePath)
|
||||||
{
|
{
|
||||||
if (filePath.empty()) {
|
if (filePath.empty()) {
|
||||||
|
|
|
@ -42,9 +42,11 @@
|
||||||
#ifdef _WINDOWS
|
#ifdef _WINDOWS
|
||||||
#define FILE_EXT_DELIMITER_CHAR '.'
|
#define FILE_EXT_DELIMITER_CHAR '.'
|
||||||
#define DIRECTORY_DELIMITER_CHAR '\\'
|
#define DIRECTORY_DELIMITER_CHAR '\\'
|
||||||
|
#define ALL_DIRECTORY_DELIMITER_STRING "/\\"
|
||||||
#else
|
#else
|
||||||
#define FILE_EXT_DELIMITER_CHAR '.'
|
#define FILE_EXT_DELIMITER_CHAR '.'
|
||||||
#define DIRECTORY_DELIMITER_CHAR '/'
|
#define DIRECTORY_DELIMITER_CHAR '/'
|
||||||
|
#define ALL_DIRECTORY_DELIMITER_STRING "/"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef _WINDOWS
|
#ifdef _WINDOWS
|
||||||
|
@ -57,6 +59,7 @@ public:
|
||||||
static bool IsPathRooted (const std::string &path);
|
static bool IsPathRooted (const std::string &path);
|
||||||
static std::string GetFileDirectoryPath(std::string filePath);
|
static std::string GetFileDirectoryPath(std::string filePath);
|
||||||
static std::string GetFileNameFromPath(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 GetFileNameWithoutExt(std::string fileName);
|
||||||
static std::string GetFileNameFromPathWithoutExt(std::string filePath);
|
static std::string GetFileNameFromPathWithoutExt(std::string filePath);
|
||||||
static std::string GetFileExt(std::string fileName);
|
static std::string GetFileExt(std::string fileName);
|
||||||
|
@ -412,6 +415,7 @@ public:
|
||||||
std::string romPath = filename;
|
std::string romPath = filename;
|
||||||
|
|
||||||
RomName = Path::GetFileNameFromPath(romPath);
|
RomName = Path::GetFileNameFromPath(romPath);
|
||||||
|
RomName = Path::ScrubInvalid(RomName);
|
||||||
RomDirectory = Path::GetFileDirectoryPath(romPath);
|
RomDirectory = Path::GetFileDirectoryPath(romPath);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue