forked from rainmeter/rainmeter
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSkinRegistry.h
118 lines (91 loc) · 3.14 KB
/
SkinRegistry.h
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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
/* Copyright (C) 2013 Rainmeter Project Developers
*
* This Source Code Form is subject to the terms of the GNU General Public
* License; either version 2 of the License, or (at your option) any later
* version. If a copy of the GPL was not distributed with this file, You can
* obtain one at <https://www.gnu.org/licenses/gpl-2.0.html>. */
#ifndef RM_LIBRARY_SKINDIRECTORY_H_
#define RM_LIBRARY_SKINDIRECTORY_H_
#include <Windows.h>
#include <string>
#include <vector>
#include <cstdint>
// Reprsents a hierarchy of skin folders (reprsented by the Folder struct) and the names of their
// respective files.
class SkinRegistry
{
public:
SkinRegistry() = default;
SkinRegistry(const SkinRegistry& other) = delete;
SkinRegistry& operator=(SkinRegistry other) = delete;
struct File
{
std::wstring filename;
bool isFavorite;
File() : isFavorite(false) {}
~File() {}
File(std::wstring name) : filename(name), isFavorite(false) {}
const bool operator==(const File& rhs) const
{
return (rhs.filename == filename) && (rhs.isFavorite == isFavorite);
}
};
struct Folder
{
std::wstring name;
std::vector<SkinRegistry::File> files;
UINT baseID;
int16_t active;
int16_t level;
bool hasFavorite;
Folder() : baseID(0U), active(0), level(0), hasFavorite(false) {}
~Folder() {}
Folder(Folder&& r) noexcept :
name(std::move(r.name)),
files(std::move(r.files)),
baseID(r.baseID),
active(r.active),
level(r.level),
hasFavorite(r.hasFavorite)
{
}
Folder& operator=(Folder&& r) noexcept
{
name = std::move(r.name);
files = std::move(r.files);
baseID = r.baseID;
active = r.active;
level = r.level;
hasFavorite = r.hasFavorite;
return *this;
}
};
struct Indexes
{
int folder;
int file;
Indexes(int folderIndex = 0, int fileIndex = 0) : folder(folderIndex), file(fileIndex) {}
bool IsValid() const { return folder != -1; }
static Indexes Invalid() { return Indexes(-1, 0); }
};
int FindFolderIndex(std::wstring folderPath) const;
Folder* FindFolder(const std::wstring& folderPath);
Indexes FindIndexes(const std::wstring& folderPath, const std::wstring& file);
Indexes FindIndexesForID(UINT id);
std::wstring GetFolderPath(int folderIndex) const;
Folder& GetFolder(int index) { return m_Folders[index]; }
int GetFolderCount() const { return (int)m_Folders.size(); }
bool IsEmpty() const { return m_Folders.empty(); }
void Populate(const std::wstring& path, std::vector<std::wstring>& favorites);
std::vector<std::wstring> UpdateFavorite(const std::wstring& config, const std::wstring& filename, bool favorite);
private:
int PopulateRecursive(const std::wstring& path, std::vector<std::wstring>& favorites, std::wstring base, int index, UINT level);
std::vector<std::wstring> ValidateFavorites();
// Contains a sequential list of Folders. The folders are arranged as follows:
// A (index: 0, level: 1)
// B (index: 1, level: 2)
// C (index: 2, level: 3)
// D (index: 3, level: 2)
std::vector<Folder> m_Folders;
};
#endif