PARAM.SFO loader improvement

This commit is contained in:
Eladash 2022-04-09 13:13:08 +03:00 committed by Megamouse
parent f8ea50caae
commit c35da0085f
3 changed files with 24 additions and 13 deletions

View File

@ -189,7 +189,7 @@ error_code cellHddGameCheck(ppu_thread& ppu, u32 version, vm::cptr<char> dirName
if (!new_data)
{
const auto cat = psf::get_string(sfo, "CATEGORY", "");
if (cat != "HG"sv && cat != "AM"sv && cat != "AP"sv && cat != "AT"sv && cat != "AV"sv && cat != "BV"sv && cat != "WT"sv)
if (!psf::is_cat_hdd(cat))
{
return { CELL_GAMEDATA_ERROR_BROKEN, fmt::format("CATEGORY='%s'", cat) };
}
@ -594,7 +594,7 @@ error_code cellGameDataCheck(u32 type, vm::cptr<char> dirName, vm::ptr<CellGameC
{
switch (type)
{
case CELL_GAME_GAMETYPE_HDD: return cat != "HG"sv && cat != "AM"sv && cat != "AP"sv && cat != "AT"sv && cat != "AV"sv && cat != "BV"sv && cat != "WT"sv;
case CELL_GAME_GAMETYPE_HDD: return !psf::is_cat_hdd(cat);
case CELL_GAME_GAMETYPE_GAMEDATA: return cat != "GD"sv;
case CELL_GAME_GAMETYPE_DISC: return cat != "DG"sv;
default: fmt::throw_exception("Unreachable");

View File

@ -116,10 +116,6 @@ namespace psf
{
}
entry::~entry()
{
}
const std::string& entry::as_string() const
{
ensure(m_type == format::string || m_type == format::array);
@ -246,6 +242,15 @@ namespace psf
}
}
const auto cat = get_string(pair.sfo, "CATEGORY", "");
constexpr std::string_view valid_cats[]{"GD", "DG", "HG", "AM", "AP", "AT", "AV", "BV", "WT", "HM", "CB", "SF", "2P", "2G", "1P", "PP", "MN", "PE", "2D", "SD", "MS"};
if (std::find(std::begin(valid_cats), std::end(valid_cats), cat) == std::end(valid_cats))
{
psf_log.error("Unknown category ('%s')", cat);
PSF_CHECK(false, corrupt);
}
#undef PSF_CHECK
return pair;
}
@ -339,7 +344,7 @@ namespace psf
return std::move(static_cast<fs::container_stream<std::vector<u8>>*>(stream.release().get())->obj);
}
std::string_view get_string(const registry& psf, const std::string& key, std::string_view def)
std::string_view get_string(const registry& psf, std::string_view key, std::string_view def)
{
const auto found = psf.find(key);
@ -351,7 +356,7 @@ namespace psf
return found->second.as_string();
}
u32 get_integer(const registry& psf, const std::string& key, u32 def)
u32 get_integer(const registry& psf, std::string_view key, u32 def)
{
const auto found = psf.find(key);

View File

@ -41,7 +41,7 @@ namespace psf
// Construct integer entry, assign the value
entry(u32 value);
~entry();
~entry() = default;
const std::string& as_string() const;
u32 as_integer() const;
@ -55,7 +55,7 @@ namespace psf
};
// Define PSF registry as a sorted map of entries:
using registry = std::map<std::string, entry>;
using registry = std::map<std::string, entry, std::less<>>;
struct load_result_t
{
@ -77,13 +77,13 @@ namespace psf
std::vector<u8> save_object(const registry&, std::vector<u8>&& init = std::vector<u8>{});
// Get string value or default value
std::string_view get_string(const registry& psf, const std::string& key, std::string_view def = ""sv);
std::string_view get_string(const registry& psf, std::string_view key, std::string_view def = ""sv);
// Get integer value or default value
u32 get_integer(const registry& psf, const std::string& key, u32 def = 0);
u32 get_integer(const registry& psf, std::string_view key, u32 def = 0);
// Assign new entry
inline void assign(registry& psf, const std::string& key, entry&& _entry)
inline void assign(registry& psf, std::string_view key, entry&& _entry)
{
const auto found = psf.find(key);
@ -108,4 +108,10 @@ namespace psf
{
return {format::array, max_size, value};
}
// Checks if of HDD catgeory (assumes a valid category is being passed)
constexpr bool is_cat_hdd(std::string_view cat)
{
return cat.size() == 2u && cat[1] != 'D' && cat != "DG"sv && cat != "MS"sv;
}
}