Folder Memory Card: Detect and handle filenames that end in dots and/or spaces.

This commit is contained in:
Admiral H. Curtiss 2016-01-25 23:12:08 +01:00
parent df356694c5
commit 326d50b686
2 changed files with 24 additions and 2 deletions

View File

@ -1530,9 +1530,9 @@ bool FileAccessHelper::CleanMemcardFilename( char* name ) {
const char illegalChars[] = { '\\', '%', ':', '|', '"', '<', '>' };
bool cleaned = false;
const size_t filenameLength = strlen( name );
for ( size_t i = 0; i < sizeof( illegalChars ); ++i ) {
// this sizeof looks really odd but I couldn't get MemoryCardFileEntry::entry.data.name (or variants) working, feel free to replace with something equivalent but nicer looking
for ( size_t j = 0; j < sizeof( ( (MemoryCardFileEntry*)0 )->entry.data.name ); ++j ) {
for ( size_t j = 0; j < filenameLength; ++j ) {
if ( name[j] == illegalChars[i] ) {
name[j] = '_';
cleaned = true;
@ -1540,9 +1540,28 @@ bool FileAccessHelper::CleanMemcardFilename( char* name ) {
}
}
cleaned = CleanMemcardFilenameEndDotOrSpace( name, filenameLength ) || cleaned;
return cleaned;
}
bool FileAccessHelper::CleanMemcardFilenameEndDotOrSpace( char* name, size_t length ) {
// Windows truncates dots and spaces at the end of filenames, so make sure that doesn't happen
bool cleaned = false;
for ( size_t j = length; j > 0; --j ) {
switch ( name[j - 1] ) {
case ' ':
case '.':
name[j - 1] = '_';
cleaned = true;
break;
default:
return cleaned;
}
}
return cleaned;
}
bool MemoryCardFileMetadataReference::GetPath( wxFileName* fileName ) const {
bool parentCleaned = false;

View File

@ -237,6 +237,9 @@ public:
static bool CleanMemcardFilename( char* name );
protected:
// helper function for CleanMemcardFilename()
static bool CleanMemcardFilenameEndDotOrSpace( char* name, size_t length );
// Open a new file and remember it for later
wxFFile* Open( const wxFileName& folderName, MemoryCardFileMetadataReference* fileRef, bool writeMetadata = false );
// Close a file and delete its handle