diff --git a/rpcs3/Crypto/unpkg.cpp b/rpcs3/Crypto/unpkg.cpp index a89447d096..dc5ff63866 100644 --- a/rpcs3/Crypto/unpkg.cpp +++ b/rpcs3/Crypto/unpkg.cpp @@ -535,7 +535,7 @@ package_error package_reader::check_target_app_version() const auto category = psf::get_string(psf, "CATEGORY", ""); const auto title_id = psf::get_string(psf, "TITLE_ID", ""); 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") { @@ -561,7 +561,7 @@ package_error package_reader::check_target_app_version() 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 (!target_app_ver.empty()) @@ -587,9 +587,9 @@ package_error package_reader::check_target_app_version() } std::add_pointer_t 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); 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. - 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); 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 - 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); return package_error::other; diff --git a/rpcs3/Emu/Cell/Modules/cellGame.cpp b/rpcs3/Emu/Cell/Modules/cellGame.cpp index 9d59ce42bc..117a065bfb 100644 --- a/rpcs3/Emu/Cell/Modules/cellGame.cpp +++ b/rpcs3/Emu/Cell/Modules/cellGame.cpp @@ -876,7 +876,7 @@ error_code cellGameGetParamString(s32 id, vm::ptr buf, u32 bufsize) 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))) { diff --git a/rpcs3/Emu/System.cpp b/rpcs3/Emu/System.cpp index 029f4eb4a0..0c63ef72f0 100644 --- a/rpcs3/Emu/System.cpp +++ b/rpcs3/Emu/System.cpp @@ -761,7 +761,7 @@ std::string Emulator::GetSfoDirFromGamePath(const std::string& game_path, const if (entry.is_directory && fs::is_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) { 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 std::string category = get_string(psf, "CATEGORY"); - const std::string content_id = get_string(psf, "CONTENT_ID"); + const auto category = psf::get_string(psf, "CATEGORY"); + const auto content_id = std::string(psf::get_string(psf, "CONTENT_ID")); + if (category == "HG" && !content_id.empty()) { // 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")); } - m_title = psf::get_string(_psf, "TITLE", m_path.substr(m_path.find_last_of('/') + 1)); - m_title_id = psf::get_string(_psf, "TITLE_ID"); - m_cat = psf::get_string(_psf, "CATEGORY"); + m_title = std::string(psf::get_string(_psf, "TITLE", std::string_view(m_path).substr(m_path.find_last_of('/') + 1))); + m_title_id = std::string(psf::get_string(_psf, "TITLE_ID")); + m_cat = std::string(psf::get_string(_psf, "CATEGORY")); - m_app_version = psf::get_string(_psf, "APP_VER", "Unknown"); - const std::string version_disc = psf::get_string(_psf, "VERSION", "Unknown"); + m_app_version = std::string(psf::get_string(_psf, "APP_VER", "Unknown")); + const auto version_disc = psf::get_string(_psf, "VERSION", "Unknown"); 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; } - 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) { @@ -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)) { - 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) { diff --git a/rpcs3/Loader/PSF.cpp b/rpcs3/Loader/PSF.cpp index 49a2ddc465..c0cd15e8b6 100644 --- a/rpcs3/Loader/PSF.cpp +++ b/rpcs3/Loader/PSF.cpp @@ -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); diff --git a/rpcs3/Loader/PSF.h b/rpcs3/Loader/PSF.h index d8d8eaa59f..de303f75d8 100644 --- a/rpcs3/Loader/PSF.h +++ b/rpcs3/Loader/PSF.h @@ -1,6 +1,7 @@ #pragma once #include +#include namespace psf { @@ -48,7 +49,7 @@ namespace psf void save_object(const fs::file&, const registry&); // 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 u32 get_integer(const registry& psf, const std::string& key, u32 def = 0); @@ -69,14 +70,14 @@ namespace psf } // 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 - 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)}; } } diff --git a/rpcs3/rpcs3qt/game_list_frame.cpp b/rpcs3/rpcs3qt/game_list_frame.cpp index b9a078669a..d7f0ffd00c 100644 --- a/rpcs3/rpcs3qt/game_list_frame.cpp +++ b/rpcs3/rpcs3qt/game_list_frame.cpp @@ -556,12 +556,12 @@ void game_list_frame::Refresh(const bool from_drive, const bool scroll_after) GameInfo game; game.path = dir; game.icon_path = sfo_dir + "/ICON0.PNG"; - game.serial = psf::get_string(psf, "TITLE_ID", ""); - game.name = psf::get_string(psf, "TITLE", cat_unknown_localized); - game.app_ver = psf::get_string(psf, "APP_VER", cat_unknown_localized); - game.version = psf::get_string(psf, "VERSION", cat_unknown_localized); - game.category = psf::get_string(psf, "CATEGORY", cat_unknown); - game.fw = psf::get_string(psf, "PS3_SYSTEM_VER", cat_unknown_localized); + game.serial = std::string(psf::get_string(psf, "TITLE_ID", "")); + game.name = std::string(psf::get_string(psf, "TITLE", cat_unknown_localized)); + game.app_ver = std::string(psf::get_string(psf, "APP_VER", cat_unknown_localized)); + game.version = std::string(psf::get_string(psf, "VERSION", cat_unknown_localized)); + game.category = std::string(psf::get_string(psf, "CATEGORY", cat_unknown)); + 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.resolution = psf::get_integer(psf, "RESOLUTION", 0); game.sound_format = psf::get_integer(psf, "SOUND_FORMAT", 0);