-
Notifications
You must be signed in to change notification settings - Fork 16
/
Copy pathwsa.pas
316 lines (274 loc) · 9.75 KB
/
wsa.pas
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
310
311
312
313
314
315
316
unit wsa;
interface
uses
Winapi.Windows, Generics.Collections, System.Classes, Vcl.ImageCollection;
type
PAPK = ^TAPK;
TAPK = record
AndroidPackageName: string;
AndroidVersionCode: string;
DisplayIcon: string;
DisplayName: string;
DisplayVersion: string;
EstimatedSize: Integer;
InstallDate: string;
ModifyPath: string;
NoRepair: Integer;
Publisher: string;
QuietUninstallString: string;
UninstalString: string;
end;
TAPKList = class(TList)
private
function Get(Index: Integer): PAPK;
public
destructor Destroy; override;
function Add(Value: PAPK): Integer;
property Items[Index: Integer]: PAPK read Get; default;
end;
TWSA = class
private
FInstalledApps: TAPKList;
FImageCollection: TImageCollection;
FInstallationPath: string;
FAppUserModelId: string;
FVersion: string;
FDisplayName: string;
FMinimumWindowsVersion: string;
FIconPath: string;
FLogoPath: string;
FPublisherDisplayName: string;
FWsaClientRelativePath: string;
FWsaSettingsRelativePath: string;
procedure SetInstallationPath(const Value: string);
procedure SetAppUserModelId(const Value: string);
procedure SetVersion(const Value: string);
procedure SetDisplayName(const Value: string);
procedure SetMinimumWindowsVersion(const Value: string);
procedure SetIconPath(const Value: string);
procedure SetLogoPath(const Value: string);
procedure SetPublisherDisplayName(const Value: string);
procedure SetWsaClientRelativePath(const Value: string);
procedure SetWsaSettingsRelativePath(const Value: string);
{WSA related things}
public
constructor Create;
destructor Destroy; override;
procedure UpdateInstalledAPKList;
property InstallationPath: string read FInstallationPath write SetInstallationPath;
property AppUserModelId: string read FAppUserModelId write SetAppUserModelId;
property Version: string read FVersion write SetVersion;
property DisplayName: string read FDisplayName write SetDisplayName;
property IconPath: string read FIconPath write SetIconPath;
property LogoPath: string read FLogoPath write SetLogoPath;
property PublisherDisplayName: string read FPublisherDisplayName write SetPublisherDisplayName;
property MinimumWindowsVersion: string read FMinimumWindowsVersion write SetMinimumWindowsVersion;
property WsaClientRelativePath: string read FWsaClientRelativePath write SetWsaClientRelativePath;
property WsaSettingsRelativePath: string read FWsaSettingsRelativePath write SetWsaSettingsRelativePath;
end;
implementation
uses
Winapi.ShlObj, Winapi.ActiveX, Winapi.KnownFolders, Winapi.ShellAPI,
Winapi.PropKey, Vcl.Graphics, System.SysUtils, helperFuncs;
{ TWSA }
constructor TWSA.Create;
begin
FInstalledApps := TAPKList.Create;
FImageCollection := TImageCollection.Create(nil);
end;
destructor TWSA.Destroy;
begin
FImageCollection.Free;
FInstalledApps.Free;
inherited;
end;
procedure TWSA.SetAppUserModelId(const Value: string);
begin
FAppUserModelId := Value;
end;
procedure TWSA.SetDisplayName(const Value: string);
begin
FDisplayName := Value;
end;
procedure TWSA.SetIconPath(const Value: string);
begin
FIconPath := Value;
end;
procedure TWSA.SetInstallationPath(const Value: string);
begin
FInstallationPath := Value;
end;
procedure TWSA.SetLogoPath(const Value: string);
begin
FLogoPath := Value;
end;
procedure TWSA.SetMinimumWindowsVersion(const Value: string);
begin
FMinimumWindowsVersion := Value;
end;
procedure TWSA.SetPublisherDisplayName(const Value: string);
begin
FPublisherDisplayName := Value;
end;
procedure TWSA.SetVersion(const Value: string);
begin
FVersion := Value;
end;
procedure TWSA.SetWsaClientRelativePath(const Value: string);
begin
FWsaClientRelativePath := Value;
end;
procedure TWSA.SetWsaSettingsRelativePath(const Value: string);
begin
FWsaSettingsRelativePath := Value;
end;
procedure TWSA.UpdateInstalledAPKList;
var
io: IKnownFolderManager;
count: Cardinal;
a: PGUIDList;
knownfoldernative: IKnownFolder;
hr: HRESULT;
oguid: TGUID;
si: IShellItem2;
sfgao: Cardinal;
isFileSystem: Boolean;
fd: TKnownFolderDefinition;
Item: TStrings;
fPath: array[0..1024] of Char;
pidControl: PItemIDList;
psfDesktop, dt: IShellFolder;
psfControl: IShellFolder;
pc: IShellFolder2;
pEnumList: IEnumIDList;
pidChild: PItemIDList;
pidAbsolute: PItemIDList;
celtFetched: ULONG;
fileInfo: SHFILEINFOW;
vAPK: PAPK;
begin
CoInitialize(nil);
// Clear content
FImageCollection.Images.Clear;
FInstalledApps.Clear;
CoCreateInstance(CLSID_KnownFolderManager, nil, CLSCTX_ALL, IID_IKnownFolderManager, io);
if Assigned(io) then
begin
//FOLDERID_AppsFolder 1e87508d-89c2-42f0-8a7e-645a0f50ca58
hr := io.GetFolder(FOLDERID_AppsFolder, knownfoldernative);
if hr = S_OK then
begin
hr := knownfoldernative.GetShellItem(0, IID_IShellItem2, si);
if Succeeded(hr) then
begin
if si <> nil then
begin
si.GetAttributes(SFGAO_FILESYSTEM, sfgao);
isFileSystem := (sfgao and SFGAO_FILESYSTEM) <> 0;
if not isFileSystem then
begin
knownfoldernative.GetFolderDefinition(fd);
if SHGetDesktopFolder(psfDesktop) = S_OK then
if SHGetDesktopFolder(dt) = S_OK then
if knownfoldernative.GetIDList(KF_FLAG_DEFAULT, pidControl) = S_OK then
if psfDesktop.BindToObject(pidControl, nil, IID_IShellFolder, psfControl) = S_OK then
if psfControl.EnumObjects(0, SHCONTF_NONFOLDERS or SHCONTF_INCLUDEHIDDEN, pEnumList) = S_OK then
begin
GetMem(vAPK, SizeOf(TAPK));
while pEnumList.Next(1, pidChild, celtFetched) = 0 do
begin
pidAbsolute := ILCombine(pidControl, pidChild);
if dt.BindToObject(pidControl, nil, IID_IShellFolder2, Pointer(pc)) = S_OK then
begin
var sa, lnk, flnk: OleVariant;
// var cs: SHCOLUMNID;
// cs.fmtid := StringToGUID('{9F4C2855-9F79-4B39-A8D0-E1D42DE1D5F3}');
// cs.pid := 5;
if pc.GetDetailsEx(pidChild, SHCOLUMNID(PKEY_AppUserModel_ID), @sa) = S_OK then
begin
var re: HRESULT;
try
re := (pc.GetDetailsEx(pidChild, SHCOLUMNID(PKEY_Link_Arguments), @flnk));
re := (pc.GetDetailsEx(pidChild, SHCOLUMNID(PKEY_Link_TargetParsingPath), @lnk));
// SHGetPathFromIDList(pidAbsolute, fPath);
except
lnk := '';
end;
if IsValidAppPackageName(sa)
or (Pos('!Setti', sa) > 0)
then
begin
SHGetFileInfo(LPCTSTR(pidAbsolute), 0, fileInfo, SizeOf(fileInfo),
SHGFI_PIDL or SHGFI_DISPLAYNAME or SHGFI_ICON or SHGFI_SYSICONINDEX {or SHGFI_SHELLICONSIZE} or SHGFI_LARGEICON);
// pc.GetUIObjectOf(0, )
// var c:uint32;
// pc.GetAttributesOf(1,pidChild,c);
CoTaskMemFree(pidAbsolute);
// Get WSA (wsaclient.exe) info
if Pos('!Sett', sa) > 0 then
begin
FDisplayName := fileInfo.szDisplayName;
FAppUserModelId := sa;
end
// and APK installed ones info
else if LowerCase(lnk).Contains('wsaclient.exe') then//if IsWsaClientLnkTarget(sa) then
begin
Item := TStrings.Create;
try
vAPK.DisplayName := fileInfo.szDisplayName;
vAPK.AndroidPackageName := sa;
FInstalledApps.Add(vAPK);
finally
Item.Free;
end;
end;
var icon := TIcon.Create;
try
icon.Handle := fileInfo.hIcon;
finally
icon.Free;
end;
end;
end;
end;
end;
end;
end;
end;
end;
end;
end;
CoUninitialize;
end;
{ TAPKList }
function TAPKList.Add(Value: PAPK): Integer;
begin
Result := inherited Add(Value);
end;
destructor TAPKList.Destroy;
var
I: Integer;
begin
for I := 0 to Count - 1 do
begin
// let's first release strings
SetLength(Items[I].AndroidPackageName, 0);
SetLength(Items[I].AndroidVersionCode, 0);
SetLength(Items[I].DisplayIcon, 0);
SetLength(Items[I].DisplayName, 0);
SetLength(Items[I].DisplayVersion, 0);
SetLength(Items[I].InstallDate, 0);
SetLength(Items[I].ModifyPath, 0);
SetLength(Items[I].Publisher, 0);
SetLength(Items[I].QuietUninstallString, 0);
SetLength(Items[I].UninstalString, 0);
// since we use GetMem(PAPK, SizeOf(TAPK)); we release it here
FreeMem(Items[I]);
end;
inherited;
end;
function TAPKList.Get(Index: Integer): PAPK;
begin
Result := PAPK(inherited Get(Index));
end;
end.