| 100 | } |
| 101 | |
| 102 | bool MemoryCardConvertWorker::ConvertToFolder(const std::string& srcFileName, const std::string& destFolderName, const MemoryCardFileType type) |
| 103 | { |
| 104 | const std::string srcPath(Path::Combine(EmuFolders::MemoryCards, srcFileName)); |
| 105 | const std::string destPath(Path::Combine(EmuFolders::MemoryCards, destFolderName)); |
| 106 | |
| 107 | FolderMemoryCard targetFolderMemoryCard; |
| 108 | Pcsx2Config::McdOptions config; |
| 109 | config.Enabled = true; |
| 110 | config.Type = MemoryCardType::Folder; |
| 111 | |
| 112 | std::optional<std::vector<u8>> sourceBufferOpt = FileSystem::ReadBinaryFile(srcPath.c_str()); |
| 113 | |
| 114 | if (!sourceBufferOpt.has_value()) |
| 115 | { |
| 116 | Console.Error("%s(%s, %s, %d) Failed to open file Memory Card!", __FUNCTION__, srcFileName.c_str(), destFolderName.c_str(), type); |
| 117 | return false; |
| 118 | } |
| 119 | |
| 120 | std::vector<u8> sourceBuffer = sourceBufferOpt.value(); |
| 121 | // Set progress bar to the literal number of bytes in the memcard. |
| 122 | // Plus two because there is a lag period after the Save calls complete |
| 123 | // where the progress bar stalls out; this lets us stop the progress bar |
| 124 | // just shy of 50 and 100% so it seems like it's still doing some work. |
| 125 | this->SetProgressRange((sourceBuffer.size() * 2) + 2); |
| 126 | this->SetProgressValue(0); |
| 127 | |
| 128 | // Attempt the write twice. Once with writes being simulated rather than truly committed. |
| 129 | // Again with actual writes. If a file memcard has a corrupted page or something which would |
| 130 | // cause the conversion to fail, it will fail on the simulated run, with no files committed |
| 131 | // to the filesystem yet. |
| 132 | for (int i = 0; i < 2; i++) |
| 133 | { |
| 134 | bool simulateWrites = (i == 0); |
| 135 | targetFolderMemoryCard.Open(destPath, config, 0, false, "", simulateWrites); |
| 136 | |
| 137 | size_t address = 0; |
| 138 | |
| 139 | while (address < sourceBuffer.size()) |
| 140 | { |
| 141 | targetFolderMemoryCard.Save(sourceBuffer.data() + address, address, FolderMemoryCard::PageSizeRaw); |
| 142 | address += FolderMemoryCard::PageSizeRaw; |
| 143 | |
| 144 | // Only report progress every 16 pages. Substantially speeds up the conversion. |
| 145 | if (address % (FolderMemoryCard::PageSizeRaw * 16) == 0) |
| 146 | this->SetProgressValue(address + (i * sourceBuffer.size())); |
| 147 | } |
| 148 | |
| 149 | targetFolderMemoryCard.Close(); |
| 150 | |
| 151 | // If the source file Memory Card was larger than 8 MB, the raw copy will have also made the superblock of |
| 152 | // the destination folder Memory Card larger than 8 MB. For compatibility, we always want folder Memory Cards |
| 153 | // to report 8 MB, so we'll override that here. Don't do this on the simulated run, only the actual. |
| 154 | if (!simulateWrites && sourceBuffer.size() != FolderMemoryCard::TotalSizeRaw) |
| 155 | { |
| 156 | targetFolderMemoryCard.Open(destPath, config, 0, false, "", simulateWrites); |
| 157 | targetFolderMemoryCard.SetSizeInMB(8); |
| 158 | targetFolderMemoryCard.Close(); |
| 159 | } |
nothing calls this directly
no test coverage detected