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

Method ConvertToFile

pcsx2-qt/Settings/MemoryCardConvertWorker.cpp:36–100  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

34}
35
36bool MemoryCardConvertWorker::ConvertToFile(const std::string& srcFolderName, const std::string& destFileName, const MemoryCardFileType type)
37{
38 const std::string srcPath(Path::Combine(EmuFolders::MemoryCards, srcFolderName));
39 const std::string destPath(Path::Combine(EmuFolders::MemoryCards, destFileName));
40 size_t sizeInMB = 0;
41
42 switch (type)
43 {
44 case MemoryCardFileType::PS2_8MB:
45 sizeInMB = 8;
46 break;
47 case MemoryCardFileType::PS2_16MB:
48 sizeInMB = 16;
49 break;
50 case MemoryCardFileType::PS2_32MB:
51 sizeInMB = 32;
52 break;
53 case MemoryCardFileType::PS2_64MB:
54 sizeInMB = 64;
55 break;
56 default:
57 Console.Error("%s(%s, %s, %d) Received invalid MemoryCardFileType, aborting", __FUNCTION__, srcPath.c_str(), destPath.c_str(), type);
58 return false;
59 }
60
61 FolderMemoryCard sourceFolderMemoryCard;
62 Pcsx2Config::McdOptions config;
63 config.Enabled = true;
64 config.Type = MemoryCardType::Folder;
65 sourceFolderMemoryCard.Open(srcPath, config, (sizeInMB * 1024 * 1024) / FolderMemoryCard::ClusterSize, false, "");
66 const size_t capacity = sourceFolderMemoryCard.GetSizeInClusters() * FolderMemoryCard::ClusterSizeRaw;
67
68 std::vector<u8> sourceBuffer;
69 sourceBuffer.resize(capacity);
70 size_t address = 0;
71 this->SetProgressRange(capacity);
72 this->SetProgressValue(0);
73
74 while (address < capacity)
75 {
76 sourceFolderMemoryCard.Read(sourceBuffer.data() + address, address, FolderMemoryCard::PageSizeRaw);
77 address += FolderMemoryCard::PageSizeRaw;
78
79 // Only report progress every 16 pages. Substantially speeds up the conversion.
80 if (address % (FolderMemoryCard::PageSizeRaw * 16) == 0)
81 this->SetProgressValue(address);
82 }
83
84 bool writeResult = FileSystem::WriteBinaryFile(destPath.c_str(), sourceBuffer.data(), sourceBuffer.size());
85
86 if (!writeResult)
87 {
88 Console.Error("%s(%s, %s, %d) Failed to write Memory Card contents to file", __FUNCTION__, srcPath.c_str(), destPath.c_str(), type);
89 return false;
90 }
91#ifdef _WIN32
92 else
93 {

Callers

nothing calls this directly

Calls 12

CombineFunction · 0.85
GetSizeInClustersMethod · 0.80
ErrorMethod · 0.45
c_strMethod · 0.45
OpenMethod · 0.45
resizeMethod · 0.45
SetProgressRangeMethod · 0.45
SetProgressValueMethod · 0.45
ReadMethod · 0.45
dataMethod · 0.45
sizeMethod · 0.45
CloseMethod · 0.45

Tested by

no test coverage detected