mirror of https://github.com/PCSX2/pcsx2.git
CDVD: Purge MultpartFileReader
Nobody should be using this.
This commit is contained in:
parent
e8e84d160b
commit
431b8b0df6
|
@ -96,45 +96,6 @@ public:
|
||||||
void SetDataOffset(u32 bytes) override { m_dataoffset = bytes; }
|
void SetDataOffset(u32 bytes) override { m_dataoffset = bytes; }
|
||||||
};
|
};
|
||||||
|
|
||||||
class MultipartFileReader final : public AsyncFileReader
|
|
||||||
{
|
|
||||||
DeclareNoncopyableObject(MultipartFileReader);
|
|
||||||
|
|
||||||
static const int MaxParts = 8;
|
|
||||||
|
|
||||||
struct Part
|
|
||||||
{
|
|
||||||
u32 start;
|
|
||||||
u32 end; // exclusive
|
|
||||||
bool isReading;
|
|
||||||
AsyncFileReader* reader;
|
|
||||||
} m_parts[MaxParts];
|
|
||||||
u32 m_numparts;
|
|
||||||
|
|
||||||
u32 GetFirstPart(u32 lsn);
|
|
||||||
void FindParts();
|
|
||||||
|
|
||||||
public:
|
|
||||||
MultipartFileReader(AsyncFileReader* firstPart);
|
|
||||||
~MultipartFileReader() override;
|
|
||||||
|
|
||||||
bool Open(std::string filename, Error* error) override;
|
|
||||||
|
|
||||||
int ReadSync(void* pBuffer, u32 sector, u32 count) override;
|
|
||||||
|
|
||||||
void BeginRead(void* pBuffer, u32 sector, u32 count) override;
|
|
||||||
int FinishRead() override;
|
|
||||||
void CancelRead() override;
|
|
||||||
|
|
||||||
void Close() override;
|
|
||||||
|
|
||||||
u32 GetBlockCount() const override;
|
|
||||||
|
|
||||||
void SetBlockSize(u32 bytes) override;
|
|
||||||
|
|
||||||
static AsyncFileReader* DetectMultipart(AsyncFileReader* reader);
|
|
||||||
};
|
|
||||||
|
|
||||||
class BlockdumpFileReader : public AsyncFileReader
|
class BlockdumpFileReader : public AsyncFileReader
|
||||||
{
|
{
|
||||||
DeclareNoncopyableObject(BlockdumpFileReader);
|
DeclareNoncopyableObject(BlockdumpFileReader);
|
||||||
|
|
|
@ -251,9 +251,6 @@ bool InputIsoFile::Open(std::string srcfile, Error* error, bool testOnly)
|
||||||
|
|
||||||
m_reader->SetDataOffset(m_offset);
|
m_reader->SetDataOffset(m_offset);
|
||||||
m_reader->SetBlockSize(m_blocksize);
|
m_reader->SetBlockSize(m_blocksize);
|
||||||
|
|
||||||
// Returns the original reader if single-part or a Multipart reader otherwise
|
|
||||||
m_reader = MultipartFileReader::DetectMultipart(m_reader);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
m_blocks = m_reader->GetBlockCount();
|
m_blocks = m_reader->GetBlockCount();
|
||||||
|
|
|
@ -91,7 +91,6 @@ set(pcsx2Sources
|
||||||
MMI.cpp
|
MMI.cpp
|
||||||
MTGS.cpp
|
MTGS.cpp
|
||||||
MTVU.cpp
|
MTVU.cpp
|
||||||
MultipartFileReader.cpp
|
|
||||||
Patch.cpp
|
Patch.cpp
|
||||||
Pcsx2Config.cpp
|
Pcsx2Config.cpp
|
||||||
PerformanceMetrics.cpp
|
PerformanceMetrics.cpp
|
||||||
|
|
|
@ -1,247 +0,0 @@
|
||||||
// SPDX-FileCopyrightText: 2002-2023 PCSX2 Dev Team
|
|
||||||
// SPDX-License-Identifier: LGPL-3.0+
|
|
||||||
|
|
||||||
#include "AsyncFileReader.h"
|
|
||||||
|
|
||||||
#include "common/Assertions.h"
|
|
||||||
#include "common/Console.h"
|
|
||||||
#include "common/FileSystem.h"
|
|
||||||
#include "common/Error.h"
|
|
||||||
#include "common/Path.h"
|
|
||||||
#include "common/StringUtil.h"
|
|
||||||
|
|
||||||
// Tests for a filename extension in both upper and lower case, if the filesystem happens
|
|
||||||
// to be case-sensitive.
|
|
||||||
static bool pxFileExists_WithExt( std::string& filename, const std::string& ext )
|
|
||||||
{
|
|
||||||
std::string temp(Path::ReplaceExtension(filename, StringUtil::toLower(ext)));
|
|
||||||
if (FileSystem::FileExists(temp.c_str()))
|
|
||||||
return true;
|
|
||||||
|
|
||||||
#if defined(_WIN32) || defined(__DARWIN__)
|
|
||||||
temp = Path::ReplaceExtension(filename, StringUtil::toUpper(ext));
|
|
||||||
if (FileSystem::FileExists(temp.c_str()))
|
|
||||||
{
|
|
||||||
// make sure we open the correct one
|
|
||||||
filename = std::move(temp);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
AsyncFileReader* MultipartFileReader::DetectMultipart(AsyncFileReader* reader)
|
|
||||||
{
|
|
||||||
MultipartFileReader* multi = new MultipartFileReader(reader);
|
|
||||||
|
|
||||||
multi->FindParts();
|
|
||||||
if (multi->m_numparts > 1)
|
|
||||||
{
|
|
||||||
Console.WriteLn( Color_Blue, "isoFile: multi-part ISO detected. %u parts found.", multi->m_numparts);
|
|
||||||
|
|
||||||
return multi;
|
|
||||||
}
|
|
||||||
|
|
||||||
multi->m_parts[0].reader = NULL;
|
|
||||||
delete multi;
|
|
||||||
return reader;
|
|
||||||
}
|
|
||||||
|
|
||||||
MultipartFileReader::MultipartFileReader(AsyncFileReader* firstPart)
|
|
||||||
{
|
|
||||||
memset(m_parts,0,sizeof(m_parts));
|
|
||||||
|
|
||||||
m_filename = firstPart->GetFilename();
|
|
||||||
|
|
||||||
m_numparts = 1;
|
|
||||||
|
|
||||||
m_parts[0].reader = firstPart;
|
|
||||||
m_parts[0].end = firstPart->GetBlockCount();
|
|
||||||
}
|
|
||||||
|
|
||||||
MultipartFileReader::~MultipartFileReader(void)
|
|
||||||
{
|
|
||||||
Close();
|
|
||||||
}
|
|
||||||
|
|
||||||
void MultipartFileReader::FindParts()
|
|
||||||
{
|
|
||||||
std::string curext(Path::GetExtension(m_filename));
|
|
||||||
if (curext.empty())
|
|
||||||
return;
|
|
||||||
|
|
||||||
char prefixch = std::tolower(curext[0]);
|
|
||||||
|
|
||||||
// Multi-part rules!
|
|
||||||
// * The first part can either be the proper extension (ISO, MDF, etc) or the numerical
|
|
||||||
// extension (I00, I01, M00, M01, etc).
|
|
||||||
// * Numerical extensions MUST begin at 00 (I00 etc), regardless of if the first part
|
|
||||||
// is proper or numerical.
|
|
||||||
|
|
||||||
uint i = 0;
|
|
||||||
|
|
||||||
if ((curext.length() == 3) && (curext[1] == '0') && (curext[2] == '0'))
|
|
||||||
{
|
|
||||||
// First file is an OO, so skip 0 in the loop below:
|
|
||||||
i = 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
std::string extbuf(StringUtil::StdStringFromFormat("%c%02u", prefixch, i));
|
|
||||||
std::string nameparts(Path::ReplaceExtension(m_filename, extbuf));
|
|
||||||
if (!pxFileExists_WithExt(nameparts, extbuf))
|
|
||||||
return;
|
|
||||||
|
|
||||||
DevCon.WriteLn( Color_Blue, "isoFile: multi-part %s detected...", StringUtil::toUpper(curext).c_str() );
|
|
||||||
|
|
||||||
int bsize = m_parts[0].reader->GetBlockSize();
|
|
||||||
int blocks = m_parts[0].end;
|
|
||||||
|
|
||||||
m_numparts = 1;
|
|
||||||
|
|
||||||
for (; i < MaxParts; ++i)
|
|
||||||
{
|
|
||||||
extbuf = StringUtil::StdStringFromFormat("%c%02u", prefixch, i );
|
|
||||||
nameparts = Path::ReplaceExtension(m_filename, extbuf);
|
|
||||||
if (!pxFileExists_WithExt(nameparts, extbuf))
|
|
||||||
break;
|
|
||||||
|
|
||||||
Part* thispart = m_parts + m_numparts;
|
|
||||||
AsyncFileReader* thisreader = new FlatFileReader();
|
|
||||||
|
|
||||||
if (!thisreader->Open(nameparts, nullptr))
|
|
||||||
{
|
|
||||||
delete thisreader;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
thisreader->SetBlockSize(bsize);
|
|
||||||
|
|
||||||
thispart->reader = thisreader;
|
|
||||||
thispart->start = blocks;
|
|
||||||
|
|
||||||
uint bcount = thisreader->GetBlockCount();
|
|
||||||
blocks += bcount;
|
|
||||||
|
|
||||||
thispart->end = blocks;
|
|
||||||
|
|
||||||
DevCon.WriteLn( Color_Blue, "\tblocks %u - %u in: %s",
|
|
||||||
thispart->start, thispart->end,
|
|
||||||
nameparts.c_str()
|
|
||||||
);
|
|
||||||
|
|
||||||
++m_numparts;
|
|
||||||
}
|
|
||||||
|
|
||||||
//Console.WriteLn( Color_Blue, "isoFile: multi-part ISO loaded (%u parts found)", m_numparts );
|
|
||||||
}
|
|
||||||
|
|
||||||
bool MultipartFileReader::Open(std::string filename, Error* error)
|
|
||||||
{
|
|
||||||
Error::SetString(error, "Cannot open a MultipartFileReader directly.");
|
|
||||||
// Cannot open a MultipartFileReader directly,
|
|
||||||
// use DetectMultipart to convert a FlatFileReader
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
uint MultipartFileReader::GetFirstPart(uint lsn)
|
|
||||||
{
|
|
||||||
pxAssertMsg(lsn < GetBlockCount(), "Invalid lsn passed into MultipartFileReader::GetFirstPart.");
|
|
||||||
pxAssertMsg(m_numparts, "Invalid object state; multi-part iso file needs at least one part!");
|
|
||||||
|
|
||||||
for (uint i = 0; i < m_numparts; ++i)
|
|
||||||
{
|
|
||||||
if (lsn < m_parts[i].end)
|
|
||||||
return i;
|
|
||||||
}
|
|
||||||
|
|
||||||
// should never get here
|
|
||||||
return 0xBAAAAAAD;
|
|
||||||
}
|
|
||||||
|
|
||||||
int MultipartFileReader::ReadSync(void* pBuffer, uint sector, uint count)
|
|
||||||
{
|
|
||||||
BeginRead(pBuffer,sector,count);
|
|
||||||
return FinishRead();
|
|
||||||
}
|
|
||||||
|
|
||||||
void MultipartFileReader::BeginRead(void* pBuffer, uint sector, uint count)
|
|
||||||
{
|
|
||||||
u8* lBuffer = (u8*)pBuffer;
|
|
||||||
|
|
||||||
for(uint i = GetFirstPart(sector); i < m_numparts; i++)
|
|
||||||
{
|
|
||||||
uint num = std::min(count, m_parts[i].end - sector);
|
|
||||||
|
|
||||||
m_parts[i].reader->BeginRead(lBuffer, sector - m_parts[i].start, num);
|
|
||||||
m_parts[i].isReading = true;
|
|
||||||
|
|
||||||
lBuffer += num * m_blocksize;
|
|
||||||
sector += num;
|
|
||||||
count -= num;
|
|
||||||
|
|
||||||
if(count <= 0)
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
int MultipartFileReader::FinishRead(void)
|
|
||||||
{
|
|
||||||
int ret = 0;
|
|
||||||
for(uint i=0;i<m_numparts;i++)
|
|
||||||
{
|
|
||||||
if(m_parts[i].isReading)
|
|
||||||
{
|
|
||||||
ret = std::min(ret, m_parts[i].reader->FinishRead());
|
|
||||||
m_parts[i].isReading = false;
|
|
||||||
|
|
||||||
if(ret < 0)
|
|
||||||
ret = -1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
void MultipartFileReader::CancelRead(void)
|
|
||||||
{
|
|
||||||
for(uint i=0;i<m_numparts;i++)
|
|
||||||
{
|
|
||||||
if(m_parts[i].isReading)
|
|
||||||
{
|
|
||||||
m_parts[i].reader->CancelRead();
|
|
||||||
m_parts[i].isReading = false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void MultipartFileReader::Close(void)
|
|
||||||
{
|
|
||||||
for(uint i=0;i<m_numparts;i++)
|
|
||||||
{
|
|
||||||
if(m_parts[i].reader)
|
|
||||||
{
|
|
||||||
m_parts[i].reader->Close();
|
|
||||||
delete m_parts[i].reader;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
uint MultipartFileReader::GetBlockCount(void) const
|
|
||||||
{
|
|
||||||
return m_parts[m_numparts-1].end;
|
|
||||||
}
|
|
||||||
|
|
||||||
void MultipartFileReader::SetBlockSize(uint bytes)
|
|
||||||
{
|
|
||||||
uint last_end = 0;
|
|
||||||
for(uint i=0;i<m_numparts;i++)
|
|
||||||
{
|
|
||||||
m_parts[i].reader->SetBlockSize(bytes);
|
|
||||||
uint count = m_parts[i].reader->GetBlockCount();
|
|
||||||
|
|
||||||
m_parts[i].start = last_end;
|
|
||||||
m_parts[i].end = last_end = m_parts[i].start + count;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
|
@ -264,7 +264,6 @@
|
||||||
<ClCompile Include="IPU\IPUdma.cpp" />
|
<ClCompile Include="IPU\IPUdma.cpp" />
|
||||||
<ClCompile Include="IPU\IPUdither.cpp" />
|
<ClCompile Include="IPU\IPUdither.cpp" />
|
||||||
<ClCompile Include="Mdec.cpp" />
|
<ClCompile Include="Mdec.cpp" />
|
||||||
<ClCompile Include="MultipartFileReader.cpp" />
|
|
||||||
<ClCompile Include="Patch.cpp" />
|
<ClCompile Include="Patch.cpp" />
|
||||||
<ClCompile Include="PrecompiledHeader.cpp">
|
<ClCompile Include="PrecompiledHeader.cpp">
|
||||||
<PrecompiledHeader>Create</PrecompiledHeader>
|
<PrecompiledHeader>Create</PrecompiledHeader>
|
||||||
|
|
|
@ -722,9 +722,6 @@
|
||||||
<ClCompile Include="CDVD\InputIsoFile.cpp">
|
<ClCompile Include="CDVD\InputIsoFile.cpp">
|
||||||
<Filter>System\ISO</Filter>
|
<Filter>System\ISO</Filter>
|
||||||
</ClCompile>
|
</ClCompile>
|
||||||
<ClCompile Include="MultipartFileReader.cpp">
|
|
||||||
<Filter>System\ISO</Filter>
|
|
||||||
</ClCompile>
|
|
||||||
<ClCompile Include="CDVD\OutputIsoFile.cpp">
|
<ClCompile Include="CDVD\OutputIsoFile.cpp">
|
||||||
<Filter>System\ISO</Filter>
|
<Filter>System\ISO</Filter>
|
||||||
</ClCompile>
|
</ClCompile>
|
||||||
|
|
Loading…
Reference in New Issue