From f6d89c5c988f3d70c1acfbe55518e05d80382821 Mon Sep 17 00:00:00 2001 From: LPFaint99 Date: Tue, 29 Jul 2014 21:30:58 -0700 Subject: [PATCH 1/2] GCI Folder: if there are too many files in the folder, try to leave free directory entries. Rule: Load first 112 files, any remaining files in the folder are ignored unless they are the same gameid as the current game --- Source/Core/Core/HW/GCMemcardDirectory.cpp | 70 ++++++++++++++-------- Source/Core/Core/HW/GCMemcardDirectory.h | 2 +- 2 files changed, 45 insertions(+), 27 deletions(-) diff --git a/Source/Core/Core/HW/GCMemcardDirectory.cpp b/Source/Core/Core/HW/GCMemcardDirectory.cpp index 5e15056282..0aef9cf8cb 100644 --- a/Source/Core/Core/HW/GCMemcardDirectory.cpp +++ b/Source/Core/Core/HW/GCMemcardDirectory.cpp @@ -4,6 +4,7 @@ #include #include "Common/CommonTypes.h" +#include "Common/FileSearch.h" #include "Core/ConfigManager.h" #include "Core/Core.h" #include "Core/HW/GCMemcardDirectory.h" @@ -12,7 +13,7 @@ const int NO_INDEX = -1; static const char *MC_HDR = "MC_SYSTEM_AREA"; -int GCMemcardDirectory::LoadGCI(std::string fileName, DiscIO::IVolume::ECountry card_region) +int GCMemcardDirectory::LoadGCI(std::string fileName, DiscIO::IVolume::ECountry card_region, bool currentGameOnly) { File::IOFile gcifile(fileName, "rb"); if (gcifile) @@ -89,6 +90,10 @@ int GCMemcardDirectory::LoadGCI(std::string fileName, DiscIO::IVolume::ECountry { gci.LoadSaveBlocks(); } + else if (currentGameOnly) + { + return NO_INDEX; + } u16 first_block = m_bat1.AssignBlocksContiguous(numBlocks); if (first_block == 0xFFFF) { @@ -114,13 +119,13 @@ int GCMemcardDirectory::LoadGCI(std::string fileName, DiscIO::IVolume::ECountry } GCMemcardDirectory::GCMemcardDirectory(std::string directory, int slot, u16 sizeMb, bool ascii, DiscIO::IVolume::ECountry card_region, int gameId) - : MemoryCardBase(slot, sizeMb) - , m_GameId(gameId) - , m_LastBlock(-1) - , m_hdr(slot, sizeMb, ascii) - , m_bat1(sizeMb) - , m_saves(0) - , m_SaveDirectory(directory) +: MemoryCardBase(slot, sizeMb) +, m_GameId(gameId) +, m_LastBlock(-1) +, m_hdr(slot, sizeMb, ascii) +, m_bat1(sizeMb) +, m_saves(0) +, m_SaveDirectory(directory) { // Use existing header data if available if (File::Exists(m_SaveDirectory + MC_HDR)) @@ -131,26 +136,39 @@ GCMemcardDirectory::GCMemcardDirectory(std::string directory, int slot, u16 size File::FSTEntry FST_Temp; File::ScanDirectoryTree(m_SaveDirectory, FST_Temp); - for (u32 j = 0; j < FST_Temp.children.size(); j++) + + CFileSearch::XStringVector Directory; + Directory.push_back(m_SaveDirectory); + CFileSearch::XStringVector Extensions; + Extensions.push_back("*.gci"); + + CFileSearch FileSearch(Extensions, Directory); + const CFileSearch::XStringVector& rFilenames = FileSearch.GetFileNames(); + + if (rFilenames.size() > 112) { - std::string ext; - std::string const &name = FST_Temp.children[j].virtualName; - SplitPath(name, nullptr, nullptr, &ext); - if (strcasecmp(ext.c_str(), ".gci") == 0) - { - if (m_saves.size() == DIRLEN) - { - PanicAlertT("There are too many gci files in the folder\n%s\nOnly the first 127 will be available", - m_SaveDirectory.c_str()); - break; - } - int index = LoadGCI(FST_Temp.children[j].physicalName, card_region); - if (index != NO_INDEX) - { - m_loaded_saves.push_back(m_saves.at(index).m_gci_header.GCI_FileName()); - } - } + Core::DisplayMessage( + StringFromFormat("WARNING: There are more than 112 save files on this memorycards"\ + "\n Only loading the first 112 in the folder, unless the gameid is the current games id"), + 4000); } + + for (auto gciFile : rFilenames) + { + if (m_saves.size() == DIRLEN) + { + PanicAlertT("There are too many gci files in the folder\n%s\nOnly the first 127 will be available", + m_SaveDirectory.c_str()); + break; + } + int index = LoadGCI(gciFile, card_region, m_saves.size() > 112 ); + if (index != NO_INDEX) + { + m_loaded_saves.push_back(m_saves.at(index).m_gci_header.GCI_FileName()); + } + + } + m_loaded_saves.clear(); m_dir1.fixChecksums(); m_dir2 = m_dir1; diff --git a/Source/Core/Core/HW/GCMemcardDirectory.h b/Source/Core/Core/HW/GCMemcardDirectory.h index e4e03c6530..7d2154ac43 100644 --- a/Source/Core/Core/HW/GCMemcardDirectory.h +++ b/Source/Core/Core/HW/GCMemcardDirectory.h @@ -25,7 +25,7 @@ public: void DoState(PointerWrap &p) override; private: - int LoadGCI(std::string fileName, DiscIO::IVolume::ECountry card_region); + int LoadGCI(std::string fileName, DiscIO::IVolume::ECountry card_region, bool currentGameOnly); inline s32 SaveAreaRW(u32 block, bool writing = false); // s32 DirectoryRead(u32 offset, u32 length, u8* destaddress); s32 DirectoryWrite(u32 destaddress, u32 length, u8 *srcaddress); From e6e50ee62191de9e7d234871730e99d0fd5fda5a Mon Sep 17 00:00:00 2001 From: LPFaint99 Date: Tue, 29 Jul 2014 21:42:57 -0700 Subject: [PATCH 2/2] GCI Folder: try to leave 10% of the blocks free. only applies if the save is not for the current game --- Source/Core/Core/HW/GCMemcardDirectory.cpp | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/Source/Core/Core/HW/GCMemcardDirectory.cpp b/Source/Core/Core/HW/GCMemcardDirectory.cpp index 0aef9cf8cb..0ac4199a82 100644 --- a/Source/Core/Core/HW/GCMemcardDirectory.cpp +++ b/Source/Core/Core/HW/GCMemcardDirectory.cpp @@ -90,9 +90,22 @@ int GCMemcardDirectory::LoadGCI(std::string fileName, DiscIO::IVolume::ECountry { gci.LoadSaveBlocks(); } - else if (currentGameOnly) + else { - return NO_INDEX; + if (currentGameOnly) + { + return NO_INDEX; + } + int totalBlocks = BE16(m_hdr.SizeMb)*MBIT_TO_BLOCKS - MC_FST_BLOCKS; + int freeBlocks = BE16(m_bat1.FreeBlocks); + if (totalBlocks > freeBlocks * 10) + { + + PanicAlertT("%s\nwas not loaded because there is less than 10%% free space on the memorycard\n"\ + "Total Blocks: %d; Free Blocks: %d", + gci.m_filename.c_str(), totalBlocks, freeBlocks); + return NO_INDEX; + } } u16 first_block = m_bat1.AssignBlocksContiguous(numBlocks); if (first_block == 0xFFFF)