| 1710 | } |
| 1711 | |
| 1712 | void FolderMemoryCard::AttemptToRecreateIndexFile(const std::string& directory) const |
| 1713 | { |
| 1714 | // Attempt to fix broken index files (potentially broken in v1.7.2115, fixed in 1.7.2307 |
| 1715 | Console.Error(fmt::format("[Memcard] Folder memory card index file is malformed, backing up and attempting to re-create. This may not work for all games (ie. GTA), so backing up the current index file!. '{}'", |
| 1716 | directory)); |
| 1717 | |
| 1718 | // This isn't full-proof, so we backup the broken index file |
| 1719 | FileSystem::CopyFilePath(Path::Combine(directory, "_pcsx2_index").c_str(), |
| 1720 | Path::Combine(directory, "_pcsx2_index.invalid.bak").c_str(), true); |
| 1721 | |
| 1722 | // Create everything relative to a point in time, with an artifical delay to minimize edge-cases |
| 1723 | auto currTime = std::time(nullptr) - 1000; |
| 1724 | auto currOrder = 1; |
| 1725 | ryml::Tree tree; |
| 1726 | ryml::NodeRef root = tree.rootref(); |
| 1727 | root |= ryml::MAP; |
| 1728 | root.append_child() << ryml::key("$ROOT") |= ryml::MAP; |
| 1729 | root["$ROOT"]["timeCreated"] << currTime++; |
| 1730 | |
| 1731 | FileSystem::FindResultsArray results; |
| 1732 | FileSystem::FindFiles(directory.c_str(), "*", FILESYSTEM_FIND_FILES | FILESYSTEM_FIND_RELATIVE_PATHS | FILESYSTEM_FIND_HIDDEN_FILES, &results); |
| 1733 | for (const FILESYSTEM_FIND_DATA& fd : results) |
| 1734 | { |
| 1735 | if (fd.FileName.rfind("_pcsx2_", 0) == 0) |
| 1736 | { |
| 1737 | continue; |
| 1738 | } |
| 1739 | |
| 1740 | root.append_child() << ryml::key(fd.FileName) |= ryml::MAP; |
| 1741 | ryml::NodeRef newNode = root[ryml::to_csubstr(fd.FileName)]; |
| 1742 | newNode["order"] << currOrder++; |
| 1743 | newNode["timeCreated"] << currTime++; |
| 1744 | newNode["timeModified"] << currTime++; |
| 1745 | } |
| 1746 | |
| 1747 | root["$ROOT"]["timeModified"] << currTime; |
| 1748 | |
| 1749 | auto file = FileSystem::OpenManagedCFile(Path::Combine(directory, "_pcsx2_index").c_str(), "w"); |
| 1750 | if (file) |
| 1751 | ryml::emit_yaml(tree, file.get()); |
| 1752 | } |
| 1753 | |
| 1754 | std::string FolderMemoryCard::GetDisabledMessage(uint slot) const |
| 1755 | { |