Repository navigation
Expand file tree
/
Copy pathPoggetStorageProvider.cpp
More file actions
187 lines (174 loc) · 10 KB
/
Copy pathPoggetStorageProvider.cpp
File metadata and controls
187 lines (174 loc) · 10 KB
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
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
#include "../framework.h"
#include "PoggetStorageProvider.hpp"
#include <iostream>
namespace PoggetCore {
static std::wstring FormatCompKey(const std::wstring& id) {
if (id.rfind(L"ComID_", 0) == 0) return id;
return L"ComID_" + id;
}
void PoggetStorageProvider::Initialize(const std::wstring& filePath) {
std::lock_guard<std::mutex> lock(m_mutex);
m_filePath = filePath;
try {
std::filesystem::path p(filePath);
std::wstring backupPath = (p.parent_path() / L"Backups" / L"BufferBak" / p.filename()).wstring();
m_storage.SetBackupPath(backupPath);
const auto result = m_storage.TryLoad(filePath);
m_isInitialized = result.ok();
if (!result.ok()) {
std::cerr << "PoggetStorageProvider Init Error: " << result.message << std::endl;
}
} catch (const std::exception& e) {
std::cerr << "PoggetStorageProvider Init Error: " << e.what() << std::endl;
m_isInitialized = false;
}
}
bool PoggetStorageProvider::IsInitialized() const {
std::lock_guard<std::mutex> lock(m_mutex);
return m_isInitialized;
}
void PoggetStorageProvider::SubmitContainerModel(const ContainerModel& model) {
std::lock_guard<std::mutex> lock(m_mutex);
if (model.id.empty()) return;
std::wstring key = FormatCompKey(model.id);
auto proxy = m_storage[L"Components"][key];
proxy[L"id"] = model.id;
proxy[L"alias"] = model.alias;
proxy[L"title"] = model.title;
proxy[L"IsMinimized"] = model.IsMinimized;
proxy[L"IsIntegrated"] = model.IsIntegrated;
proxy[L"IsMergedHost"] = model.IsMergedHost;
proxy[L"MergedHostColor"] = model.MergedHostColor;
proxy[L"MergedHostId"] = model.MergedHostId;
proxy[L"UseTargetFolder"] = model.UseTargetFolder;
proxy[L"TargetFolder"] = model.TargetFolder;
proxy[L"IsCustomTarget"] = model.IsCustomTarget;
proxy[L"SortMode"] = model.SortMode;
proxy[L"IconSizeLevel"] = model.IconSizeLevel;
proxy[L"ShowDefaultFolderIcon"] = model.ShowDefaultFolderIcon;
proxy[L"ShowTextPreview"] = model.ShowTextPreview;
proxy[L"ShowMediaPreview"] = model.ShowMediaPreview;
proxy[L"HideFileExtension"] = model.HideFileExtension;
proxy[L"IconSpacingMode"] = model.IconSpacingMode;
proxy[L"IconSpacingType"] = model.IconSpacingType;
proxy[L"IsListView"] = model.IsListView;
proxy[L"TextRenderMode"] = model.TextRenderMode;
proxy[L"FileNameColorMode"] = model.FileNameColorMode;
proxy[L"TitleType"] = model.TitleType;
proxy[L"TagStyle"] = model.TagStyle;
proxy[L"ListDetailType"] = model.ListDetailType;
proxy[L"fontFamily"] = model.fontFamily;
proxy[L"DisableLayoutAnimations"] = model.DisableLayoutAnimations;
proxy[L"IsLocked"] = model.IsLocked;
proxy[L"IsPositionLocked"] = model.IsPositionLocked;
proxy[L"IsEmbeddedLayer"] = model.IsEmbeddedLayer;
proxy[L"IsUpwardExpand"] = model.IsUpwardExpand;
proxy[L"TransparentFrameMode"] = model.TransparentFrameMode;
proxy[L"AutoHideTitleBar"] = model.AutoHideTitleBar;
proxy[L"QuickExpandCollapse"] = model.QuickExpandCollapse;
proxy[L"AutoFade"] = model.AutoFade;
proxy[L"FadeOutSwitch"] = model.FadeOutSwitch;
proxy[L"AutoFadeDragStat"] = model.AutoFadeDragStat;
proxy[L"FolderOpenMode"] = model.FolderOpenMode;
proxy[L"SwipeUpSearchEnabled"] = model.SwipeUpSearchEnabled;
proxy[L"bgAlpha"] = model.backgroundAlpha;
proxy[L"titleAlpha"] = model.titleAlpha;
proxy[L"CompatibleLayer"] = model.CompatibleLayer;
proxy[L"DwmCornerPreference"] = model.DwmCornerPreference;
proxy[L"EnableStaticMaterialLayerForD3D11"] = model.EnableStaticMaterialLayerForD3D11;
proxy[L"EnableDynamicMaterialLayerForD3D11"] = model.EnableDynamicMaterialLayerForD3D11;
proxy[L"cornerRad"] = model.cornerRad;
proxy[L"shadowBlur"] = model.shadowBlur;
proxy[L"shadowAlpha"] = model.shadowAlpha;
proxy[L"shadowOffsetX"] = model.shadowOffsetX;
proxy[L"shadowOffsetY"] = model.shadowOffsetY;
proxy[L"EnableInlineFolderView"] = model.EnableInlineFolderView;
proxy[L"textSize"] = model.textSize;
proxy[L"TextOmitOffset"] = model.TextOmitOffset;
proxy[L"AllowTextWrapOverflow"] = model.AllowTextWrapOverflow;
}
bool PoggetStorageProvider::LoadContainerModel(const std::wstring& containerId, ContainerModel& outModel) {
std::lock_guard<std::mutex> lock(m_mutex);
if (containerId.empty()) return false;
std::wstring key = FormatCompKey(containerId);
outModel.id = containerId;
if (!m_storage.HasNestedObject(L"Components", key)) {
return false;
}
auto proxy = m_storage[L"Components"][key];
outModel.alias = proxy[L"alias"].get<std::wstring>(L"");
outModel.title = proxy[L"title"].get<std::wstring>(L"Unnamed");
outModel.IsMinimized = proxy[L"IsMinimized"].get<bool>(false);
outModel.IsIntegrated = proxy[L"IsIntegrated"].get<bool>(false);
outModel.IsMergedHost = proxy[L"IsMergedHost"].get<bool>(false);
outModel.MergedHostColor = proxy[L"MergedHostColor"].get<std::wstring>(L"");
outModel.MergedHostId = proxy[L"MergedHostId"].get<std::wstring>(L"");
outModel.UseTargetFolder = proxy[L"UseTargetFolder"].get<bool>(false);
outModel.TargetFolder = proxy[L"TargetFolder"].get<std::wstring>(L"vui!NULL");
outModel.IsCustomTarget = proxy[L"IsCustomTarget"].get<bool>(false);
outModel.SortMode = proxy[L"SortMode"].get<int>(0);
outModel.IconSizeLevel = proxy[L"IconSizeLevel"].get<int>(3);
outModel.ShowDefaultFolderIcon = proxy[L"ShowDefaultFolderIcon"].get<bool>(false);
outModel.ShowTextPreview = proxy[L"ShowTextPreview"].get<bool>(true);
outModel.ShowMediaPreview = proxy[L"ShowMediaPreview"].get<bool>(true);
outModel.HideFileExtension = proxy[L"HideFileExtension"].get<int>(0);
outModel.IconSpacingMode = proxy[L"IconSpacingMode"].get<int>(0);
outModel.IconSpacingType = proxy[L"IconSpacingType"].get<int>(0);
outModel.IsListView = proxy[L"IsListView"].get<bool>(false);
outModel.TextRenderMode = proxy[L"TextRenderMode"].get<int>(0);
outModel.FileNameColorMode = proxy[L"FileNameColorMode"].get<int>(0);
outModel.TitleType = proxy[L"TitleType"].get<int>(0);
outModel.TagStyle = proxy[L"TagStyle"].get<int>(0);
outModel.ListDetailType = proxy[L"ListDetailType"].get<int>(0);
outModel.fontFamily = proxy[L"fontFamily"].get<std::wstring>(L"Segoe UI");
outModel.DisableLayoutAnimations = proxy[L"DisableLayoutAnimations"].get<bool>(false);
outModel.IsLocked = proxy[L"IsLocked"].get<bool>(false);
outModel.IsPositionLocked = proxy[L"IsPositionLocked"].get<bool>(outModel.IsLocked);
outModel.IsEmbeddedLayer = proxy[L"IsEmbeddedLayer"].get<bool>(false);
outModel.IsUpwardExpand = proxy[L"IsUpwardExpand"].get<bool>(false);
outModel.TransparentFrameMode = proxy[L"TransparentFrameMode"].get<int>(0);
outModel.AutoHideTitleBar = proxy[L"AutoHideTitleBar"].get<int>(0);
outModel.QuickExpandCollapse = proxy[L"QuickExpandCollapse"].get<int>(1);
outModel.AutoFade = proxy[L"AutoFade"].get<int>(0);
outModel.FadeOutSwitch = proxy[L"FadeOutSwitch"].get<bool>(false);
outModel.AutoFadeDragStat = proxy[L"AutoFadeDragStat"].get<bool>(false);
outModel.FolderOpenMode = proxy[L"FolderOpenMode"].get<int>(0);
outModel.SwipeUpSearchEnabled = proxy[L"SwipeUpSearchEnabled"].get<bool>(true);
outModel.backgroundAlpha = static_cast<float>(proxy[L"bgAlpha"].get<double>(1.0));
outModel.titleAlpha = static_cast<float>(proxy[L"titleAlpha"].get<double>(1.0));
outModel.CompatibleLayer = proxy[L"CompatibleLayer"].get<int>(0);
outModel.DwmCornerPreference = proxy[L"DwmCornerPreference"].get<int>(0);
outModel.EnableStaticMaterialLayerForD3D11 = proxy[L"EnableStaticMaterialLayerForD3D11"].get<bool>(false);
outModel.EnableDynamicMaterialLayerForD3D11 = proxy[L"EnableDynamicMaterialLayerForD3D11"].get<bool>(false);
outModel.cornerRad = static_cast<float>(proxy[L"cornerRad"].get<double>(16.0));
outModel.shadowBlur = static_cast<float>(proxy[L"shadowBlur"].get<double>(16.0));
outModel.shadowAlpha = static_cast<float>(proxy[L"shadowAlpha"].get<double>(0.2));
outModel.shadowOffsetX = static_cast<float>(proxy[L"shadowOffsetX"].get<double>(0.0));
outModel.shadowOffsetY = static_cast<float>(proxy[L"shadowOffsetY"].get<double>(4.0));
outModel.EnableInlineFolderView = proxy[L"EnableInlineFolderView"].get<bool>(true);
outModel.textSize = static_cast<float>(proxy[L"textSize"].get<double>(10.0));
outModel.TextOmitOffset = std::clamp(proxy[L"TextOmitOffset"].get<int>(0), -6, 6);
outModel.AllowTextWrapOverflow = proxy[L"AllowTextWrapOverflow"].get<bool>(false);
return true;
}
void PoggetStorageProvider::RemoveContainerModel(const std::wstring& containerId) {
std::lock_guard<std::mutex> lock(m_mutex);
if (containerId.empty()) return;
std::wstring key = FormatCompKey(containerId);
m_storage[L"Components"][key].remove();
}
bool PoggetStorageProvider::SaveStorage() {
std::lock_guard<std::mutex> lock(m_mutex);
if (m_filePath.empty() || !m_isInitialized) return false;
const auto result = m_storage.TrySave();
if (!result.ok()) {
std::cerr << "PoggetStorageProvider Save Error: " << result.message << std::endl;
return false;
}
return true;
}
void ContainerModel::Save() {
PoggetStorageProvider::GetInstance().SubmitContainerModel(*this);
PoggetStorageProvider::GetInstance().SaveStorage();
}
} // namespace PoggetCore