mirror of https://github.com/PCSX2/pcsx2.git
Folder memcards: Write the file index from FlushFileEntries
Resolves issues with flushes being performed out of order, breaking the intended order of files in the file dictionary
This commit is contained in:
parent
f8f783737d
commit
c7ad748e98
|
@ -985,70 +985,79 @@ void FolderMemoryCard::FlushFileEntries( const u32 dirCluster, const u32 remaini
|
||||||
const u32 filesInThisCluster = std::min( remainingFiles, 2u );
|
const u32 filesInThisCluster = std::min( remainingFiles, 2u );
|
||||||
for ( unsigned int i = 0; i < filesInThisCluster; ++i ) {
|
for ( unsigned int i = 0; i < filesInThisCluster; ++i ) {
|
||||||
MemoryCardFileEntry* entry = &entries->entries[i];
|
MemoryCardFileEntry* entry = &entries->entries[i];
|
||||||
if ( entry->IsValid() && entry->IsUsed() && entry->IsDir() ) {
|
if ( entry->IsValid() && entry->IsUsed() )
|
||||||
if ( !entry->IsDotDir() ) {
|
{
|
||||||
char cleanName[sizeof( entry->entry.data.name )];
|
if ( entry->IsDir() )
|
||||||
memcpy( cleanName, (const char*)entry->entry.data.name, sizeof( cleanName ) );
|
{
|
||||||
bool filenameCleaned = FileAccessHelper::CleanMemcardFilename( cleanName );
|
if ( !entry->IsDotDir() ) {
|
||||||
const wxString subDirName = wxString::FromAscii( (const char*)cleanName );
|
char cleanName[sizeof( entry->entry.data.name )];
|
||||||
const wxString subDirPath = dirPath + L"/" + subDirName;
|
memcpy( cleanName, (const char*)entry->entry.data.name, sizeof( cleanName ) );
|
||||||
|
bool filenameCleaned = FileAccessHelper::CleanMemcardFilename( cleanName );
|
||||||
|
const wxString subDirName = wxString::FromAscii( (const char*)cleanName );
|
||||||
|
const wxString subDirPath = dirPath + L"/" + subDirName;
|
||||||
|
|
||||||
if ( m_performFileWrites ) {
|
if ( m_performFileWrites ) {
|
||||||
// if this directory has nonstandard metadata, write that to the file system
|
// if this directory has nonstandard metadata, write that to the file system
|
||||||
wxFileName metaFileName( m_folderName.GetFullPath() + subDirPath, L"_pcsx2_meta_directory" );
|
wxFileName metaFileName( m_folderName.GetFullPath() + subDirPath, L"_pcsx2_meta_directory" );
|
||||||
if ( !metaFileName.DirExists() ) {
|
if ( !metaFileName.DirExists() ) {
|
||||||
metaFileName.Mkdir();
|
metaFileName.Mkdir();
|
||||||
}
|
|
||||||
|
|
||||||
if ( filenameCleaned || entry->entry.data.mode != MemoryCardFileEntry::DefaultDirMode || entry->entry.data.attr != 0 ) {
|
|
||||||
wxFFile metaFile( metaFileName.GetFullPath(), L"wb" );
|
|
||||||
if ( metaFile.IsOpened() ) {
|
|
||||||
metaFile.Write( entry->entry.raw, sizeof( entry->entry.raw ) );
|
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
// if metadata is standard make sure to remove a possibly existing metadata file
|
if ( filenameCleaned || entry->entry.data.mode != MemoryCardFileEntry::DefaultDirMode || entry->entry.data.attr != 0 ) {
|
||||||
if ( metaFileName.FileExists() ) {
|
wxFFile metaFile( metaFileName.GetFullPath(), L"wb" );
|
||||||
wxRemoveFile( metaFileName.GetFullPath() );
|
if ( metaFile.IsOpened() ) {
|
||||||
|
metaFile.Write( entry->entry.raw, sizeof( entry->entry.raw ) );
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// if metadata is standard make sure to remove a possibly existing metadata file
|
||||||
|
if ( metaFileName.FileExists() ) {
|
||||||
|
wxRemoveFile( metaFileName.GetFullPath() );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// write the directory index
|
||||||
|
metaFileName.SetName( L"_pcsx2_index" );
|
||||||
|
YAML::Node index = LoadYAMLFromFile( metaFileName.GetFullPath() );
|
||||||
|
YAML::Node entryNode = index[ "%ROOT" ];
|
||||||
|
|
||||||
|
entryNode["timeCreated"] = entry->entry.data.timeCreated.ToTime();
|
||||||
|
entryNode["timeModified"] = entry->entry.data.timeModified.ToTime();
|
||||||
|
|
||||||
|
// Write out the changes
|
||||||
|
wxFFile indexFile;
|
||||||
|
if ( indexFile.Open( metaFileName.GetFullPath(), L"w" ) ) {
|
||||||
|
indexFile.Write( YAML::Dump( index ) );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// write the directory index
|
MemoryCardFileMetadataReference* dirRef = AddDirEntryToMetadataQuickAccess( entry, parent );
|
||||||
metaFileName.SetName( L"_pcsx2_index" );
|
|
||||||
YAML::Node index = LoadYAMLFromFile( metaFileName.GetFullPath() );
|
|
||||||
YAML::Node entryNode = index[ "%ROOT" ];
|
|
||||||
|
|
||||||
entryNode["timeCreated"] = entry->entry.data.timeCreated.ToTime();
|
FlushFileEntries( entry->entry.data.cluster, entry->entry.data.length, subDirPath, dirRef );
|
||||||
entryNode["timeModified"] = entry->entry.data.timeModified.ToTime();
|
}
|
||||||
|
} else if ( entry->IsFile() ) {
|
||||||
|
const MemoryCardFileMetadataReference* fileRef = AddFileEntryToMetadataQuickAccess( entry, parent );
|
||||||
|
|
||||||
// Write out the changes
|
if ( entry->entry.data.length == 0 ) {
|
||||||
wxFFile indexFile;
|
// empty files need to be explicitly created, as there will be no data cluster referencing it later
|
||||||
if ( indexFile.Open( metaFileName.GetFullPath(), L"w" ) ) {
|
if ( m_performFileWrites ) {
|
||||||
indexFile.Write( YAML::Dump( index ) );
|
char cleanName[sizeof( entry->entry.data.name )];
|
||||||
|
memcpy( cleanName, (const char*)entry->entry.data.name, sizeof( cleanName ) );
|
||||||
|
FileAccessHelper::CleanMemcardFilename( cleanName );
|
||||||
|
const wxString filePath = dirPath + L"/" + wxString::FromAscii( (const char*)cleanName );
|
||||||
|
wxFileName fn( m_folderName.GetFullPath() + filePath );
|
||||||
|
|
||||||
|
if ( !fn.FileExists() ) {
|
||||||
|
if ( !fn.DirExists() ) {
|
||||||
|
fn.Mkdir( 0777, wxPATH_MKDIR_FULL );
|
||||||
|
}
|
||||||
|
wxFFile createEmptyFile( fn.GetFullPath(), L"wb" );
|
||||||
|
createEmptyFile.Close();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
MemoryCardFileMetadataReference* dirRef = AddDirEntryToMetadataQuickAccess( entry, parent );
|
|
||||||
|
|
||||||
FlushFileEntries( entry->entry.data.cluster, entry->entry.data.length, subDirPath, dirRef );
|
|
||||||
}
|
|
||||||
} else if ( entry->IsValid() && entry->IsUsed() && entry->IsFile() ) {
|
|
||||||
AddFileEntryToMetadataQuickAccess( entry, parent );
|
|
||||||
if ( entry->entry.data.length == 0 ) {
|
|
||||||
// empty files need to be explicitly created, as there will be no data cluster referencing it later
|
|
||||||
char cleanName[sizeof( entry->entry.data.name )];
|
|
||||||
memcpy( cleanName, (const char*)entry->entry.data.name, sizeof( cleanName ) );
|
|
||||||
FileAccessHelper::CleanMemcardFilename( cleanName );
|
|
||||||
const wxString filePath = dirPath + L"/" + wxString::FromAscii( (const char*)cleanName );
|
|
||||||
|
|
||||||
if ( m_performFileWrites ) {
|
if ( m_performFileWrites ) {
|
||||||
wxFileName fn( m_folderName.GetFullPath() + filePath );
|
FileAccessHelper::WriteIndex( m_folderName.GetFullPath() + dirPath, fileRef );
|
||||||
if ( !fn.FileExists() ) {
|
|
||||||
if ( !fn.DirExists() ) {
|
|
||||||
fn.Mkdir( 0777, wxPATH_MKDIR_FULL );
|
|
||||||
}
|
|
||||||
wxFFile createEmptyFile( fn.GetFullPath(), L"wb" );
|
|
||||||
createEmptyFile.Close();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1515,7 +1524,6 @@ wxFFile* FileAccessHelper::Open( const wxFileName& folderName, MemoryCardFileMet
|
||||||
|
|
||||||
if ( writeMetadata ) {
|
if ( writeMetadata ) {
|
||||||
WriteMetadata( folderName, fileRef );
|
WriteMetadata( folderName, fileRef );
|
||||||
WriteIndex( folderName, fileRef );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return file;
|
return file;
|
||||||
|
@ -1594,7 +1602,6 @@ wxFFile* FileAccessHelper::ReOpen( const wxFileName& folderName, MemoryCardFileM
|
||||||
if ( writeMetadata ) {
|
if ( writeMetadata ) {
|
||||||
if ( m_lastWrittenFileRef != fileRef ) {
|
if ( m_lastWrittenFileRef != fileRef ) {
|
||||||
WriteMetadata( folderName, fileRef );
|
WriteMetadata( folderName, fileRef );
|
||||||
WriteIndex( folderName, fileRef );
|
|
||||||
m_lastWrittenFileRef = fileRef;
|
m_lastWrittenFileRef = fileRef;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -246,6 +246,8 @@ public:
|
||||||
// returns true if any changes were made
|
// returns true if any changes were made
|
||||||
static bool CleanMemcardFilename( char* name );
|
static bool CleanMemcardFilename( char* name );
|
||||||
|
|
||||||
|
static void WriteIndex( wxFileName folderName, const MemoryCardFileMetadataReference* fileRef );
|
||||||
|
|
||||||
private:
|
private:
|
||||||
// helper function for CleanMemcardFilename()
|
// helper function for CleanMemcardFilename()
|
||||||
static bool CleanMemcardFilenameEndDotOrSpace( char* name, size_t length );
|
static bool CleanMemcardFilenameEndDotOrSpace( char* name, size_t length );
|
||||||
|
@ -257,7 +259,6 @@ private:
|
||||||
void CloseFileHandle( wxFFile* file, const MemoryCardFileEntry* entry = nullptr );
|
void CloseFileHandle( wxFFile* file, const MemoryCardFileEntry* entry = nullptr );
|
||||||
|
|
||||||
void WriteMetadata( wxFileName folderName, const MemoryCardFileMetadataReference* fileRef );
|
void WriteMetadata( wxFileName folderName, const MemoryCardFileMetadataReference* fileRef );
|
||||||
void WriteIndex( wxFileName folderName, const MemoryCardFileMetadataReference* fileRef );
|
|
||||||
};
|
};
|
||||||
|
|
||||||
// --------------------------------------------------------------------------------------
|
// --------------------------------------------------------------------------------------
|
||||||
|
|
Loading…
Reference in New Issue