forked from henrypp/simplewall
-
Notifications
You must be signed in to change notification settings - Fork 0
/
icons.c
276 lines (226 loc) · 4.77 KB
/
icons.c
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
// simplewall
// Copyright (c) 2016-2023 Henry++
#include "global.h"
PICON_INFORMATION _app_icons_getdefault ()
{
static R_INITONCE init_once = PR_INITONCE_INIT;
static ICON_INFORMATION icon_info = {0};
PR_STRING path;
if (_r_initonce_begin (&init_once))
{
// load default icons
path = _r_obj_concatstrings (
2,
_r_sys_getsystemdirectory ()->buffer,
L"\\svchost.exe"
);
_app_icons_loadfromfile (
path,
0,
&icon_info.app_icon_id,
&icon_info.app_hicon,
FALSE
);
// load default service icons
_r_obj_dereference (path);
path = _r_obj_concatstrings (
2,
_r_sys_getsystemdirectory ()->buffer,
L"\\shell32.dll"
);
_app_icons_loadfromfile (
path,
0,
&icon_info.service_icon_id,
&icon_info.service_hicon,
FALSE
);
// load uwp icons
if (_r_sys_isosversiongreaterorequal (WINDOWS_8))
{
_r_obj_dereference (path);
path = _r_obj_concatstrings (
2,
_r_sys_getsystemdirectory ()->buffer,
L"\\wsreset.exe"
);
_app_icons_loadfromfile (
path,
0,
&icon_info.uwp_icon_id,
&icon_info.uwp_hicon,
FALSE
);
}
_r_obj_dereference (path);
_r_initonce_end (&init_once);
}
return &icon_info;
}
_Ret_maybenull_
HICON _app_icons_getdefaultapp_hicon ()
{
PICON_INFORMATION icon_info;
icon_info = _app_icons_getdefault ();
if (icon_info->app_hicon)
return CopyIcon (icon_info->app_hicon);
return NULL;
}
_Ret_maybenull_
HICON _app_icons_getdefaulttype_hicon (
_In_ ENUM_TYPE_DATA type,
_In_ PICON_INFORMATION icon_info
)
{
if (type == DATA_APP_UWP)
{
if (icon_info->uwp_hicon)
return CopyIcon (icon_info->uwp_hicon);
}
else if (type == DATA_APP_SERVICE)
{
if (icon_info->service_hicon)
return CopyIcon (icon_info->service_hicon);
}
if (icon_info->app_hicon)
return CopyIcon (icon_info->app_hicon);
return NULL;
}
LONG _app_icons_getdefaultapp_id (
_In_ ENUM_TYPE_DATA type
)
{
PICON_INFORMATION icon_info;
icon_info = _app_icons_getdefault ();
if (type == DATA_APP_UWP)
{
return icon_info->uwp_icon_id;
}
else if (type == DATA_APP_SERVICE)
{
return icon_info->service_icon_id;
}
return icon_info->app_icon_id;
}
HICON _app_icons_getsafeapp_hicon (
_In_ ULONG_PTR app_hash
)
{
PICON_INFORMATION icon_info;
PITEM_APP ptr_app;
HICON hicon;
LONG icon_id;
BOOLEAN is_iconshidded;
icon_info = _app_icons_getdefault ();
ptr_app = _app_getappitem (app_hash);
if (!ptr_app)
{
if (icon_info->app_hicon)
return CopyIcon (icon_info->app_hicon);
return NULL;
}
is_iconshidded = _r_config_getboolean (L"IsIconsHidden", FALSE);
if (!ptr_app->real_path || is_iconshidded || !_app_isappvalidbinary (ptr_app->type, ptr_app->real_path))
{
hicon = _app_icons_getdefaulttype_hicon (ptr_app->type, icon_info);
_r_obj_dereference (ptr_app);
return hicon;
}
_app_icons_loadfromfile (
ptr_app->real_path,
ptr_app->type,
&icon_id,
&hicon,
TRUE
);
if (!icon_id ||
((ptr_app->type == DATA_APP_UWP || ptr_app->type == DATA_APP_SERVICE) && icon_id == icon_info->app_icon_id))
{
if (hicon)
DestroyIcon (hicon);
hicon = _app_icons_getdefaulttype_hicon (ptr_app->type, icon_info);
}
_r_obj_dereference (ptr_app);
return hicon;
}
VOID _app_icons_loaddefaults (
_In_ ENUM_TYPE_DATA type,
_Inout_opt_ PLONG icon_id_ptr,
_Inout_opt_ HICON_PTR hicon_ptr
)
{
PICON_INFORMATION icon_info;
icon_info = _app_icons_getdefault ();
if (icon_id_ptr)
{
if (*icon_id_ptr == 0 ||
(type == DATA_APP_UWP && *icon_id_ptr == icon_info->app_icon_id) ||
(type == DATA_APP_SERVICE && *icon_id_ptr == icon_info->app_icon_id))
{
if (type == DATA_APP_UWP)
{
*icon_id_ptr = icon_info->uwp_icon_id;
}
else if (type == DATA_APP_SERVICE)
{
*icon_id_ptr = icon_info->service_icon_id;
}
else
{
*icon_id_ptr = icon_info->app_icon_id;
}
}
}
if (hicon_ptr)
{
if (*hicon_ptr == NULL || type == DATA_APP_UWP)
{
if (type == DATA_APP_UWP)
{
if (icon_info->uwp_hicon)
*hicon_ptr = CopyIcon (icon_info->uwp_hicon);
}
else
{
if (icon_info->app_hicon)
*hicon_ptr = CopyIcon (icon_info->app_hicon);
}
}
}
}
VOID _app_icons_loadfromfile (
_In_opt_ PR_STRING path,
_In_ ENUM_TYPE_DATA type,
_Out_opt_ PLONG icon_id_ptr,
_Out_opt_ HICON_PTR hicon_ptr,
_In_ BOOLEAN is_loaddefaults
)
{
SHFILEINFO shfi = {0};
UINT flags;
if (!icon_id_ptr && !hicon_ptr)
return;
flags = SHGFI_LARGEICON;
if (icon_id_ptr)
{
flags |= SHGFI_SYSICONINDEX;
*icon_id_ptr = 0;
}
if (hicon_ptr)
{
flags |= SHGFI_ICON;
*hicon_ptr = NULL;
}
if (path)
{
if (SHGetFileInfo (path->buffer, 0, &shfi, sizeof (shfi), flags))
{
if (icon_id_ptr)
*icon_id_ptr = shfi.iIcon;
if (hicon_ptr)
*hicon_ptr = shfi.hIcon;
}
}
if (is_loaddefaults)
_app_icons_loaddefaults (type, icon_id_ptr, hicon_ptr);
}