| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
#pragma once |
| 5 |
|
| 6 |
#include <atomic> |
| 7 |
#include <cstddef> |
| 8 |
#include <functional> |
| 9 |
#include <memory> |
| 10 |
#include <span> |
| 11 |
#include <string> |
| 12 |
#include <vector> |
| 13 |
|
| 14 |
#include "Common/CommonTypes.h" |
| 15 |
|
| 16 |
class PointerWrap; |
| 17 |
|
| 18 |
namespace UICommon |
| 19 |
{ |
| 20 |
class GameFile; |
| 21 |
|
| 22 |
std::vector<std::string> FindAllGamePaths(std::span<const std::string_view> directories_to_scan, |
| 23 |
bool recursive_scan); |
| 24 |
|
| 25 |
class GameFileCache |
| 26 |
{ |
| 27 |
public: |
| 28 |
enum class DeleteOnDisk |
| 29 |
{ |
| 30 |
No = 0, |
| 31 |
Yes = 1, |
| 32 |
}; |
| 33 |
|
| 34 |
using ForEachFn = std::function<void(const std::shared_ptr<const GameFile>&)>; |
| 35 |
using GameAddedToCacheFn = std::function<void(const std::shared_ptr<const GameFile>&)>; |
| 36 |
using GameRemovedFromCacheFn = std::function<void(const std::string&)>; |
| 37 |
using GameUpdatedFn = std::function<void(const std::shared_ptr<const GameFile>&)>; |
| 38 |
|
| 39 |
GameFileCache(); |
| 40 |
|
| 41 |
void ForEach(const ForEachFn& f) const; |
| 42 |
|
| 43 |
size_t GetSize() const; |
| 44 |
void Clear(DeleteOnDisk delete_on_disk); |
| 45 |
|
| 46 |
|
| 47 |
std::shared_ptr<const GameFile> AddOrGet(const std::string& path, bool* cache_changed); |
| 48 |
|
| 49 |
|
| 50 |
bool Update(std::span<const std::string> all_game_paths, |
| 51 |
const GameAddedToCacheFn& game_added_to_cache = {}, |
| 52 |
const GameRemovedFromCacheFn& game_removed_from_cache = {}, |
| 53 |
const std::atomic_bool& processing_halted = false); |
| 54 |
bool UpdateAdditionalMetadata(const GameUpdatedFn& game_updated = {}, |
| 55 |
const std::atomic_bool& processing_halted = false); |
| 56 |
|
| 57 |
bool Load(); |
| 58 |
bool Save(); |
| 59 |
|
| 60 |
private: |
| 61 |
bool UpdateAdditionalMetadata(std::shared_ptr<GameFile>* game_file); |
| 62 |
|
| 63 |
bool SyncCacheFile(bool save); |
| 64 |
void DoState(PointerWrap* p, u64 size = 0); |
| 65 |
|
| 66 |
std::string m_path; |
| 67 |
std::vector<std::shared_ptr<GameFile>> m_cached_files; |
| 68 |
}; |
| 69 |
|
| 70 |
} |