CDVD: Simplify compressed ISO detection

This commit is contained in:
Stenzek 2023-12-22 09:10:54 +10:00 committed by Connor McLaughlin
parent fdc0370cdf
commit 9967d5ca9e
7 changed files with 28 additions and 65 deletions

View File

@ -41,14 +41,6 @@ ChdFileReader::~ChdFileReader()
Close();
}
bool ChdFileReader::CanHandle(const std::string& fileName, const std::string& displayName)
{
if (!StringUtil::EndsWith(displayName, ".chd"))
return false;
return true;
}
static chd_file* OpenCHD(const std::string& filename, FileSystem::ManagedCFilePtr fp, Error* error, u32 recursion_level)
{
chd_file* chd;

View File

@ -27,8 +27,6 @@ public:
ChdFileReader();
~ChdFileReader() override;
static bool CanHandle(const std::string& fileName, const std::string& displayName);
bool Open2(std::string filename, Error* error) override;
Chunk ChunkForOffset(u64 offset) override;

View File

@ -1,49 +1,49 @@
/* PCSX2 - PS2 Emulator for PCs
* Copyright (C) 2002-2014 PCSX2 Dev Team
*
* PCSX2 is free software: you can redistribute it and/or modify it under the terms
* of the GNU Lesser General Public License as published by the Free Software Found-
* ation, either version 3 of the License, or (at your option) any later version.
*
* PCSX2 is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
* PURPOSE. See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along with PCSX2.
* If not, see <http://www.gnu.org/licenses/>.
*/
* Copyright (C) 2002-2023 PCSX2 Dev Team
*
* PCSX2 is free software: you can redistribute it and/or modify it under the terms
* of the GNU Lesser General Public License as published by the Free Software Found-
* ation, either version 3 of the License, or (at your option) any later version.
*
* PCSX2 is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
* PURPOSE. See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along with PCSX2.
* If not, see <http://www.gnu.org/licenses/>.
*/
#include "PrecompiledHeader.h"
#include "AsyncFileReader.h"
#include "CompressedFileReader.h"
#include "ChdFileReader.h"
#include "CsoFileReader.h"
#include "GzippedFileReader.h"
#include "common/FileSystem.h"
#include "common/Path.h"
#include "common/StringUtil.h"
#include <algorithm>
#include <cctype>
// CompressedFileReader factory.
AsyncFileReader* CompressedFileReader::GetNewReader(const std::string& fileName)
{
if (!FileSystem::FileExists(fileName.c_str()))
return nullptr;
std::string displayName(FileSystem::GetDisplayNameFromPath(fileName));
std::transform(displayName.begin(), displayName.end(), displayName.begin(), tolower);
const std::string_view extension = Path::GetExtension(fileName);
if (ChdFileReader::CanHandle(fileName, displayName))
{
if (StringUtil::compareNoCase(extension, "chd"))
return new ChdFileReader();
}
if (GzippedFileReader::CanHandle(fileName, displayName))
{
return new GzippedFileReader();
}
if (CsoFileReader::CanHandle(fileName, displayName))
{
if (StringUtil::compareNoCase(extension, "cso") || StringUtil::compareNoCase(extension, "zso"))
return new CsoFileReader();
}
// This is the one which will fail on open.
return NULL;
if (StringUtil::compareNoCase(extension, "gz"))
return new GzippedFileReader();
// Not a known compressed format.
return nullptr;
}

View File

@ -50,25 +50,6 @@ CsoFileReader::~CsoFileReader()
Close();
}
bool CsoFileReader::CanHandle(const std::string& fileName, const std::string& displayName)
{
bool supported = false;
if (displayName.ends_with(".cso") || displayName.ends_with(".zso"))
{
FILE* fp = FileSystem::OpenCFile(fileName.c_str(), "rb");
CsoHeader hdr;
if (fp)
{
if (fread(&hdr, 1, sizeof(hdr), fp) == sizeof(hdr))
{
supported = ValidateHeader(hdr, nullptr);
}
fclose(fp);
}
}
return supported;
}
bool CsoFileReader::ValidateHeader(const CsoHeader& hdr, Error* error)
{
if ((hdr.magic[0] != 'C' && hdr.magic[0] != 'Z') || hdr.magic[1] != 'I' || hdr.magic[2] != 'S' || hdr.magic[3] != 'O')

View File

@ -39,7 +39,6 @@ public:
CsoFileReader();
~CsoFileReader() override;
static bool CanHandle(const std::string& fileName, const std::string& displayName);
bool Open2(std::string filename, Error* error) override;
Chunk ChunkForOffset(u64 offset) override;

View File

@ -265,12 +265,6 @@ void GzippedFileReader::AsyncPrefetchCancel()
};
#endif /* _WIN32 */
// TODO: do better than just checking existance and extension
bool GzippedFileReader::CanHandle(const std::string& fileName, const std::string& displayName)
{
return StringUtil::EndsWith(fileName, ".gz");
}
bool GzippedFileReader::OkIndex(Error* error)
{
if (m_pIndex)

View File

@ -33,7 +33,6 @@ public:
GzippedFileReader();
~GzippedFileReader();;
static bool CanHandle(const std::string& fileName, const std::string& displayName);
bool Open(std::string filename, Error* error) override;
int ReadSync(void* pBuffer, u32 sector, u32 count) override;