Merge pull request #701 from LPFaint99/memcard
GCI Folder: try to reserve space for new saves from the current game
This commit is contained in:
commit
3d88dfbad9
|
@ -4,6 +4,7 @@
|
||||||
#include <cinttypes>
|
#include <cinttypes>
|
||||||
|
|
||||||
#include "Common/CommonTypes.h"
|
#include "Common/CommonTypes.h"
|
||||||
|
#include "Common/FileSearch.h"
|
||||||
#include "Core/ConfigManager.h"
|
#include "Core/ConfigManager.h"
|
||||||
#include "Core/Core.h"
|
#include "Core/Core.h"
|
||||||
#include "Core/HW/GCMemcardDirectory.h"
|
#include "Core/HW/GCMemcardDirectory.h"
|
||||||
|
@ -12,7 +13,7 @@
|
||||||
const int NO_INDEX = -1;
|
const int NO_INDEX = -1;
|
||||||
static const char *MC_HDR = "MC_SYSTEM_AREA";
|
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");
|
File::IOFile gcifile(fileName, "rb");
|
||||||
if (gcifile)
|
if (gcifile)
|
||||||
|
@ -89,6 +90,23 @@ int GCMemcardDirectory::LoadGCI(std::string fileName, DiscIO::IVolume::ECountry
|
||||||
{
|
{
|
||||||
gci.LoadSaveBlocks();
|
gci.LoadSaveBlocks();
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
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);
|
u16 first_block = m_bat1.AssignBlocksContiguous(numBlocks);
|
||||||
if (first_block == 0xFFFF)
|
if (first_block == 0xFFFF)
|
||||||
{
|
{
|
||||||
|
@ -131,12 +149,24 @@ GCMemcardDirectory::GCMemcardDirectory(std::string directory, int slot, u16 size
|
||||||
|
|
||||||
File::FSTEntry FST_Temp;
|
File::FSTEntry FST_Temp;
|
||||||
File::ScanDirectoryTree(m_SaveDirectory, 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;
|
Core::DisplayMessage(
|
||||||
std::string const &name = FST_Temp.children[j].virtualName;
|
StringFromFormat("WARNING: There are more than 112 save files on this memorycards"\
|
||||||
SplitPath(name, nullptr, nullptr, &ext);
|
"\n Only loading the first 112 in the folder, unless the gameid is the current games id"),
|
||||||
if (strcasecmp(ext.c_str(), ".gci") == 0)
|
4000);
|
||||||
|
}
|
||||||
|
|
||||||
|
for (auto gciFile : rFilenames)
|
||||||
{
|
{
|
||||||
if (m_saves.size() == DIRLEN)
|
if (m_saves.size() == DIRLEN)
|
||||||
{
|
{
|
||||||
|
@ -144,13 +174,14 @@ GCMemcardDirectory::GCMemcardDirectory(std::string directory, int slot, u16 size
|
||||||
m_SaveDirectory.c_str());
|
m_SaveDirectory.c_str());
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
int index = LoadGCI(FST_Temp.children[j].physicalName, card_region);
|
int index = LoadGCI(gciFile, card_region, m_saves.size() > 112 );
|
||||||
if (index != NO_INDEX)
|
if (index != NO_INDEX)
|
||||||
{
|
{
|
||||||
m_loaded_saves.push_back(m_saves.at(index).m_gci_header.GCI_FileName());
|
m_loaded_saves.push_back(m_saves.at(index).m_gci_header.GCI_FileName());
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
m_loaded_saves.clear();
|
m_loaded_saves.clear();
|
||||||
m_dir1.fixChecksums();
|
m_dir1.fixChecksums();
|
||||||
m_dir2 = m_dir1;
|
m_dir2 = m_dir1;
|
||||||
|
|
|
@ -25,7 +25,7 @@ public:
|
||||||
void DoState(PointerWrap &p) override;
|
void DoState(PointerWrap &p) override;
|
||||||
|
|
||||||
private:
|
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);
|
inline s32 SaveAreaRW(u32 block, bool writing = false);
|
||||||
// s32 DirectoryRead(u32 offset, u32 length, u8* destaddress);
|
// s32 DirectoryRead(u32 offset, u32 length, u8* destaddress);
|
||||||
s32 DirectoryWrite(u32 destaddress, u32 length, u8 *srcaddress);
|
s32 DirectoryWrite(u32 destaddress, u32 length, u8 *srcaddress);
|
||||||
|
|
Loading…
Reference in New Issue