2017-12-31 19:33:36 +00:00
|
|
|
// Copyright 2017 Dolphin Emulator Project
|
2021-07-05 01:22:19 +00:00
|
|
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
2017-12-31 19:33:36 +00:00
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
2020-09-27 02:01:54 +00:00
|
|
|
#include <atomic>
|
2017-12-31 19:33:36 +00:00
|
|
|
#include <cstddef>
|
|
|
|
#include <functional>
|
|
|
|
#include <memory>
|
2023-12-11 16:12:06 +00:00
|
|
|
#include <span>
|
2017-12-31 19:33:36 +00:00
|
|
|
#include <string>
|
|
|
|
#include <vector>
|
|
|
|
|
|
|
|
#include "Common/CommonTypes.h"
|
|
|
|
|
|
|
|
class PointerWrap;
|
|
|
|
|
|
|
|
namespace UICommon
|
|
|
|
{
|
|
|
|
class GameFile;
|
|
|
|
|
|
|
|
std::vector<std::string> FindAllGamePaths(const std::vector<std::string>& directories_to_scan,
|
|
|
|
bool recursive_scan);
|
|
|
|
|
|
|
|
class GameFileCache
|
|
|
|
{
|
|
|
|
public:
|
2018-10-14 16:03:10 +00:00
|
|
|
enum class DeleteOnDisk
|
|
|
|
{
|
|
|
|
No = 0,
|
|
|
|
Yes = 1,
|
|
|
|
};
|
|
|
|
|
2023-12-11 16:04:26 +00:00
|
|
|
using ForEachFn = std::function<void(const std::shared_ptr<const GameFile>&)>;
|
|
|
|
using GameAddedToCacheFn = std::function<void(const std::shared_ptr<const GameFile>&)>;
|
|
|
|
using GameRemovedFromCacheFn = std::function<void(const std::string&)>;
|
|
|
|
using GameUpdatedFn = std::function<void(const std::shared_ptr<const GameFile>&)>;
|
|
|
|
|
2021-06-08 16:09:22 +00:00
|
|
|
GameFileCache();
|
2018-06-01 07:36:29 +00:00
|
|
|
|
2023-12-11 16:04:26 +00:00
|
|
|
void ForEach(const ForEachFn& f) const;
|
2017-12-31 19:33:36 +00:00
|
|
|
|
2018-06-01 07:36:29 +00:00
|
|
|
size_t GetSize() const;
|
2018-10-14 16:03:10 +00:00
|
|
|
void Clear(DeleteOnDisk delete_on_disk);
|
2017-12-31 19:33:36 +00:00
|
|
|
|
2018-03-29 19:52:21 +00:00
|
|
|
// Returns nullptr if the file is invalid.
|
2018-06-03 10:07:53 +00:00
|
|
|
std::shared_ptr<const GameFile> AddOrGet(const std::string& path, bool* cache_changed);
|
2017-12-31 19:33:36 +00:00
|
|
|
|
|
|
|
// These functions return true if the call modified the cache.
|
2023-12-11 16:12:06 +00:00
|
|
|
bool Update(std::span<const std::string> all_game_paths,
|
2023-12-11 16:04:26 +00:00
|
|
|
const GameAddedToCacheFn& game_added_to_cache = {},
|
|
|
|
const GameRemovedFromCacheFn& game_removed_from_cache = {},
|
2020-09-27 02:01:54 +00:00
|
|
|
const std::atomic_bool& processing_halted = false);
|
2023-12-11 16:04:26 +00:00
|
|
|
bool UpdateAdditionalMetadata(const GameUpdatedFn& game_updated = {},
|
|
|
|
const std::atomic_bool& processing_halted = false);
|
2017-12-31 19:33:36 +00:00
|
|
|
|
|
|
|
bool Load();
|
|
|
|
bool Save();
|
|
|
|
|
|
|
|
private:
|
2018-06-03 10:07:53 +00:00
|
|
|
bool UpdateAdditionalMetadata(std::shared_ptr<GameFile>* game_file);
|
2017-12-31 19:33:36 +00:00
|
|
|
|
|
|
|
bool SyncCacheFile(bool save);
|
|
|
|
void DoState(PointerWrap* p, u64 size = 0);
|
|
|
|
|
2018-06-01 07:36:29 +00:00
|
|
|
std::string m_path;
|
2017-12-31 19:33:36 +00:00
|
|
|
std::vector<std::shared_ptr<GameFile>> m_cached_files;
|
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace UICommon
|