Don't store custom names from TitleDatabase in GameFileCache

This saves us from having to update the GameFileCache when the
TitleDatabase changes (for instance when the user changes language).
This commit is contained in:
JosJuice
2018-06-03 12:07:53 +02:00
parent 0f7370a22c
commit 85e94cc510
12 changed files with 75 additions and 94 deletions

View File

@ -141,20 +141,6 @@ bool GameFile::IsValid() const
return true;
}
bool GameFile::CustomNameChanged(const Core::TitleDatabase& title_database)
{
const auto type = m_platform == DiscIO::Platform::WiiWAD ?
Core::TitleDatabase::TitleType::Channel :
Core::TitleDatabase::TitleType::Other;
m_pending.custom_name = title_database.GetTitleName(m_game_id, type);
return m_custom_name != m_pending.custom_name;
}
void GameFile::CustomNameCommit()
{
m_custom_name = std::move(m_pending.custom_name);
}
void GameBanner::DoState(PointerWrap& p)
{
p.Do(buffer);
@ -191,7 +177,6 @@ void GameFile::DoState(PointerWrap& p)
m_volume_banner.DoState(p);
m_custom_banner.DoState(p);
p.Do(m_custom_name);
}
bool GameFile::IsElfOrDol() const
@ -280,11 +265,17 @@ void GameFile::CustomBannerCommit()
m_custom_banner = std::move(m_pending.custom_banner);
}
const std::string& GameFile::GetName(const Core::TitleDatabase& title_database) const
{
const auto type = m_platform == DiscIO::Platform::WiiWAD ?
Core::TitleDatabase::TitleType::Channel :
Core::TitleDatabase::TitleType::Other;
const std::string& custom_name = title_database.GetTitleName(m_game_id, type);
return custom_name.empty() ? GetName() : custom_name;
}
const std::string& GameFile::GetName(bool long_name) const
{
if (!m_custom_name.empty())
return m_custom_name;
const std::string& name = long_name ? GetLongName() : GetShortName();
if (!name.empty())
return name;
@ -323,9 +314,7 @@ std::string GameFile::GetUniqueIdentifier() const
if (GetRevision() != 0)
info.push_back("Revision " + std::to_string(GetRevision()));
std::string name(GetLongName(lang));
if (name.empty())
name = GetName();
const std::string& name = GetName();
int disc_number = GetDiscNumber() + 1;

View File

@ -44,6 +44,7 @@ public:
bool IsValid() const;
const std::string& GetFilePath() const { return m_file_path; }
const std::string& GetFileName() const { return m_file_name; }
const std::string& GetName(const Core::TitleDatabase& title_database) const;
const std::string& GetName(bool long_name = true) const;
const std::string& GetMaker(bool long_maker = true) const;
const std::string& GetShortName(DiscIO::Language l) const { return Lookup(l, m_short_names); }
@ -79,8 +80,6 @@ public:
void WiiBannerCommit();
bool CustomBannerChanged();
void CustomBannerCommit();
bool CustomNameChanged(const Core::TitleDatabase& title_database);
void CustomNameCommit();
private:
static const std::string& Lookup(DiscIO::Language language,
@ -121,8 +120,6 @@ private:
GameBanner m_volume_banner{};
GameBanner m_custom_banner{};
// Overridden name from TitleDatabase
std::string m_custom_name{};
// The following data members allow GameFileCache to construct updated versions
// of GameFiles in a threadsafe way. They should not be handled in DoState.
@ -130,7 +127,6 @@ private:
{
GameBanner volume_banner;
GameBanner custom_banner;
std::string custom_name;
} m_pending{};
};

View File

@ -20,15 +20,13 @@
#include "Common/FileSearch.h"
#include "Common/FileUtil.h"
#include "Core/TitleDatabase.h"
#include "DiscIO/DirectoryBlob.h"
#include "UICommon/GameFile.h"
namespace UICommon
{
static constexpr u32 CACHE_REVISION = 10; // Last changed in PR 6429
static constexpr u32 CACHE_REVISION = 11; // Last changed in PR 7058
std::vector<std::string> FindAllGamePaths(const std::vector<std::string>& directories_to_scan,
bool recursive_scan)
@ -52,8 +50,7 @@ void GameFileCache::Clear()
}
std::shared_ptr<const GameFile> GameFileCache::AddOrGet(const std::string& path,
bool* cache_changed,
const Core::TitleDatabase& title_database)
bool* cache_changed)
{
auto it = std::find_if(
m_cached_files.begin(), m_cached_files.end(),
@ -67,7 +64,7 @@ std::shared_ptr<const GameFile> GameFileCache::AddOrGet(const std::string& path,
m_cached_files.emplace_back(std::move(game));
}
std::shared_ptr<GameFile>& result = found ? *it : m_cached_files.back();
if (UpdateAdditionalMetadata(&result, title_database) || !found)
if (UpdateAdditionalMetadata(&result) || !found)
*cache_changed = true;
return result;
@ -135,14 +132,13 @@ bool GameFileCache::Update(
}
bool GameFileCache::UpdateAdditionalMetadata(
const Core::TitleDatabase& title_database,
std::function<void(const std::shared_ptr<const GameFile>&)> game_updated)
{
bool cache_changed = false;
for (std::shared_ptr<GameFile>& file : m_cached_files)
{
const bool updated = UpdateAdditionalMetadata(&file, title_database);
const bool updated = UpdateAdditionalMetadata(&file);
cache_changed |= updated;
if (game_updated && updated)
game_updated(file);
@ -151,13 +147,11 @@ bool GameFileCache::UpdateAdditionalMetadata(
return cache_changed;
}
bool GameFileCache::UpdateAdditionalMetadata(std::shared_ptr<GameFile>* game_file,
const Core::TitleDatabase& title_database)
bool GameFileCache::UpdateAdditionalMetadata(std::shared_ptr<GameFile>* game_file)
{
const bool wii_banner_changed = (*game_file)->WiiBannerChanged();
const bool custom_banner_changed = (*game_file)->CustomBannerChanged();
const bool custom_title_changed = (*game_file)->CustomNameChanged(title_database);
if (!wii_banner_changed && !custom_banner_changed && !custom_title_changed)
if (!wii_banner_changed && !custom_banner_changed)
return false;
// If a cached file needs an update, apply the updates to a copy and delete the original.
@ -168,8 +162,6 @@ bool GameFileCache::UpdateAdditionalMetadata(std::shared_ptr<GameFile>* game_fil
copy->WiiBannerCommit();
if (custom_banner_changed)
copy->CustomBannerCommit();
if (custom_title_changed)
copy->CustomNameCommit();
*game_file = std::move(copy);
return true;

View File

@ -16,11 +16,6 @@
class PointerWrap;
namespace Core
{
class TitleDatabase;
}
namespace UICommon
{
class GameFile;
@ -36,23 +31,20 @@ public:
void Clear();
// Returns nullptr if the file is invalid.
std::shared_ptr<const GameFile> AddOrGet(const std::string& path, bool* cache_changed,
const Core::TitleDatabase& title_database);
std::shared_ptr<const GameFile> AddOrGet(const std::string& path, bool* cache_changed);
// These functions return true if the call modified the cache.
bool Update(const std::vector<std::string>& all_game_paths,
std::function<void(const std::shared_ptr<const GameFile>&)> game_added_to_cache = {},
std::function<void(const std::string&)> game_removed_from_cache = {});
bool UpdateAdditionalMetadata(
const Core::TitleDatabase& title_database,
std::function<void(const std::shared_ptr<const GameFile>&)> game_updated = {});
bool Load();
bool Save();
private:
bool UpdateAdditionalMetadata(std::shared_ptr<GameFile>* game_file,
const Core::TitleDatabase& title_database);
bool UpdateAdditionalMetadata(std::shared_ptr<GameFile>* game_file);
bool SyncCacheFile(bool save);
void DoState(PointerWrap* p, u64 size = 0);