GameList: Fix uninitialized fields of PSF/EXE

This commit is contained in:
Connor McLaughlin 2021-04-17 20:20:09 +10:00
parent 8ad0f78ef7
commit 2985c395df
3 changed files with 21 additions and 32 deletions

View File

@ -59,27 +59,16 @@ float File::GetTagFloat(const char* tag_name, float default_value) const
bool File::Load(const char* path) bool File::Load(const char* path)
{ {
auto fp = FileSystem::OpenManagedCFile(path, "rb"); std::optional<std::vector<u8>> file_data(FileSystem::ReadBinaryFile(path));
if (!fp) if (!file_data.has_value() || file_data->empty())
{ {
Log_ErrorPrintf("Failed to open PSF file '%s'", path); Log_ErrorPrintf("Failed to open/read PSF file '%s'", path);
return false; return false;
} }
// we could mmap this instead const u8* file_pointer = file_data->data();
std::fseek(fp.get(), 0, SEEK_END); const u8* file_pointer_end = file_data->data() + file_data->size();
const u32 file_size = static_cast<u32>(std::ftell(fp.get())); const u32 file_size = static_cast<u32>(file_data->size());
std::fseek(fp.get(), 0, SEEK_SET);
std::vector<u8> file_data(file_size);
if (std::fread(file_data.data(), 1, file_size, fp.get()) != file_size)
{
Log_ErrorPrintf("Failed to read data from PSF '%s'", path);
return false;
}
const u8* file_pointer = file_data.data();
const u8* file_pointer_end = file_data.data() + file_data.size();
PSFHeader header; PSFHeader header;
std::memcpy(&header, file_pointer, sizeof(header)); std::memcpy(&header, file_pointer, sizeof(header));

View File

@ -122,7 +122,7 @@ bool GameList::GetPsfListEntry(const char* path, GameListEntry* entry)
entry->code.clear(); entry->code.clear();
entry->path = path; entry->path = path;
entry->region = file.GetRegion(); entry->region = file.GetRegion();
entry->total_size = ffd.Size; entry->total_size = static_cast<u32>(file.GetProgramData().size());
entry->last_modified_time = ffd.ModificationTime.AsUnixTimestamp(); entry->last_modified_time = ffd.ModificationTime.AsUnixTimestamp();
entry->type = GameListEntryType::PSF; entry->type = GameListEntryType::PSF;
entry->compatibility_rating = GameListCompatibilityRating::Unknown; entry->compatibility_rating = GameListCompatibilityRating::Unknown;

View File

@ -1,7 +1,7 @@
#pragma once #pragma once
#include "core/types.h" #include "core/types.h"
#include "game_settings.h"
#include "game_database.h" #include "game_database.h"
#include "game_settings.h"
#include <memory> #include <memory>
#include <optional> #include <optional>
#include <string> #include <string>
@ -37,8 +37,8 @@ enum class GameListCompatibilityRating
struct GameListEntry struct GameListEntry
{ {
GameListEntryType type; GameListEntryType type = GameListEntryType::Disc;
DiscRegion region; DiscRegion region = DiscRegion::Other;
std::string path; std::string path;
std::string code; std::string code;
@ -46,17 +46,17 @@ struct GameListEntry
std::string genre; std::string genre;
std::string publisher; std::string publisher;
std::string developer; std::string developer;
u64 total_size; u64 total_size = 0;
u64 last_modified_time; u64 last_modified_time = 0;
u64 release_date; u64 release_date = 0;
u32 supported_controllers; u32 supported_controllers = ~static_cast<u32>(0);
u8 min_players; u8 min_players = 1;
u8 max_players; u8 max_players = 1;
u8 min_blocks; u8 min_blocks = 0;
u8 max_blocks; u8 max_blocks = 0;
GameListCompatibilityRating compatibility_rating; GameListCompatibilityRating compatibility_rating = GameListCompatibilityRating::Unknown;
GameSettings::Entry settings; GameSettings::Entry settings;
size_t GetReleaseDateString(char* buffer, size_t buffer_size) const; size_t GetReleaseDateString(char* buffer, size_t buffer_size) const;
@ -69,8 +69,8 @@ struct GameListCompatibilityEntry
std::string version_tested; std::string version_tested;
std::string upscaling_issues; std::string upscaling_issues;
std::string comments; std::string comments;
DiscRegion region; DiscRegion region = DiscRegion::Other;
GameListCompatibilityRating compatibility_rating; GameListCompatibilityRating compatibility_rating = GameListCompatibilityRating::Unknown;
}; };
class GameList class GameList