mirror of https://github.com/PCSX2/pcsx2.git
Memcard: Track file size globally at open
Prevents FSeek64 hits on every retrieval of memcard attributes
This commit is contained in:
parent
77d5a04aa4
commit
333c7ef61b
|
@ -157,6 +157,7 @@ class FileMemoryCard
|
||||||
{
|
{
|
||||||
protected:
|
protected:
|
||||||
std::FILE* m_file[8] = {};
|
std::FILE* m_file[8] = {};
|
||||||
|
s64 m_fileSize[8] = {};
|
||||||
std::string m_filenames[8] = {};
|
std::string m_filenames[8] = {};
|
||||||
std::vector<u8> m_currentdata;
|
std::vector<u8> m_currentdata;
|
||||||
u64 m_chksum[8] = {};
|
u64 m_chksum[8] = {};
|
||||||
|
@ -246,7 +247,13 @@ std::string FileMcd_GetDefaultName(uint slot)
|
||||||
return StringUtil::StdStringFromFormat("Mcd%03u.ps2", slot + 1);
|
return StringUtil::StdStringFromFormat("Mcd%03u.ps2", slot + 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
FileMemoryCard::FileMemoryCard() = default;
|
FileMemoryCard::FileMemoryCard()
|
||||||
|
{
|
||||||
|
for (u8 slot = 0; slot < 8; slot++)
|
||||||
|
{
|
||||||
|
m_fileSize[slot] = -1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
FileMemoryCard::~FileMemoryCard() = default;
|
FileMemoryCard::~FileMemoryCard() = default;
|
||||||
|
|
||||||
|
@ -314,12 +321,14 @@ void FileMemoryCard::Open()
|
||||||
}
|
}
|
||||||
else // Load checksum
|
else // Load checksum
|
||||||
{
|
{
|
||||||
|
m_fileSize[slot] = FileSystem::FSize64(m_file[slot]);
|
||||||
|
|
||||||
Console.WriteLnFmt(Color_Green, "McdSlot {} [File]: {} [{} MB, {}]", slot, Path::GetFileName(fname),
|
Console.WriteLnFmt(Color_Green, "McdSlot {} [File]: {} [{} MB, {}]", slot, Path::GetFileName(fname),
|
||||||
(FileSystem::FSize64(m_file[slot]) + (MCD_SIZE + 1)) / MC2_MBSIZE,
|
(m_fileSize[slot] + (MCD_SIZE + 1)) / MC2_MBSIZE,
|
||||||
FileMcd_IsMemoryCardFormatted(m_file[slot]) ? "Formatted" : "UNFORMATTED");
|
FileMcd_IsMemoryCardFormatted(m_file[slot]) ? "Formatted" : "UNFORMATTED");
|
||||||
|
|
||||||
m_filenames[slot] = std::move(fname);
|
m_filenames[slot] = std::move(fname);
|
||||||
m_ispsx[slot] = FileSystem::FSize64(m_file[slot]) == 0x20000;
|
m_ispsx[slot] = m_fileSize[slot] == 0x20000;
|
||||||
m_chkaddr = 0x210;
|
m_chkaddr = 0x210;
|
||||||
|
|
||||||
if (!m_ispsx[slot] && FileSystem::FSeek64(m_file[slot], m_chkaddr, SEEK_SET) == 0)
|
if (!m_ispsx[slot] && FileSystem::FSeek64(m_file[slot], m_chkaddr, SEEK_SET) == 0)
|
||||||
|
@ -354,6 +363,7 @@ void FileMemoryCard::Close()
|
||||||
}
|
}
|
||||||
|
|
||||||
m_filenames[slot] = {};
|
m_filenames[slot] = {};
|
||||||
|
m_fileSize[slot] = -1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -398,7 +408,7 @@ void FileMemoryCard::GetSizeInfo(uint slot, McdSizeInfo& outways)
|
||||||
|
|
||||||
pxAssert(m_file[slot]);
|
pxAssert(m_file[slot]);
|
||||||
if (m_file[slot])
|
if (m_file[slot])
|
||||||
outways.McdSizeInSectors = static_cast<u32>(FileSystem::FSize64(m_file[slot])) / (outways.SectorSize + outways.EraseBlockSizeInSectors);
|
outways.McdSizeInSectors = static_cast<u32>(m_fileSize[slot]) / (outways.SectorSize + outways.EraseBlockSizeInSectors);
|
||||||
else
|
else
|
||||||
outways.McdSizeInSectors = 0x4000;
|
outways.McdSizeInSectors = 0x4000;
|
||||||
|
|
||||||
|
@ -525,7 +535,7 @@ u64 FileMemoryCard::GetCRC(uint slot)
|
||||||
if (!Seek(mcfp, 0))
|
if (!Seek(mcfp, 0))
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
const s64 mcfpsize = FileSystem::FSize64(mcfp);
|
const s64 mcfpsize = m_fileSize[slot];
|
||||||
if (mcfpsize < 0)
|
if (mcfpsize < 0)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue