mirror of
https://github.com/RPCS3/rpcs3.git
synced 2025-04-19 19:15:26 +00:00
Qt/System: Clear games in games.yml that are inside the old vfs path during game list refresh
This commit is contained in:
parent
5ac4db752d
commit
c9ec48ea96
5 changed files with 70 additions and 4 deletions
|
@ -4139,6 +4139,13 @@ game_boot_result Emulator::AddGameToYml(const std::string& path)
|
|||
return game_boot_result::invalid_file_or_folder;
|
||||
}
|
||||
|
||||
void Emulator::UpdateGamesPath(const std::string& path, bool save_on_disk)
|
||||
{
|
||||
m_games_config.set_save_on_dirty(save_on_disk);
|
||||
[[maybe_unused]] const games_config::result res = m_games_config.update_vfs_path(path);
|
||||
m_games_config.set_save_on_dirty(true);
|
||||
}
|
||||
|
||||
u32 Emulator::RemoveGames(const std::vector<std::string>& title_id_list, bool save_on_disk)
|
||||
{
|
||||
if (title_id_list.empty())
|
||||
|
|
|
@ -454,6 +454,7 @@ public:
|
|||
u32 AddGamesFromDir(const std::string& path);
|
||||
game_boot_result AddGame(const std::string& path);
|
||||
game_boot_result AddGameToYml(const std::string& path);
|
||||
void UpdateGamesPath(const std::string& path, bool save_on_disk = true);
|
||||
u32 RemoveGames(const std::vector<std::string>& title_id_list, bool save_on_disk = true);
|
||||
game_boot_result RemoveGameFromYml(const std::string& title_id);
|
||||
|
||||
|
|
|
@ -118,20 +118,64 @@ games_config::result games_config::remove_game(const std::string& key)
|
|||
return result::success;
|
||||
}
|
||||
|
||||
games_config::result games_config::update_vfs_path(const std::string& path)
|
||||
{
|
||||
std::lock_guard lock(m_mutex);
|
||||
|
||||
if (m_vfs_path != path)
|
||||
{
|
||||
cfg_log.notice("Changing VFS path in games.yml from '%s' to '%s'", m_vfs_path, path);
|
||||
|
||||
// Remove games in old vfs path
|
||||
if (!m_vfs_path.empty())
|
||||
{
|
||||
for (auto it = m_games.begin(); it != m_games.end();)
|
||||
{
|
||||
if (it->second.starts_with(m_vfs_path))
|
||||
{
|
||||
cfg_log.notice("Removing game from games.yml due to outdated vfs games path: '%s' (old vfs path: '%s')", it->second, m_vfs_path);
|
||||
it = m_games.erase(it);
|
||||
continue;
|
||||
}
|
||||
|
||||
it++;
|
||||
}
|
||||
}
|
||||
|
||||
m_vfs_path = path;
|
||||
m_dirty = true;
|
||||
|
||||
if (m_save_on_dirty && !save_nl())
|
||||
{
|
||||
return result::failure;
|
||||
}
|
||||
}
|
||||
|
||||
return result::success;
|
||||
}
|
||||
|
||||
bool games_config::save_nl()
|
||||
{
|
||||
YAML::Emitter out;
|
||||
out << m_games;
|
||||
out << YAML::BeginMap;
|
||||
out << vfs_path_key << m_vfs_path;
|
||||
for (const auto& [key, value] : m_games)
|
||||
{
|
||||
out << key << value;
|
||||
}
|
||||
out << YAML::EndMap;
|
||||
|
||||
fs::pending_file temp(fs::get_config_dir(true) + "games.yml");
|
||||
const std::string path = fs::get_config_dir(true) + "games.yml";
|
||||
fs::pending_file temp(path);
|
||||
|
||||
if (temp.file && temp.file.write(out.c_str(), out.size()) >= out.size() && temp.commit())
|
||||
{
|
||||
cfg_log.notice("Saved games.yml to '%s'", path);
|
||||
m_dirty = false;
|
||||
return true;
|
||||
}
|
||||
|
||||
cfg_log.error("Failed to save games.yml: %s", fs::g_tls_error);
|
||||
cfg_log.error("Failed to save games.yml to '%s': %s", path, fs::g_tls_error);
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -145,6 +189,7 @@ void games_config::load()
|
|||
{
|
||||
std::lock_guard lock(m_mutex);
|
||||
|
||||
m_vfs_path.clear();
|
||||
m_games.clear();
|
||||
|
||||
const std::string path = fs::get_config_dir(true) + "games.yml";
|
||||
|
@ -186,7 +231,14 @@ void games_config::load()
|
|||
{
|
||||
if (!entry.first.Scalar().empty() && entry.second.IsScalar() && !entry.second.Scalar().empty())
|
||||
{
|
||||
m_games.emplace(entry.first.Scalar(), entry.second.Scalar());
|
||||
if (entry.first.Scalar() == vfs_path_key)
|
||||
{
|
||||
m_vfs_path = entry.second.Scalar();
|
||||
}
|
||||
else
|
||||
{
|
||||
m_games.emplace(entry.first.Scalar(), entry.second.Scalar());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -25,12 +25,15 @@ public:
|
|||
result add_game(const std::string& key, const std::string& path);
|
||||
result add_external_hdd_game(const std::string& key, std::string& path);
|
||||
result remove_game(const std::string& key);
|
||||
result update_vfs_path(const std::string& path);
|
||||
bool save();
|
||||
|
||||
private:
|
||||
bool save_nl();
|
||||
void load();
|
||||
|
||||
const std::string vfs_path_key = "VFS_PATH";
|
||||
std::string m_vfs_path;
|
||||
std::map<std::string, std::string> m_games;
|
||||
mutable shared_mutex m_mutex;
|
||||
|
||||
|
|
|
@ -419,6 +419,9 @@ void game_list_frame::Refresh(const bool from_drive, const std::vector<std::stri
|
|||
|
||||
const std::string games_dir = rpcs3::utils::get_games_dir();
|
||||
|
||||
// Update games path. This will remove any game in memory that matches the previous games path (we don't save to "games.yml" yet).
|
||||
Emu.UpdateGamesPath(games_dir, false);
|
||||
|
||||
// List of serials (title id) to remove in "games.yml" file (if any)
|
||||
std::vector<std::string> serials_to_remove = serials_to_remove_from_yml; // Initialize the list with the specified serials (if any)
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue