GameList: Avoid double fopen/read of EXEs
Some checks failed
Create rolling release / Windows x64 Build (push) Has been cancelled
Create rolling release / Windows x64 SSE2 Build (push) Has been cancelled
Create rolling release / Windows ARM64 Build (push) Has been cancelled
Create rolling release / Linux x64 AppImage (push) Has been cancelled
Create rolling release / Linux x64 SSE2 AppImage (push) Has been cancelled
Create rolling release / MacOS Universal Build (push) Has been cancelled
Create rolling release / Create Release (push) Has been cancelled

This commit is contained in:
Stenzek 2024-10-23 21:20:23 +10:00
parent 2d04f2eff9
commit 7d2216c289
No known key found for this signature in database
4 changed files with 25 additions and 6 deletions

View File

@ -1187,8 +1187,11 @@ bool Bus::SideloadEXE(const std::string& path, Error* error)
return false; return false;
} }
// Stupid Android...
std::string filename = FileSystem::GetDisplayNameFromPath(path);
bool okay = true; bool okay = true;
if (StringUtil::EndsWithNoCase(path, ".cpe")) if (StringUtil::EndsWithNoCase(filename, ".cpe"))
{ {
okay = InjectCPE(exe_data->cspan(), true, error); okay = InjectCPE(exe_data->cspan(), true, error);
} }

View File

@ -179,10 +179,13 @@ bool GameList::GetExeListEntry(const std::string& path, GameList::Entry* entry)
if (entry->file_size < 0) if (entry->file_size < 0)
return false; return false;
entry->title = Path::GetFileTitle(FileSystem::GetDisplayNameFromPath(path)); // Stupid Android...
const std::string filename = FileSystem::GetDisplayNameFromPath(path);
entry->title = Path::GetFileTitle(filename);
entry->type = EntryType::PSExe; entry->type = EntryType::PSExe;
if (StringUtil::EndsWithNoCase(path, ".cpe")) if (StringUtil::EndsWithNoCase(filename, ".cpe"))
{ {
u32 magic; u32 magic;
if (std::fread(&magic, sizeof(magic), 1, fp.get()) != 1 || magic != BIOS::CPE_MAGIC) if (std::fread(&magic, sizeof(magic), 1, fp.get()) != 1 || magic != BIOS::CPE_MAGIC)
@ -207,7 +210,14 @@ bool GameList::GetExeListEntry(const std::string& path, GameList::Entry* entry)
entry->region = BIOS::GetPSExeDiscRegion(header); entry->region = BIOS::GetPSExeDiscRegion(header);
} }
const GameHash hash = System::GetGameHashFromFile(path.c_str()); const auto data = FileSystem::ReadBinaryFile(fp.get());
if (!data.has_value())
{
WARNING_LOG("Failed to read {}", path);
return false;
}
const GameHash hash = System::GetGameHashFromBuffer(filename, data->cspan());
entry->serial = hash ? System::GetGameHashId(hash) : std::string(); entry->serial = hash ? System::GetGameHashId(hash) : std::string();
return true; return true;
} }

View File

@ -997,8 +997,12 @@ GameHash System::GetGameHashFromFile(const char* path)
if (!data) if (!data)
return 0; return 0;
const std::string display_name = FileSystem::GetDisplayNameFromPath(path); return GetGameHashFromBuffer(FileSystem::GetDisplayNameFromPath(path), data->cspan());
return GetGameHashFromBuffer(display_name, data->cspan(), IsoReader::ISOPrimaryVolumeDescriptor{}, 0); }
GameHash System::GetGameHashFromBuffer(const std::string_view filename, const std::span<const u8> data)
{
return GetGameHashFromBuffer(filename, data, IsoReader::ISOPrimaryVolumeDescriptor{}, 0);
} }
std::string System::GetExecutableNameForImage(IsoReader& iso, bool strip_subdirectories) std::string System::GetExecutableNameForImage(IsoReader& iso, bool strip_subdirectories)

View File

@ -10,6 +10,7 @@
#include <memory> #include <memory>
#include <optional> #include <optional>
#include <span>
#include <string> #include <string>
class ByteStream; class ByteStream;
@ -143,6 +144,7 @@ bool ReadExecutableFromImage(CDImage* cdi, std::string* out_executable_name, std
std::string GetGameHashId(GameHash hash); std::string GetGameHashId(GameHash hash);
bool GetGameDetailsFromImage(CDImage* cdi, std::string* out_id, GameHash* out_hash); bool GetGameDetailsFromImage(CDImage* cdi, std::string* out_id, GameHash* out_hash);
GameHash GetGameHashFromFile(const char* path); GameHash GetGameHashFromFile(const char* path);
GameHash GetGameHashFromBuffer(const std::string_view filename, const std::span<const u8> data);
DiscRegion GetRegionForSerial(const std::string_view serial); DiscRegion GetRegionForSerial(const std::string_view serial);
DiscRegion GetRegionFromSystemArea(CDImage* cdi); DiscRegion GetRegionFromSystemArea(CDImage* cdi);
DiscRegion GetRegionForImage(CDImage* cdi); DiscRegion GetRegionForImage(CDImage* cdi);