Use UICommon's game list code on Android

Deduplicates code, and gets rid of some problems the old code had
(such as: bad performance when calling native functions, only one
disc showing up for multi-disc games, Wii banners being low-res,
unnecessarily much effort being needed for adding more metadata).
This commit is contained in:
JosJuice
2018-06-01 09:36:29 +02:00
parent daee5a4b43
commit 1c027bc148
43 changed files with 976 additions and 1574 deletions

View File

@ -78,8 +78,15 @@ const std::string& GameFile::Lookup(DiscIO::Language language,
const std::string&
GameFile::LookupUsingConfigLanguage(const std::map<DiscIO::Language, std::string>& strings) const
{
#ifdef ANDROID
// TODO: Make the Android app load the config at app start instead of emulation start
// so that we can access the user's preference here
const DiscIO::Language language = DiscIO::Language::English;
#else
const bool wii = DiscIO::IsWii(m_platform);
return Lookup(SConfig::GetInstance().GetCurrentLanguage(wii), strings);
const DiscIO::Language language = SConfig::GetInstance().GetCurrentLanguage(wii);
#endif
return Lookup(language, strings);
}
GameFile::GameFile(const std::string& path)

View File

@ -12,6 +12,7 @@
#include <mutex>
#include <string>
#include <unordered_set>
#include <utility>
#include <vector>
#include "Common/ChunkFile.h"
@ -38,12 +39,25 @@ std::vector<std::string> FindAllGamePaths(const std::vector<std::string>& direct
return Common::DoFileSearch(directories_to_scan, search_extensions, recursive_scan);
}
GameFileCache::GameFileCache() : m_path(File::GetUserPath(D_CACHE_IDX) + "gamelist.cache")
{
}
GameFileCache::GameFileCache(std::string path) : m_path(std::move(path))
{
}
void GameFileCache::ForEach(std::function<void(const std::shared_ptr<const GameFile>&)> f) const
{
for (const std::shared_ptr<const GameFile>& item : m_cached_files)
f(item);
}
size_t GameFileCache::GetSize() const
{
return m_cached_files.size();
}
void GameFileCache::Clear()
{
m_cached_files.clear();
@ -179,9 +193,8 @@ bool GameFileCache::Save()
bool GameFileCache::SyncCacheFile(bool save)
{
std::string filename(File::GetUserPath(D_CACHE_IDX) + "gamelist.cache");
const char* open_mode = save ? "wb" : "rb";
File::IOFile f(filename, open_mode);
File::IOFile f(m_path, open_mode);
if (!f)
return false;
bool success = false;
@ -217,7 +230,7 @@ bool GameFileCache::SyncCacheFile(bool save)
{
// If some file operation failed, try to delete the probably-corrupted cache
f.Close();
File::Delete(filename);
File::Delete(m_path);
}
return success;
}

View File

@ -6,9 +6,7 @@
#include <cstddef>
#include <functional>
#include <list>
#include <memory>
#include <mutex>
#include <string>
#include <vector>
@ -26,8 +24,12 @@ std::vector<std::string> FindAllGamePaths(const std::vector<std::string>& direct
class GameFileCache
{
public:
GameFileCache(); // Uses the default path
explicit GameFileCache(std::string path);
void ForEach(std::function<void(const std::shared_ptr<const GameFile>&)> f) const;
size_t GetSize() const;
void Clear();
// Returns nullptr if the file is invalid.
@ -49,6 +51,7 @@ private:
bool SyncCacheFile(bool save);
void DoState(PointerWrap* p, u64 size = 0);
std::string m_path;
std::vector<std::shared_ptr<GameFile>> m_cached_files;
};