summaryrefslogtreecommitdiff
path: root/src/shared/filesorigin.h
blob: 4ea21f57d751a9f065fef138a3853de938e5f862 (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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
#ifndef MO_REGISTER_FILESORIGIN_INCLUDED
#define MO_REGISTER_FILESORIGIN_INCLUDED

#include "fileregisterfwd.h"

namespace MOShared
{

// represents a mod or the data directory, providing files to the tree
class FilesOrigin
{
public:
  FilesOrigin();
//  FilesOrigin(const FilesOrigin &reference);

  FilesOrigin(
    int ID, const std::wstring &name, const std::wstring &path, int priority,
    boost::shared_ptr<FileRegister> fileRegister,
    boost::shared_ptr<OriginConnection> originConnection);

  // noncopyable
  FilesOrigin(const FilesOrigin&) = delete;
  FilesOrigin& operator=(const FilesOrigin&) = delete;
  FilesOrigin(FilesOrigin&&) = default;
  FilesOrigin& operator=(FilesOrigin&&) = default;

  // sets priority for this origin, but it will overwrite the existing mapping
  // for this priority, the previous origin will no longer be referenced
  void setPriority(int priority);

  int getPriority() const
  {
    return m_Priority;
  }

  void setName(const std::wstring &name);
  const std::wstring &getName() const
  {
    return m_Name;
  }

  int getID() const
  {
    return m_ID;
  }

  const std::wstring &getPath() const
  {
    return m_Path;
  }

  std::vector<FileEntryPtr> getFiles() const;
  FileEntryPtr findFile(FileIndex index) const;

  void enable(bool enabled, DirectoryStats& stats);
  void enable(bool enabled);

  bool isDisabled() const
  {
    return m_Disabled;
  }

  void addFile(FileIndex index)
  {
    std::scoped_lock lock(m_Mutex);
    m_Files.insert(index);
  }

  void removeFile(FileIndex index);

  bool containsArchive(std::wstring archiveName);

private:
  int m_ID;
  bool m_Disabled;
  std::set<FileIndex> m_Files;
  std::wstring m_Name;
  std::wstring m_Path;
  int m_Priority;
  boost::weak_ptr<FileRegister> m_FileRegister;
  boost::weak_ptr<OriginConnection> m_OriginConnection;
  mutable std::mutex m_Mutex;
};

} // namespace

#endif // MO_REGISTER_FILESORIGIN_INCLUDED