forked from rainmeter/rainmeter
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRainmeter.h
309 lines (227 loc) · 9.74 KB
/
Rainmeter.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
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
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
/* Copyright (C) 2001 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 __RAINMETER_H__
#define __RAINMETER_H__
#include <windows.h>
#include <map>
#include <vector>
#include <list>
#include <string>
#include "CommandHandler.h"
#include "ContextMenu.h"
#include "DialogManage.h"
#include "Logger.h"
#include "Skin.h"
#include "SkinRegistry.h"
#define MAX_LINE_LENGTH 4096
#define APPNAME L"Rainmeter"
#ifdef _WIN64
#define APPBITS L"64-bit"
#else
#define APPBITS L"32-bit"
#endif
#define WIDEN2(x) L ## x
#define WIDEN(x) WIDEN2(x)
#define APPDATE WIDEN(__DATE__)
#define RAINMETER_CLASS_NAME L"DummyRainWClass"
#define RAINMETER_WINDOW_NAME L"Rainmeter control window"
#define WM_RAINMETER_DELAYED_REFRESH_ALL WM_APP + 0
#define WM_RAINMETER_DELAYED_EXECUTE WM_APP + 1
#define WM_RAINMETER_EXECUTE WM_APP + 2
struct GlobalOptions
{
double netInSpeed;
double netOutSpeed;
};
class ConfigParser;
class TrayIcon;
class Rainmeter
{
public:
static Rainmeter& GetInstance();
int Initialize(LPCWSTR iniPath, LPCWSTR layout, bool safeStart);
void Finalize();
void RestartRainmeter();
bool IsAlreadyRunning();
int MessagePump();
void SetNetworkStatisticsTimer();
ConfigParser* GetCurrentParser() { return m_CurrentParser; }
void SetCurrentParser(ConfigParser* parser) { m_CurrentParser = parser; }
TrayIcon* GetTrayIcon() { return m_TrayIcon; }
bool HasSkin(const Skin* skin) const;
Skin* GetSkin(std::wstring folderPath);
Skin* GetSkinByINI(const std::wstring& ini_searching);
Skin* GetSkin(HWND hwnd);
void GetSkinsByLoadOrder(std::multimap<int, Skin*>& windows, const std::wstring& group = std::wstring());
std::map<std::wstring, Skin*>& GetAllSkins() { return m_Skins; }
const std::vector<std::wstring>& GetAllLayouts() { return m_Layouts; }
void RemoveSkin(Skin* skin);
void AddUnmanagedSkin(Skin* skin);
void RemoveUnmanagedSkin(Skin* skin);
bool ActivateSkin(const std::wstring& folderPath);
bool ActivateSkin(const std::wstring& folderPath, const std::wstring& file);
void ActivateSkin(int folderIndex, int fileIndex);
void DeactivateSkin(Skin* skin, int folderIndex, bool save = true);
void ToggleSkin(int folderIndex, int fileIndex);
void ToggleSkinWithID(UINT id);
const std::wstring& GetPath() { return m_Path; }
const std::wstring& GetIniFile() { return m_IniFile; }
const std::wstring& GetDataFile() { return m_DataFile; }
const std::wstring& GetSettingsPath() { return m_SettingsPath; }
const std::wstring& GetSkinPath() { return m_SkinPath; }
void SetSkinPath(const std::wstring& skinPath);
std::wstring GetLayoutPath() { return m_SettingsPath + L"Layouts\\"; }
std::wstring GetPluginPath() { return m_Path + L"Plugins\\"; }
std::wstring GetUserPluginPath() { return m_SettingsPath + L"Plugins\\"; }
std::wstring GetAddonPath() { return m_SettingsPath + L"Addons\\"; }
bool HasUserPluginPath() { return (_wcsicmp(m_Path.c_str(), m_SettingsPath.c_str()) != 0); }
std::wstring GetDefaultSkinPath() { return m_Path + L"Defaults\\Skins\\"; }
std::wstring GetDefaultLayoutPath() { return m_Path + L"Defaults\\Layouts\\"; }
std::wstring GetDefaultPluginPath() { return m_Path + L"Defaults\\Plugins\\"; }
std::wstring GetDefaultAddonPath() { return m_Path + L"Defaults\\Addons\\"; }
const std::wstring& GetDrive() { return m_Drive; }
const std::wstring& GetSkinEditor() { return m_SkinEditor; }
void SetSkinEditor(const std::wstring& path);
const std::wstring& GetStatsDate() { return m_StatsDate; }
bool IsHardwareAccelerated() { return m_HardwareAccelerated; }
void SetHardwareAccelerated(bool hardwareAccelerated);
HWND GetWindow() { return m_Window; }
HINSTANCE GetModuleInstance() { return m_Instance; }
HINSTANCE GetResourceInstance() { return m_ResourceInstance; }
LCID GetResourceLCID() { return m_ResourceLCID; }
bool GetDebug() { return m_Debug; }
GlobalOptions& GetGlobalOptions() { return m_GlobalOptions; }
void ReloadSettings();
void EditSettings();
void EditSkinFile(const std::wstring& name, const std::wstring& iniFile);
void OpenSkinFolder(const std::wstring& name = std::wstring());
bool DoesSkinHaveSettings(const std::wstring& folderPath);
void ReadStats();
void WriteStats(bool bForce);
void ResetStats();
bool GetDisableVersionCheck() { return m_DisableVersionCheck; }
void SetDisableVersionCheck(bool check);
bool GetNewVersion() { return m_NewVersion; }
void SetNewVersion() { m_NewVersion = true; }
bool GetDisableAutoUpdate() { return m_DisableAutoUpdate; }
void SetDisableAutoUpdate(bool check);
bool GetDownloadedNewVersion() { return m_DownloadedNewVersion; }
void SetDownloadedNewVersion() { m_DownloadedNewVersion = true; }
bool GetLanguageStatus() { return m_LanguageObsolete; }
void SetLanguageStatus(bool status) { m_LanguageObsolete = status; DialogManage::UpdateLanguageStatus(); }
void ShowLogFile();
bool GetDisableRDP() { return m_DisableRDP; }
bool IsRedrawable() { return (!GetDisableRDP() || !GetSystemMetrics(SM_REMOTESESSION)); }
bool GetDisableDragging() { return m_DisableDragging; }
void SetDisableDragging(bool dragging);
bool IsNormalStayDesktop() { return m_NormalStayDesktop; }
void SetDebug(bool debug);
int ShowMessage(HWND parent, const WCHAR* text, UINT type);
bool IsMenuActive() { return m_ContextMenu.IsMenuActive(); }
void ShowContextMenu(POINT pos, Skin* skin) { return m_ContextMenu.ShowMenu(pos, skin); }
void ShowSkinCustomContextMenu(POINT pos, Skin* skin) { return m_ContextMenu.ShowSkinCustomMenu(pos, skin); }
const std::wstring& GetTrayExecuteR() { return m_TrayExecuteR; }
const std::wstring& GetTrayExecuteM() { return m_TrayExecuteM; }
const std::wstring& GetTrayExecuteDR() { return m_TrayExecuteDR; }
const std::wstring& GetTrayExecuteDM() { return m_TrayExecuteDM; }
void ExecuteBang(const WCHAR* bang, std::vector<std::wstring>& args, Skin* skin);
void ExecuteCommand(const WCHAR* command, Skin* skin, bool multi = true);
void DelayedExecuteCommand(const WCHAR* command, Skin* skin = nullptr);
void ExecuteActionCommand(const WCHAR* command, Section* section);
void RefreshAll();
bool LoadLayout(const std::wstring& name);
void PreserveSetting(const std::wstring& from, LPCTSTR key, bool replace = true);
bool IsSkinAFavorite(const std::wstring& folder, const std::wstring& filename);
void UpdateFavorites(const std::wstring& folder, const std::wstring& file, bool favorite);
D2D1_COLOR_F& GetDefaultSelectionColor() { return m_DefaultSelectedColor; }
const std::wstring& GetBuildTime() { return m_BuildTime; }
static const std::vector<LPCWSTR>& GetOldDefaultPlugins();
friend class CommandHandler;
friend class ContextMenu;
friend class DialogManage;
friend class DialogNewSkin;
friend class GameMode;
private:
Rainmeter();
~Rainmeter();
Rainmeter(const Rainmeter& other) = delete;
Rainmeter& operator=(Rainmeter other) = delete;
static LRESULT CALLBACK MainWndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
void ActivateActiveSkins();
void CreateSkin(const std::wstring& folderPath, const std::wstring& file, bool hasSettings);
void DeleteAllSkins();
void DeleteAllUnmanagedSkins();
void WriteActive(const std::wstring& folderPath, int fileIndex);
void ScanForSkins();
void ScanForLayouts();
void ReadFavorites();
void ReadGeneralSettings(const std::wstring& iniFile);
void SetLoadOrder(int folderIndex, int order);
int GetLoadOrder(const std::wstring& folderPath);
void UpdateDesktopWorkArea(bool reset);
void CreateOptionsFile();
void CreateDataFile();
void CreateComponentFolders(bool defaultIniLocation);
void TestSettingsFile(bool bDefaultIniLocation);
void CheckSettingsFileEncoding(const std::wstring& iniFile, std::wstring* log);
void ShowTrayIconIfNecessary();
TrayIcon* m_TrayIcon;
std::multimap<int, int> m_SkinOrders;
std::map<std::wstring, Skin*> m_Skins;
std::list<Skin*> m_UnmanagedSkins;
std::vector<std::wstring> m_Layouts;
std::vector<std::wstring> m_Favorites;
std::wstring m_Path;
std::wstring m_IniFile;
std::wstring m_DataFile;
std::wstring m_StatsFile;
std::wstring m_SettingsPath;
std::wstring m_SkinPath;
std::wstring m_Drive;
std::wstring m_StatsDate;
std::wstring m_TrayExecuteR;
std::wstring m_TrayExecuteM;
std::wstring m_TrayExecuteDR;
std::wstring m_TrayExecuteDM;
bool m_Debug;
bool m_DisableVersionCheck;
bool m_NewVersion;
bool m_DisableAutoUpdate;
bool m_DownloadedNewVersion;
bool m_LanguageObsolete;
bool m_HardwareAccelerated;
bool m_DesktopWorkAreaChanged;
bool m_DesktopWorkAreaType;
std::map<UINT, RECT> m_DesktopWorkAreas;
std::vector<RECT> m_OldDesktopWorkAreas;
bool m_NormalStayDesktop;
bool m_DisableRDP;
bool m_DisableDragging;
std::wstring m_SkinEditor;
D2D1_COLOR_F m_DefaultSelectedColor;
CommandHandler m_CommandHandler;
ContextMenu m_ContextMenu;
SkinRegistry m_SkinRegistry;
ConfigParser* m_CurrentParser;
HWND m_Window;
HANDLE m_Mutex;
HINSTANCE m_Instance;
HMODULE m_ResourceInstance;
LCID m_ResourceLCID;
ULONG_PTR m_GDIplusToken;
GlobalOptions m_GlobalOptions;
std::wstring m_BuildTime;
};
// Convenience function.
inline Rainmeter& GetRainmeter() { return Rainmeter::GetInstance(); }
#ifdef LIBRARY_EXPORTS
#define EXPORT_PLUGIN EXTERN_C
#else
#define EXPORT_PLUGIN EXTERN_C __declspec(dllimport)
#endif
EXPORT_PLUGIN int RainmeterMain(LPWSTR cmdLine);
#endif