diff --git a/pcsx2/CDVD/ChdFileReader.cpp b/pcsx2/CDVD/ChdFileReader.cpp
index f9be167664..43c6c73084 100644
--- a/pcsx2/CDVD/ChdFileReader.cpp
+++ b/pcsx2/CDVD/ChdFileReader.cpp
@@ -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;
diff --git a/pcsx2/CDVD/ChdFileReader.h b/pcsx2/CDVD/ChdFileReader.h
index cc28001e7e..e3453df154 100644
--- a/pcsx2/CDVD/ChdFileReader.h
+++ b/pcsx2/CDVD/ChdFileReader.h
@@ -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;
diff --git a/pcsx2/CDVD/CompressedFileReader.cpp b/pcsx2/CDVD/CompressedFileReader.cpp
index 1d8b404ece..97750d1b6f 100644
--- a/pcsx2/CDVD/CompressedFileReader.cpp
+++ b/pcsx2/CDVD/CompressedFileReader.cpp
@@ -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 .
-*/
+ * 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 .
+ */
#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
#include
-// 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;
}
diff --git a/pcsx2/CDVD/CsoFileReader.cpp b/pcsx2/CDVD/CsoFileReader.cpp
index 55ddc9d6e2..a9b8c87f47 100644
--- a/pcsx2/CDVD/CsoFileReader.cpp
+++ b/pcsx2/CDVD/CsoFileReader.cpp
@@ -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')
diff --git a/pcsx2/CDVD/CsoFileReader.h b/pcsx2/CDVD/CsoFileReader.h
index 6d035d512e..e5a033f919 100644
--- a/pcsx2/CDVD/CsoFileReader.h
+++ b/pcsx2/CDVD/CsoFileReader.h
@@ -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;
diff --git a/pcsx2/CDVD/GzippedFileReader.cpp b/pcsx2/CDVD/GzippedFileReader.cpp
index 795b1f5f99..fa104d5259 100644
--- a/pcsx2/CDVD/GzippedFileReader.cpp
+++ b/pcsx2/CDVD/GzippedFileReader.cpp
@@ -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)
diff --git a/pcsx2/CDVD/GzippedFileReader.h b/pcsx2/CDVD/GzippedFileReader.h
index df79f3632f..f1c2a0d195 100644
--- a/pcsx2/CDVD/GzippedFileReader.h
+++ b/pcsx2/CDVD/GzippedFileReader.h
@@ -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;