forked from rainmeter/rainmeter
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathExport.cpp
249 lines (205 loc) · 5.78 KB
/
Export.cpp
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
/* Copyright (C) 2011 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>. */
#include "StdAfx.h"
#include "Rainmeter.h"
#include "Export.h"
#include "Skin.h"
#include "Measure.h"
#include "MeasurePlugin.h"
#define NULLCHECK(str) { if ((str) == nullptr) { (str) = L""; } }
static std::wstring g_Buffer;
LPCWSTR __stdcall RmReadString(void* rm, LPCWSTR option, LPCWSTR defValue, BOOL replaceMeasures)
{
NULLCHECK(option);
NULLCHECK(defValue);
MeasurePlugin* measure = (MeasurePlugin*)rm;
ConfigParser& parser = measure->GetSkin()->GetParser();
return parser.ReadString(measure->GetName(), option, defValue, replaceMeasures != FALSE).c_str();
}
double __stdcall RmReadFormula(void* rm, LPCWSTR option, double defValue)
{
NULLCHECK(option);
MeasurePlugin* measure = (MeasurePlugin*)rm;
ConfigParser& parser = measure->GetSkin()->GetParser();
return parser.ReadFloat(measure->GetName(), option, defValue);
}
LPCWSTR __stdcall RmReplaceVariables(void* rm, LPCWSTR str)
{
NULLCHECK(str);
MeasurePlugin* measure = (MeasurePlugin*)rm;
ConfigParser& parser = measure->GetSkin()->GetParser();
g_Buffer = str;
parser.ReplaceVariables(g_Buffer);
parser.ReplaceMeasures(g_Buffer);
return g_Buffer.c_str();
}
LPCWSTR __stdcall RmPathToAbsolute(void* rm, LPCWSTR relativePath)
{
NULLCHECK(relativePath);
MeasurePlugin* measure = (MeasurePlugin*)rm;
g_Buffer = relativePath;
measure->GetSkin()->MakePathAbsolute(g_Buffer);
return g_Buffer.c_str();
}
void* __stdcall RmGet(void* rm, int type)
{
MeasurePlugin* measure = (MeasurePlugin*)rm;
switch (type)
{
case RMG_MEASURENAME:
{
return (void*)measure->GetName();
}
case RMG_SKIN:
{
return (void*)measure->GetSkin();
}
case RMG_SETTINGSFILE:
{
return (void*)GetRainmeter().GetDataFile().c_str();
}
case RMG_SKINNAME:
{
Skin* window = measure->GetSkin();
if (!window) break;
return (void*)window->GetFolderPath().c_str();
}
case RMG_SKINWINDOWHANDLE:
{
Skin* window = measure->GetSkin();
if (!window) break;
return (void*)window->GetWindow();
}
}
return nullptr;
}
void __stdcall RmExecute(void* skin, LPCWSTR command)
{
if (command)
{
// WM_RAINMETER_EXECUTE used instead of ExecuteCommand for thread-safety
SendMessage(GetRainmeter().GetWindow(), WM_RAINMETER_EXECUTE, (WPARAM)skin, (LPARAM)command);
}
}
BOOL LSLog(int level, LPCWSTR unused, LPCWSTR message)
{
NULLCHECK(message);
// Ignore Debug messages from plugins unless in debug mode.
if (level != (int)Logger::Level::Debug || GetRainmeter().GetDebug())
{
GetLogger().Log((Logger::Level)level, L"", message);
}
return TRUE;
}
void __stdcall RmLog(void* rm, int level, LPCWSTR message)
{
NULLCHECK(message);
MeasurePlugin* measure = (MeasurePlugin*)rm;
// Ignore Debug messages from plugins unless in debug mode.
if (level != (int)Logger::Level::Debug || GetRainmeter().GetDebug())
{
GetLogger().LogSection((Logger::Level)level, measure, message);
}
}
void RmLogF(void* rm, int level, LPCWSTR format, ...)
{
NULLCHECK(format);
MeasurePlugin* measure = (MeasurePlugin*)rm;
// Ignore Debug messages from plugins unless in debug mode.
if (level != (int)Logger::Level::Debug || GetRainmeter().GetDebug())
{
va_list args;
va_start(args, format);
GetLogger().LogSectionVF((Logger::Level)level, measure, format, args);
va_end(args);
}
}
// Deprecated!
LPCWSTR ReadConfigString(LPCWSTR section, LPCWSTR option, LPCWSTR defValue)
{
NULLCHECK(section);
NULLCHECK(option);
NULLCHECK(defValue);
ConfigParser* parser = GetRainmeter().GetCurrentParser();
if (parser)
{
return parser->ReadString(section, option, defValue, false).c_str();
}
return defValue;
}
// Deprecated!
LPCWSTR PluginBridge(LPCWSTR command, LPCWSTR data)
{
if (command == nullptr || *command == L'\0')
{
return L"noop";
}
NULLCHECK(data);
if (_wcsicmp(command, L"GetConfig") == 0)
{
Skin* skin = GetRainmeter().GetSkinByINI(data);
if (skin)
{
g_Buffer = L"\"";
g_Buffer += skin->GetFolderPath();
g_Buffer += L"\"";
return g_Buffer.c_str();
}
return L"";
}
else if (_wcsicmp(command, L"GetWindow") == 0)
{
std::vector<std::wstring> subStrings = CommandHandler::ParseString(data);
if (subStrings.size() >= 1ULL)
{
std::wstring& config = subStrings[0];
Skin* skin = GetRainmeter().GetSkin(config);
if (skin)
{
WCHAR buf1[64] = { 0 };
_snwprintf_s(buf1, _TRUNCATE, L"%lu", PtrToUlong(skin->GetWindow()));
g_Buffer = buf1;
return g_Buffer.c_str();
}
}
return L"error";
}
else if (_wcsicmp(command, L"GetVariable") == 0)
{
std::vector<std::wstring> subStrings = CommandHandler::ParseString(data);
if (subStrings.size() >= 2ULL)
{
std::wstring& config = subStrings[0];
Skin* skin = GetRainmeter().GetSkin(config);
if (skin)
{
const std::wstring& variable = subStrings[1];
const std::wstring* value = skin->GetParser().GetVariable(variable);
if (value)
{
return (*value).c_str();
}
}
}
return L"";
}
else if (_wcsicmp(command, L"SetVariable") == 0)
{
std::vector<std::wstring> subStrings = CommandHandler::ParseString(data);
if (subStrings.size() == 3ULL)
{
Skin* skin = GetRainmeter().GetSkin(subStrings[0]);
if (skin)
{
skin->SetVariable(subStrings[1], subStrings[2]);
return L"success";
}
}
return L"error";
}
return L"noop";
}