-
-
Notifications
You must be signed in to change notification settings - Fork 2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Emu: Cache games.yml and only save when necessary #13716
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
add_library(rpcs3_emu | ||
cache_utils.cpp | ||
games_config.cpp | ||
IdManager.cpp | ||
localized_string.cpp | ||
savestate_utils.cpp | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,112 @@ | ||
#include "stdafx.h" | ||
#include "games_config.h" | ||
#include "util/logs.hpp" | ||
#include "util/yaml.hpp" | ||
#include "Utilities/File.h" | ||
|
||
LOG_CHANNEL(cfg_log, "CFG"); | ||
|
||
games_config::games_config() | ||
{ | ||
load(); | ||
} | ||
|
||
games_config::~games_config() | ||
{ | ||
if (m_dirty) | ||
{ | ||
save(); | ||
} | ||
} | ||
|
||
std::string games_config::get_path(const std::string& title_id) const | ||
{ | ||
if (title_id.empty()) | ||
{ | ||
return {}; | ||
} | ||
|
||
if (const auto it = m_games.find(title_id); it != m_games.cend()) | ||
{ | ||
return it->second; | ||
} | ||
|
||
return {}; | ||
} | ||
|
||
bool games_config::add_game(const std::string& key, const std::string& path) | ||
{ | ||
// Access or create node if does not exist | ||
if (auto it = m_games.find(key); it != m_games.end()) | ||
{ | ||
if (it->second == path) | ||
{ | ||
// Nothing to do | ||
return true; | ||
} | ||
|
||
it->second = path; | ||
} | ||
else | ||
{ | ||
m_games.emplace(key, path); | ||
} | ||
|
||
m_dirty = true; | ||
|
||
if (m_save_on_dirty) | ||
{ | ||
return save(); | ||
} | ||
|
||
return true; | ||
} | ||
|
||
bool games_config::save() | ||
{ | ||
YAML::Emitter out; | ||
out << m_games; | ||
|
||
fs::pending_file temp(fs::get_config_dir() + "/games.yml"); | ||
|
||
if (temp.file && temp.file.write(out.c_str(), out.size()), temp.commit()) | ||
{ | ||
m_dirty = false; | ||
return true; | ||
} | ||
|
||
cfg_log.error("Failed to save games.yml: %s", fs::g_tls_error); | ||
return false; | ||
} | ||
|
||
void games_config::load() | ||
{ | ||
m_games.clear(); | ||
|
||
if (fs::file f{fs::get_config_dir() + "/games.yml", fs::read + fs::create}) | ||
{ | ||
auto [result, error] = yaml_load(f.to_string()); | ||
|
||
if (!error.empty()) | ||
{ | ||
cfg_log.error("Failed to load games.yml: %s", error); | ||
} | ||
|
||
if (!result.IsMap()) | ||
{ | ||
if (!result.IsNull()) | ||
{ | ||
cfg_log.error("Failed to load games.yml: type %d not a map", result.Type()); | ||
} | ||
return; | ||
} | ||
|
||
for (const auto& entry : result) | ||
{ | ||
if (!entry.first.Scalar().empty() && entry.second.IsScalar() && !entry.second.Scalar().empty()) | ||
{ | ||
m_games.emplace(entry.first.Scalar(), entry.second.Scalar()); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
#pragma once | ||
|
||
#include <map> | ||
|
||
class games_config | ||
{ | ||
public: | ||
games_config(); | ||
virtual ~games_config(); | ||
|
||
void set_save_on_dirty(bool enabled) { m_save_on_dirty = enabled; } | ||
|
||
const std::map<std::string, std::string>& get_games() const { return m_games; } | ||
bool is_dirty() const { return m_dirty; } | ||
|
||
std::string get_path(const std::string& title_id) const; | ||
|
||
bool add_game(const std::string& key, const std::string& path); | ||
bool save(); | ||
|
||
private: | ||
void load(); | ||
|
||
std::map<std::string, std::string> m_games; | ||
|
||
bool m_dirty = false; | ||
bool m_save_on_dirty = true; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why not log it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's already logged in load
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also, i would have to clear the dirty flag each time which only complicates things for no reason