mirror of
https://github.com/RPCS3/rpcs3.git
synced 2025-07-09 00:11:24 +12:00
PSF: Avoid redundent string copies in psf::array/string/get_string (#8707)
This commit is contained in:
parent
b487c09d34
commit
edc09e22b4
6 changed files with 33 additions and 31 deletions
|
@ -535,7 +535,7 @@ package_error package_reader::check_target_app_version()
|
||||||
const auto category = psf::get_string(psf, "CATEGORY", "");
|
const auto category = psf::get_string(psf, "CATEGORY", "");
|
||||||
const auto title_id = psf::get_string(psf, "TITLE_ID", "");
|
const auto title_id = psf::get_string(psf, "TITLE_ID", "");
|
||||||
const auto app_ver = psf::get_string(psf, "APP_VER", "");
|
const auto app_ver = psf::get_string(psf, "APP_VER", "");
|
||||||
auto target_app_ver = psf::get_string(psf, "TARGET_APP_VER", "");
|
const auto target_app_ver = psf::get_string(psf, "TARGET_APP_VER", "");
|
||||||
|
|
||||||
if (category != "GD")
|
if (category != "GD")
|
||||||
{
|
{
|
||||||
|
@ -561,7 +561,7 @@ package_error package_reader::check_target_app_version()
|
||||||
return package_error::no_error;
|
return package_error::no_error;
|
||||||
}
|
}
|
||||||
|
|
||||||
const fs::file installed_sfo_file(Emu.GetHddDir() + "game/" + title_id + "/PARAM.SFO");
|
const fs::file installed_sfo_file(Emu.GetHddDir() + "game/" + std::string(title_id) + "/PARAM.SFO");
|
||||||
if (!installed_sfo_file)
|
if (!installed_sfo_file)
|
||||||
{
|
{
|
||||||
if (!target_app_ver.empty())
|
if (!target_app_ver.empty())
|
||||||
|
@ -587,9 +587,9 @@ package_error package_reader::check_target_app_version()
|
||||||
}
|
}
|
||||||
|
|
||||||
std::add_pointer_t<char> ev0, ev1;
|
std::add_pointer_t<char> ev0, ev1;
|
||||||
const double old_version = std::strtod(installed_app_ver.c_str(), &ev0);
|
const double old_version = std::strtod(installed_app_ver.data(), &ev0);
|
||||||
|
|
||||||
if (installed_app_ver.c_str() + installed_app_ver.size() != ev0)
|
if (installed_app_ver.data() + installed_app_ver.size() != ev0)
|
||||||
{
|
{
|
||||||
pkg_log.error("Failed to convert the installed app version to double (%s)", installed_app_ver);
|
pkg_log.error("Failed to convert the installed app version to double (%s)", installed_app_ver);
|
||||||
return package_error::other;
|
return package_error::other;
|
||||||
|
@ -599,9 +599,9 @@ package_error package_reader::check_target_app_version()
|
||||||
{
|
{
|
||||||
// This is most likely the first patch. Let's make sure its version is high enough for the installed game.
|
// This is most likely the first patch. Let's make sure its version is high enough for the installed game.
|
||||||
|
|
||||||
const double new_version = std::strtod(app_ver.c_str(), &ev1);
|
const double new_version = std::strtod(app_ver.data(), &ev1);
|
||||||
|
|
||||||
if (app_ver.c_str() + app_ver.size() != ev1)
|
if (app_ver.data() + app_ver.size() != ev1)
|
||||||
{
|
{
|
||||||
pkg_log.error("Failed to convert the package's app version to double (%s)", app_ver);
|
pkg_log.error("Failed to convert the package's app version to double (%s)", app_ver);
|
||||||
return package_error::other;
|
return package_error::other;
|
||||||
|
@ -619,9 +619,9 @@ package_error package_reader::check_target_app_version()
|
||||||
|
|
||||||
// Check if the installed app version matches the target app version
|
// Check if the installed app version matches the target app version
|
||||||
|
|
||||||
const double target_version = std::strtod(target_app_ver.c_str(), &ev1);
|
const double target_version = std::strtod(target_app_ver.data(), &ev1);
|
||||||
|
|
||||||
if (target_app_ver.c_str() + target_app_ver.size() != ev1)
|
if (target_app_ver.data() + target_app_ver.size() != ev1)
|
||||||
{
|
{
|
||||||
pkg_log.error("Failed to convert the package's target app version to double (%s)", target_app_ver);
|
pkg_log.error("Failed to convert the package's target app version to double (%s)", target_app_ver);
|
||||||
return package_error::other;
|
return package_error::other;
|
||||||
|
|
|
@ -876,7 +876,7 @@ error_code cellGameGetParamString(s32 id, vm::ptr<char> buf, u32 bufsize)
|
||||||
return CELL_GAME_ERROR_NOTSUPPORTED;
|
return CELL_GAME_ERROR_NOTSUPPORTED;
|
||||||
}
|
}
|
||||||
|
|
||||||
const std::string value = psf::get_string(prm->sfo, std::string(key.name));
|
const auto value = psf::get_string(prm->sfo, std::string(key.name));
|
||||||
|
|
||||||
if (value.empty() && !prm->sfo.count(std::string(key.name)))
|
if (value.empty() && !prm->sfo.count(std::string(key.name)))
|
||||||
{
|
{
|
||||||
|
|
|
@ -761,7 +761,7 @@ std::string Emulator::GetSfoDirFromGamePath(const std::string& game_path, const
|
||||||
if (entry.is_directory && fs::is_file(sfo_path))
|
if (entry.is_directory && fs::is_file(sfo_path))
|
||||||
{
|
{
|
||||||
const auto psf = psf::load_object(fs::file(sfo_path));
|
const auto psf = psf::load_object(fs::file(sfo_path));
|
||||||
const std::string serial = get_string(psf, "TITLE_ID");
|
const auto serial = psf::get_string(psf, "TITLE_ID");
|
||||||
if (serial == title_id)
|
if (serial == title_id)
|
||||||
{
|
{
|
||||||
return game_path + "/" + entry.name;
|
return game_path + "/" + entry.name;
|
||||||
|
@ -775,8 +775,9 @@ std::string Emulator::GetSfoDirFromGamePath(const std::string& game_path, const
|
||||||
|
|
||||||
const auto psf = psf::load_object(fs::file(game_path + "/PARAM.SFO"));
|
const auto psf = psf::load_object(fs::file(game_path + "/PARAM.SFO"));
|
||||||
|
|
||||||
const std::string category = get_string(psf, "CATEGORY");
|
const auto category = psf::get_string(psf, "CATEGORY");
|
||||||
const std::string content_id = get_string(psf, "CONTENT_ID");
|
const auto content_id = std::string(psf::get_string(psf, "CONTENT_ID"));
|
||||||
|
|
||||||
if (category == "HG" && !content_id.empty())
|
if (category == "HG" && !content_id.empty())
|
||||||
{
|
{
|
||||||
// This is a trial game. Check if the user has a RAP file to unlock it.
|
// This is a trial game. Check if the user has a RAP file to unlock it.
|
||||||
|
@ -912,12 +913,12 @@ game_boot_result Emulator::Load(const std::string& title_id, bool add_only, bool
|
||||||
_psf = psf::load_object(fs::file(m_sfo_dir + "/PARAM.SFO"));
|
_psf = psf::load_object(fs::file(m_sfo_dir + "/PARAM.SFO"));
|
||||||
}
|
}
|
||||||
|
|
||||||
m_title = psf::get_string(_psf, "TITLE", m_path.substr(m_path.find_last_of('/') + 1));
|
m_title = std::string(psf::get_string(_psf, "TITLE", std::string_view(m_path).substr(m_path.find_last_of('/') + 1)));
|
||||||
m_title_id = psf::get_string(_psf, "TITLE_ID");
|
m_title_id = std::string(psf::get_string(_psf, "TITLE_ID"));
|
||||||
m_cat = psf::get_string(_psf, "CATEGORY");
|
m_cat = std::string(psf::get_string(_psf, "CATEGORY"));
|
||||||
|
|
||||||
m_app_version = psf::get_string(_psf, "APP_VER", "Unknown");
|
m_app_version = std::string(psf::get_string(_psf, "APP_VER", "Unknown"));
|
||||||
const std::string version_disc = psf::get_string(_psf, "VERSION", "Unknown");
|
const auto version_disc = psf::get_string(_psf, "VERSION", "Unknown");
|
||||||
|
|
||||||
if (!_psf.empty() && m_cat.empty())
|
if (!_psf.empty() && m_cat.empty())
|
||||||
{
|
{
|
||||||
|
@ -1271,7 +1272,7 @@ game_boot_result Emulator::Load(const std::string& title_id, bool add_only, bool
|
||||||
return game_boot_result::invalid_file_or_folder;
|
return game_boot_result::invalid_file_or_folder;
|
||||||
}
|
}
|
||||||
|
|
||||||
const std::string bdvd_title_id = psf::get_string(psf::load_object(fs::file{vfs::get("/dev_bdvd/PS3_GAME/PARAM.SFO")}), "TITLE_ID");
|
const auto bdvd_title_id = psf::get_string(psf::load_object(fs::file{vfs::get("/dev_bdvd/PS3_GAME/PARAM.SFO")}), "TITLE_ID");
|
||||||
|
|
||||||
if (bdvd_title_id != m_title_id)
|
if (bdvd_title_id != m_title_id)
|
||||||
{
|
{
|
||||||
|
@ -1440,7 +1441,7 @@ game_boot_result Emulator::Load(const std::string& title_id, bool add_only, bool
|
||||||
|
|
||||||
if (!disc_sfo_dir.empty() && fs::is_file(disc_sfo_dir))
|
if (!disc_sfo_dir.empty() && fs::is_file(disc_sfo_dir))
|
||||||
{
|
{
|
||||||
const std::string bdvd_title = psf::get_string(psf::load_object(fs::file{ disc_sfo_dir }), "TITLE");
|
const auto bdvd_title = psf::get_string(psf::load_object(fs::file{ disc_sfo_dir }), "TITLE");
|
||||||
|
|
||||||
if (!bdvd_title.empty() && bdvd_title != m_title)
|
if (!bdvd_title.empty() && bdvd_title != m_title)
|
||||||
{
|
{
|
||||||
|
|
|
@ -265,7 +265,7 @@ namespace psf
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string get_string(const registry& psf, const std::string& key, const std::string& def)
|
std::string_view get_string(const registry& psf, const std::string& key, std::string_view def)
|
||||||
{
|
{
|
||||||
const auto found = psf.find(key);
|
const auto found = psf.find(key);
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <map>
|
#include <map>
|
||||||
|
#include <string_view>
|
||||||
|
|
||||||
namespace psf
|
namespace psf
|
||||||
{
|
{
|
||||||
|
@ -48,7 +49,7 @@ namespace psf
|
||||||
void save_object(const fs::file&, const registry&);
|
void save_object(const fs::file&, const registry&);
|
||||||
|
|
||||||
// Get string value or default value
|
// Get string value or default value
|
||||||
std::string get_string(const registry& psf, const std::string& key, const std::string& def = {});
|
std::string_view get_string(const registry& psf, const std::string& key, std::string_view def = ""sv);
|
||||||
|
|
||||||
// Get integer value or default value
|
// 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, const std::string& key, u32 def = 0);
|
||||||
|
@ -69,14 +70,14 @@ namespace psf
|
||||||
}
|
}
|
||||||
|
|
||||||
// Make string entry
|
// Make string entry
|
||||||
inline entry string(u32 max_size, const std::string& value)
|
inline entry string(u32 max_size, std::string_view value)
|
||||||
{
|
{
|
||||||
return {format::string, max_size, value};
|
return {format::string, max_size, std::string(value)};
|
||||||
}
|
}
|
||||||
|
|
||||||
// Make array entry
|
// Make array entry
|
||||||
inline entry array(u32 max_size, const std::string& value)
|
inline entry array(u32 max_size, std::string_view value)
|
||||||
{
|
{
|
||||||
return {format::array, max_size, value};
|
return {format::array, max_size, std::string(value)};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -556,12 +556,12 @@ void game_list_frame::Refresh(const bool from_drive, const bool scroll_after)
|
||||||
GameInfo game;
|
GameInfo game;
|
||||||
game.path = dir;
|
game.path = dir;
|
||||||
game.icon_path = sfo_dir + "/ICON0.PNG";
|
game.icon_path = sfo_dir + "/ICON0.PNG";
|
||||||
game.serial = psf::get_string(psf, "TITLE_ID", "");
|
game.serial = std::string(psf::get_string(psf, "TITLE_ID", ""));
|
||||||
game.name = psf::get_string(psf, "TITLE", cat_unknown_localized);
|
game.name = std::string(psf::get_string(psf, "TITLE", cat_unknown_localized));
|
||||||
game.app_ver = psf::get_string(psf, "APP_VER", cat_unknown_localized);
|
game.app_ver = std::string(psf::get_string(psf, "APP_VER", cat_unknown_localized));
|
||||||
game.version = psf::get_string(psf, "VERSION", cat_unknown_localized);
|
game.version = std::string(psf::get_string(psf, "VERSION", cat_unknown_localized));
|
||||||
game.category = psf::get_string(psf, "CATEGORY", cat_unknown);
|
game.category = std::string(psf::get_string(psf, "CATEGORY", cat_unknown));
|
||||||
game.fw = psf::get_string(psf, "PS3_SYSTEM_VER", cat_unknown_localized);
|
game.fw = std::string(psf::get_string(psf, "PS3_SYSTEM_VER", cat_unknown_localized));
|
||||||
game.parental_lvl = psf::get_integer(psf, "PARENTAL_LEVEL", 0);
|
game.parental_lvl = psf::get_integer(psf, "PARENTAL_LEVEL", 0);
|
||||||
game.resolution = psf::get_integer(psf, "RESOLUTION", 0);
|
game.resolution = psf::get_integer(psf, "RESOLUTION", 0);
|
||||||
game.sound_format = psf::get_integer(psf, "SOUND_FORMAT", 0);
|
game.sound_format = psf::get_integer(psf, "SOUND_FORMAT", 0);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue