MCPcopy Create free account
hub / github.com/PCSX2/pcsx2 / Flush

Method Flush

pcsx2/SIO/Memcard/MemoryCardFolder.cpp:1069–1153  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1067}
1068
1069void FolderMemoryCard::Flush()
1070{
1071 if (m_cache.empty())
1072 {
1073 return;
1074 }
1075
1076#ifdef DEBUG_WRITE_FOLDER_CARD_IN_MEMORY_TO_FILE_ON_CHANGE
1077 WriteToFile(m_folderName.GetFullPath().RemoveLast() + L"-debug_" + wxDateTime::Now().Format(L"%Y-%m-%d-%H-%M-%S") + L"_pre-flush.ps2");
1078#endif
1079
1080 Console.WriteLn("FolderMcd: Writing data for slot %u to file system...", m_slot);
1081 Common::Timer timeFlushStart;
1082
1083 // Keep a copy of the old file entries so we can figure out which files and directories, if any, have been deleted from the memory card.
1084 std::vector<MemoryCardFileEntryTreeNode> oldFileEntryTree;
1085 if (IsFormatted())
1086 {
1087 CopyEntryDictIntoTree(&oldFileEntryTree, m_superBlock.data.rootdir_cluster, m_fileEntryDict[m_superBlock.data.rootdir_cluster].entries[0].entry.data.length);
1088 }
1089
1090 // first write the superblock if necessary
1091 FlushSuperBlock();
1092 if (!IsFormatted())
1093 {
1094 return;
1095 }
1096
1097 // check if we were interrupted in the middle of a save operation, if yes abort
1098 FlushBlock(m_superBlock.data.backup_block1);
1099 FlushBlock(m_superBlock.data.backup_block2);
1100 if (m_backupBlock2.programmedBlock != 0xFFFFFFFFu)
1101 {
1102 Console.Warning("FolderMcd: Aborting flush of slot %u, emulation was interrupted during save process!", m_slot);
1103 return;
1104 }
1105
1106 const u32 clusterCount = GetSizeInClusters();
1107 const u32 pageCount = clusterCount * 2;
1108
1109 // then write the indirect FAT
1110 for (int i = 0; i < IndirectFatClusterCount; ++i)
1111 {
1112 const u32 cluster = m_superBlock.data.ifc_list[i];
1113 if (cluster > 0 && cluster < clusterCount)
1114 {
1115 FlushCluster(cluster);
1116 }
1117 }
1118
1119 // and the FAT
1120 for (int i = 0; i < IndirectFatClusterCount; ++i)
1121 {
1122 for (int j = 0; j < ClusterSize / 4; ++j)
1123 {
1124 const u32 cluster = m_indirectFat.data[i][j];
1125 if (cluster > 0 && cluster < clusterCount)
1126 {

Callers

nothing calls this directly

Calls 8

FlushAllMethod · 0.80
GetTimeMillisecondsMethod · 0.80
emptyMethod · 0.45
FormatMethod · 0.45
WriteLnMethod · 0.45
WarningMethod · 0.45
clearMethod · 0.45

Tested by

no test coverage detected