summaryrefslogtreecommitdiff
path: root/Source/Core/UICommon/GameFileCache.h
blob: 2e09c6da164cd8b605e62dab65829d9400bd0fe4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
// Copyright 2017 Dolphin Emulator Project
// Licensed under GPLv2+
// Refer to the license.txt file included.

#pragma once

#include <cstddef>
#include <functional>
#include <memory>
#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:
  enum class DeleteOnDisk
  {
    No = 0,
    Yes = 1,
  };

  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(DeleteOnDisk delete_on_disk);

  // Returns nullptr if the file is invalid.
  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(
      std::function<void(const std::shared_ptr<const GameFile>&)> game_updated = {});

  bool Load();
  bool Save();

private:
  bool UpdateAdditionalMetadata(std::shared_ptr<GameFile>* game_file);

  bool SyncCacheFile(bool save);
  void DoState(PointerWrap* p, u64 size = 0);

  std::string m_path;
  std::vector<std::shared_ptr<GameFile>> m_cached_files;
};

}  // namespace UICommon