forked from TheSaw/win7shell
-
Notifications
You must be signed in to change notification settings - Fork 0
/
lines.cpp
244 lines (226 loc) · 11.2 KB
/
lines.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
#include <windows.h>
#include <windowsx.h>
#include <string>
#include <vector>
#include <sstream>
#include <strsafe.h>
#include "gen_win7shell.h"
#include "resource.h"
#include "api.h"
#include "sdk/winamp/wa_ipc.h"
#include "lines.h"
#include "tools.h"
#include <loader/loader/utils.h>
lines::lines(sSettings &Settings, MetaData &Metadata) :
m_settings(Settings), m_metadata(Metadata) {}
std::wstring lines::MetaWord(const std::wstring &word, linesettings¤t_line_settings,
void **token, bool* reentrant, INT_PTR *db_error)
{
if (word == L"d")
{
current_line_settings.dontscroll = true;
return L"";
}
else if (word == L"c")
{
current_line_settings.center = true;
return L"";
}
else if (word == L"s")
{
current_line_settings.shadow = true;
return L"";
}
else if (word == L"f")
{
current_line_settings.forceleft = true;
return L"";
}
else if (word == L"l")
{
current_line_settings.largefont = true;
return L"";
}
else if (word == L"b")
{
current_line_settings.darkbox = true;
return L"";
}
else if (word == L"curtime")
{
const int res = m_settings.play_current;
if (res == -1)
{
return L"~";
}
return tools::SecToTime(res / 1000);
}
else if (word == L"timeleft")
{
const int cur = m_settings.play_current, tot = m_settings.play_total;
if (cur == -1 || tot <= 0)
{
return L"~";
}
return tools::SecToTime((tot - cur) / 1000);
}
else if (word == L"totaltime")
{
const int tot = m_settings.play_total;
if (tot <= 0)
{
return L"~";
}
return tools::SecToTime(tot / 1000);
}
else if (word == L"kbps")
{
const int inf = m_settings.play_kbps;
if (!inf)
{
return L"~";
}
wchar_t str[16] = { 0 };
I2WStr(inf, str, ARRAYSIZE(str));
return str;
}
else if (word == L"khz")
{
const int inf = m_settings.play_khz;
if (!inf)
{
return L"~";
}
wchar_t str[16] = { 0 };
I2WStr(inf, str, ARRAYSIZE(str));
return str;
}
else if (word == L"volume")
{
wchar_t str[16] = { 0 };
I2WStr(((m_settings.play_volume * 100) / 255), str, ARRAYSIZE(str));
return str;
}
else if (word == L"shuffle")
{
static wchar_t tmp[8];
return WASABI_API_LNGSTRINGW_BUF((m_settings.state_shuffle ? IDS_ON : IDS_OFF), tmp, 8);
}
else if (word == L"repeat")
{
static wchar_t tmp[8];
return WASABI_API_LNGSTRINGW_BUF((repeat ? IDS_ON : IDS_OFF), tmp, 8);
}
else if (word == L"curpl")
{
wchar_t str[16] = { 0 };
I2WStr((m_settings.play_playlistlen ? m_settings.play_playlistpos + 1 : 0), str, ARRAYSIZE(str));
return str;
}
else if (word == L"totalpl")
{
wchar_t str[16] = { 0 };
I2WStr(m_settings.play_playlistlen, str, ARRAYSIZE(str));
return str;
}
else
{
const bool rating1 = (word == L"rating1");
if (rating1 || word == L"rating2")
{
const int rating = (int)GetSetMainRating(0, IPC_GETRATING);
if (rating1)
{
wchar_t str[16] = { 0 };
I2WStr(rating, str, ARRAYSIZE(str));
return str;
}
else
{
std::wstringstream w;
for (int i = 0; i < rating; i++)
{
w << L"\u2605";
}
for (int i = 0; i < 5 - rating; i++)
{
w << L"\u2606";
}
return w.str();
}
}
return m_metadata.getMetadata(word, token, reentrant, db_error);
}
}
void lines::Parse()
{
// these are used to help minimise the impact of directly
// querying the file for multiple pieces of metadata &/or
// if there's an issue with the local library db handling
INT_PTR db_error = FALSE;
bool reentrant = false;
void *token = NULL;
m_linesettings.clear();
m_texts.clear();
// parse all text
std::wstring::size_type pos = 0;
std::wstring text = m_settings.Text;
do
{
// cppcheck-suppress nonStandardCharLiteral
#pragma warning(disable:4066)
std::wstring::size_type pos_2 = text.find_first_of(L'\\r', pos);
#pragma warning(default:4066)
if (pos_2 == std::wstring::npos)
{
m_texts.push_back(text.substr(pos));
break;
}
m_texts.push_back(text.substr(pos, pos_2 - pos));
pos = pos_2 + 2;
}
while (pos != std::wstring::npos);
// replace text formatting tags
for (std::size_t index = 0; index != m_texts.size(); ++index)
{
linesettings current_line_settings = {0};
std::wstring::size_type meta_pos = 0;
do
{
meta_pos = m_texts[index].find_first_of(L'%', meta_pos);
if (meta_pos != std::wstring::npos)
{
if (meta_pos != 0 && m_texts[index][meta_pos - 1] == L'\\')
{
m_texts[index].erase(meta_pos - 1, 1);
continue;
}
std::wstring::size_type meta_pos2 = m_texts[index].find_first_of(L'%', meta_pos + 1);
if (meta_pos2 != std::wstring::npos)
{
// determine the %xxx% field to be processed
const std::wstring metaword = m_texts[index].substr(meta_pos + 1, (meta_pos2 - (meta_pos + 1))),
parsed = (!metaword.empty() ? MetaWord(metaword,
current_line_settings, &token,
&reentrant, &db_error) : L"");
m_texts[index].replace(meta_pos, (metaword.size() + 2), parsed);
// and then if it's a non-formatting field
// we move the position on to allow for %
// characters in the obtained text to not
// be treated as a potential %xxx% field.
if (!parsed.empty())
{
meta_pos += (parsed.size() + 1);
}
}
else
{
++meta_pos;
}
}
}
while (meta_pos != std::wstring::npos);
m_linesettings.push_back(current_line_settings);
}
plugin.metadata->FreeExtendedFileInfoToken(&token);
}