-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcpl-explorer_funcs.ahk
477 lines (475 loc) · 15.7 KB
/
cpl-explorer_funcs.ahk
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
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
#SingleInstance, Force
WM_LBUTTONDOWN(args*)
{ global
local lbPos,lbModifiers,lbWin,mods,tb,aid,thisControl
Gui,Submit,NoHide
tooltip
mods := (args[1]-1)
if (WinActive(title " Help"))
{ MouseGetPos,,,,thisControl
if (thisControl="Static1")
{ PostMessage,0xA1,2,,,%title% Help
return
}
if (thisControl="Static2")
{ Gosub,HelpGuiGuiClose
}
}
if (args[4]=runButton)
{ AnimateButton(runButton,runText,"SlideDown",33)
runCpl(isAdmin)
return
}
if (args[4]=refreshButton)
{ AnimateButton(refreshButton,refreshText,"SlideDown",33)
refreshList()
return
}
lbModifiers := { "ctrl" : (mods=8)
, "shift" : (mods=4)
, "ctrl_shift":(mods=12)}
lbPos := { "x":(args[2]&0xffff)
, "y":(args[2]>>16)&0xffff}
aid := "ahk_id " args[4]
WinGetTitle,winTitle,%aid%
WinGetClass,winClass,%aid%
lbWin := { "id":args[4]
, "title":winTitle
, "class":winClass}
aid := ""
tb := (lbWin.Id = titlebar)
if overTitleBar := (tb And (lbPos.x<398))
{
PostMessage,0xA1,2,,,% "ahk_id " mainGuiId
return
}
if overMinWin := (tb And ((lbPos.x>=398) And (lbPos.x<=438)))
{
WinMinimize,ahk_id %mainGuiId%
return
}
if overClose := (tb And ((lbPos.x>=399) And (lbPos.x<=479)))
{ AnimateWindowEx(mainGuiId,"Hide|SlideDown",333)
ExitApp
}
}
;┌──────────────────────────────────────────────────────┐
;│ mouseBounds Function: │
;│ Test if mouse is in bounds of 2 │
;│ pairs of diagonal x,y coordinates │
;│ E.g.: │
;│ mouseBounds(x1,y1,x2,y2) │
;│ mouseBounds(0,0,64,64) │
;│ mouseBounds(ctrlX,ctrlY,(ctrlX+ctrlW),(ctrlY+ctrlH)) │
;│ will all return true or false │
;└──────────────────────────────────────────────────────┘
mouseBounds(bounds*)
{ if (bounds.MaxIndex()=4) ; must supply all 4 coords
{ MouseGetPos,x,y
return ( ( (x>=bounds[1]) And (x<=bounds[3]))
And ( (y>=bounds[2]) And (y<=bounds[4])))
}
}
ttx()
{ return WinExist("ahk_class tooltips_class32")
}
WM_MOUSEMOVE(args*)
{
global
local lbPos,aid,winTitle,winClass,lbWin,activeWinId
, picAX,picAY,pixAW,picAH,thisControl
lbPos := { "x":(args[2]&0xffff)
, "y":(args[2]>>16)&0xffff}
aid := "ahk_id " args[4]
activeWinId := WinExist("A")
if (WinActive(title " Help"))
{ MouseGetPos,,,,thisControl
if (thisControl="Static2")
{ if ! (s2tog)
{ s2tog := true
GuiControl,+C0xFF2F2F,msctls_progress322,%title% Help
GuiControl,+Redraw,Static2,%title% Help
}
return
}
else
{ if (s2tog)
{ s2tog := false
GuiControl,+C0x2B5797,msctls_progress322,%title% Help
GuiControl,+Redraw,Static2,%title% Help
}
return
}
}
if (WinActive("ahk_id " mainGuiId))
{ ControlGetPos,picAX,picAY,picAW,picAH,Static5,%title%
if mouseBounds(picAX,pixAY,(picAX+picAW),(picAY+picAH))
{ if ! ttx()
{ tooltip % hotkeyString
}
}
else
{ if ttx()
{ KillToolTip()
}
}
}
WinGetTitle,winTitle,%aid%
WinGetClass,winClass,%aid%
lbWin := { "id":args[4]
, "title":winTitle
, "class":winClass}
aid := ""
tb := (lbWin.Id = titlebar)
if maxWinReset
{
maxWinReset := false
GuiControl,+C2b5797,msctls_progress323,ahk_id %mainGuiId%
GuiControl,+Redraw,Static3,ahk_id %mainGuiId%
}
if minWinReset
{
minWinReset := false
GuiControl,+C0x2B5797,msctls_progress322,ahk_id %mainGuiId%
GuiControl,+Redraw,Static2,ahk_id %mainGuiId%
}
if overMinWin := (tb And ((lbPos.x>=398) And (lbPos.x<=438)))
{
minWinReset := true
GuiControl,+C0x3B67A7,msctls_progress322,ahk_id %mainGuiId%
GuiControl,+Redraw,Static2,ahk_id %mainGuiId%
return
}
if overClose := (tb And ((lbPos.x>=399) And (lbPos.x<=479)))
{
maxWinReset := true
GuiControl,+C0xFF2F2F,msctls_progress323,ahk_id %mainGuiId%
GuiControl,+Redraw,Static2,ahk_id %mainGuiId%
return
}
}
KillToolTip()
{ if WinExist("ahk_class tooltips_class32")
{ tooltip
}
}
OnMessageBulk(objOrArray := "",funcName := "")
{ if IsObject(objOrArray)
{ for idx, item in objOrArray
{ OnMessage( (funcName?item:idx)
, (funcName?funcName:item))
}
}
}
ControlPanelObj()
{ A_SysDir := A_WinDir "\System32\"
if InStr(FileExist(A_SysDir),"D")
{ tmpObj := {}
loop,files,%A_SysDir%*.cpl
{ thisFile := A_LoopFileFullPath
SplitPath,thisFile,thisFileName,thisDir,thisExt,thisNoExt,thisDrive
tmpObj[thisNoExt] := { "full" : thisFile
, "path" : { "filename" : thisFileName
, "directory" : thisDir
, "extension" : thisExt
, "noextension": thisNoExt
, "drive" : thisDrive}
, "info" : FileInfo(thisFile)}
}
return tmpObj
}
}
FileInfo(file := "",select := "")
{ data := 0
if dataSz := DllCall("Version\GetFileVersionInfoSizeW","WStr",file,"Int",0)
{ if DllCall("Version\GetFileVersionInfoW","WStr",file,"Int",0,"UInt",VarSetCapacity(ret,dataSz),"Str",ret)
{ if select
{ if DllCall("Version\VerQueryValueW","Str",ret,"WStr","\StringFileInfo\040904B0\" select,"PtrP",data,"Int",0)
return StrGet(data,"UTF-16")
}else
{ retArray := {}
for idx, type in [ "FileDescription" , "FileVersion"
, "InternalName" , "LegalCopyright"
, "OriginalFilename" , "ProductName"
, "ProductVersion" ]
{ DllCall("Version\VerQueryValueW","Str",ret,"WStr","\StringFileInfo\040904B0\" type,"PtrP",data,"Int",0)
retArray[type] := StrGet(data,"UTF-16")
}
return retArray
}
}
}
}
listFunc(display := true)
{
global
static obj
if display
{ LV_Delete()
}
Gui,Submit,NoHide
currentFileObj := obj := cplObj[selectedCpl]
if display
{ GuiControl,-Redraw,ListView1
LV_Insert(1,,"Name:",obj.path.noextension)
LV_Insert(2,,"File Name:",obj.path.filename)
LV_Insert(3,,"Path:",obj.full)
LV_Insert(4,,"Settings for:",obj.info.ProductName)
LV_Insert(5,,"Original filename:",obj.info.OriginalFilename)
LV_Insert(6,,"Product version:",obj.info.ProductVersion)
LV_Insert(7,,"File version:",obj.info.FileVersion)
LV_Insert(8,,"Description:",obj.info.FileDescription)
LV_Insert(9,,"Copyright:",obj.info.LegalCopyright)
if IsObject(obj)
LV_ModifyCol()
else
LV_ModifyCol(1)
GuiControl,+Redraw,ListView1
}
}
refreshList()
{ global
Gui,Submit,NoHide
GuiControl,-Redraw,ListBox1
GuiControl,,ListBox1,% "|" getFullList()
GuiControl,+Redraw,ListBox1
listFunc()
}
getFullList(exitv := true)
{
global
cplObj := ControlPanelObj()
if ! IsObject(cplObj)
{ MsgBox,32,CPL Explorer Information,%noFilesErr%
if exitv
ExitApp
else
return
}
listboxList := ""
for cpl in cplObj
{
listboxList .= cpl "|"
}
listboxList := SubStr(listboxList,1,StrLen(listboxList)-1)
return listboxList
}
WM_KEYDOWN(args*)
{ global
Gui,Submit,NoHide
if (WinActive("ahk_id " mainGuiId))
{ if ( GetKeyState("Shift","P")
And GetKeyState("Enter","P"))
{ AnimateButton(runButton,runText,"SlideDown",33)
runCpl(true)
return
}
if GetKeyState("Enter","P")
{ AnimateButton(runButton,runText,"SlideDown",33)
runCpl(isAdmin)
return
}
}
}
runCpl(admin := false)
{ global
Gui,Submit,NoHide
local f,msg,runErr
if FileExist(currentFileObj.full)
{
f := currentFileObj.full?currentFileObj.full:"File not found"
if admin
{ try,run *runas %f%
catch runErr
{ msg := (runErr.Extra~="The system cannot find the file specified.")
? StrReplace(cantStart,"<<REPLACE>>",f)
: (runErr.Extra~=".*canceled by the user.")
? runErr.Extra
: "There was an unkown error."
MsgBox,32,CPL Explorer Information,%msg%
return
}
return true
}
try,run,%f%
catch runErrb
{ msg := (runErrb.Extra~="The system cannot find the file specified.")
? StrReplace(cantStart,"<<REPLACE>>",f)
: "There was an unkown error."
MsgBox,32,CPL Explorer Information,%msg%
return
}
return true
}
}
checkAdmin()
{ global
local text
Gui,Submit,NoHide
ControlGetText,text,Button1,ahk_id %mainGuiId%
if isAdmin
{
if (SubStr(text,StrLen(text)-2)="Off")
GuiControl,Text,Button1,&Admin Mode: On
return
}
if (SubStr(text,StrLen(text)-1)="On")
GuiControl,Text,Button1,&Admin Mode: Off
}
WM_SYSKEYDOWN(args*)
{ global
Gui,Submit,NoHide
if (WinActive("ahk_id " mainGuiId))
{ if GetKeyState("s","P")
{ AnimateButton(runButton,runText,"SlideDown",33)
runCpl(isAdmin)
return
}
if GetKeyState("r","P")
{ AnimateButton(refreshButton,refreshText,"SlideDown",33)
refreshList()
return
}
if GetKeyState("h","P")
{ helpFunc()
}
}
}
WM_ENTERSIZEMOVE(args*)
{ global
WinSet,Trans,191,% "ahk_id " args[4]
}
WM_EXITSIZEMOVE(args*)
{ global
WinSet,Trans,255,% "ahk_id " args[4]
WinSet,Trans,Off,% "ahk_id " args[4]
if (args[4]=helpGuiId)
{ WinSet,Redraw,,% "ahk_id " editHwnd
WinSet,Redraw,,% "ahk_id " buttonHwnd
}
}
helpFunc()
{ global
AnimateButton(helpHwnd,,"SlideDown")
helpGui()
}
helpGui()
{ global
local GNULIC
WinSet,Disable,,ahk_id %mainGuiId%
h := "HelpGui"
Gui,%h%:New,+HwndhelpGuiHwnd -Caption +Border
Gui,%h%:Font,s15 q2 c0x1F1F1F,Segoe UI
Gui,%h%:Color,0xE0E0E0,0xEFEFEF
Gui,%h%:Margin,0,0
Gui,%h%:Add,Progress,x0 y0 w496 h40 Background0x1B4787 C0x2B5797 HwndhelpTitleBar,100 ;
Gui,%h%:Add,Text,xp yp w496 h40 +Center +0x200 C0xEFEFEF +BackgroundTrans,%title% Help ;
Gui,%h%:Add,Progress,x455 y0 w40 h40 Background0x1B4787 C0x2B5797 HwndmaxWinB,100 ;
Gui,%h%:Add,Text,xp yp w40 h40 +Center +0x200 C0xEFEFEF +BackgroundTrans HwndmaxTextWinB,X
helpHeader("About: " title,,"x8 y+8")
Gui,%h%:Font,s10 w500 c0x1B4787
Gui,%h%:Add,Text,Section x8 y+0 w480 HwndhTextId,%helpText%
helpHeader("What is a cpl file?",,"x8 y+8 HwndtestHwnd")
Gui,%h%:Font,s10 w500 c0x1B4787
Gui,%h%:Add,Text,xs y+0 w480,%cplFilesNfo%
helpHeader("Hotkeys",,"y+8 +Center w480")
Gui,Font,w500 s10 c0x1B4787
Gui,%h%:Add,ListView,xs y+8 w480 R6,Name|Description
for keyName, keyDesc in hKeys
{ LV_Add(,keyName,keyDesc)
}
LV_ModifyCol()
Gui,%h%:Font,s10,Segoe UI
if (GNULIC := getLic()) ; add ! to test no lic file
{ Gui,%h%:Add,Button,xs y+8 gShowLicense HwndbuttonHwnd,Show &License
helpHeader( "Gnu Public License V3",,"Hidden xs yp +Center +0x200 w480 c0xFF2F2F HwndtextHwnd ","s12")
Gui,%h%:Add,Text,Hidden xs y+0 w480 h8 vbottomMargin HwndhideMarg
Gui,%h%:Font,S8 c0x1F1F1F w500,Consolas
Gui,%h%:Color,0xE0E0E0
Gui,%h%:Add,Edit,xs y+8 Hidden w480 r20 +0x800 +0x4 +0x80 v%h%EditVar HwndeditHwnd,%GNULIC%
}
else
{ Gui,%h%:Font,s12 w600
Gui,%h%:Add,Link,xs y+8 w480 C0xFF2F2F, % "This software is licensed under the GNU Public License V3: "
. "`n<a href=`""https://www.gnu.org/licenses/gpl-3.0.txt`"">"
. "https://www.gnu.org/licenses/gpl-3.0.txt</a>"
}
; GNULIC := "" ; uncomment to test no lic file
if (! GNULIC)
{ Gui,%h%:Add,Text,x0 y+0 w496 h8 vbottomMargin
}
else
{ GuiControl,%h%:Show,bottomMargin
GuiControlGet,Button1,%h%:Pos
GuiControl,%h%:Move,bottomMargin,% "y" (Button1Y+Button1H)
}
Gui,%h%:Show,Hide AutoSize,%title% Help
DetectHiddenWindows,On
helpWinId := WinExist(title " Help")
AnimateWindowEx(helpWinId,"SlideDown")
Gui,%h%:+LastFound
helpGuiId := WinExist()
Gui,%h%:Show,AutoSize,%title% Help
Gui,%h%:Submit,NoHide
WinActivate,%title% Help
}
helpHeader(string,fntFace := "Segoe UI",txtOpts := "",fntOpts := "",opts*)
{ global
local idx,item
if (opts.MaxIndex())
for idx, item in opts
options .= item A_Space
Gui,%h%:Font,q2 s12 w600 c0xFF2F2F %fntOpts% %options%,%fntFace%
Gui,%h%:Add,Text,xp y+0 %txtOpts%,%string%
}
getLic(del := false)
{ gpl := A_WorkingDir "\gplv3.lic"
if ! FileExist(gpl)
UrlDownloadToFile,https://www.gnu.org/licenses/gpl-3.0.txt,%gpl%
if ErrorLevel
return
loop,read,%gpl%
text .= A_LoopReadLine "`n"
if del
FileDelete,%gpl%
return text
}
arrayFromStr(string,delim := "`n")
{ array := []
loop,parse,string,%delim%
array.Push(A_LoopField)
return array
}
getEditLines()
{ global
return arrayFromStr(%h%EditVar)
}
AnimateWindowEx(hwnd,opts,time:=200)
{ DetectHiddenWindows,On
if WinExist("ahk_id " hwnd)
{ DetectHiddenWindows,Off
options := 0
optList := { "Activate" : 0x00020000, "Blend" : 0x00080000
, "Center" : 0x00000010, "Hide" : 0x00010000
, "RollRight" : 0x00000001, "RollLeft" : 0x00000002
, "RollDown" : 0x00000004, "RollUp" : 0x00000008
, "SlideRight": 0x00040001, "SlideLeft" : 0x00040002
, "SlideDown" : 0x00040004, "SlideUp" : 0x00040008 }
loop,parse,opts,|
options |= optList[A_LoopField]
return DllCall("AnimateWindow","UInt",hwnd,"Int",time,"UInt",options)
}
DetectHiddenWindows,Off
}
AnimateButton(id,hideId := "",mode := "Center",speed := 50)
{ if (id := WinExist("ahk_id " id))
{ AnimateWindowEx(id,"Hide|" mode,speed)
if (hideId := WinExist("ahk_id " hideId))
{ WinHide,ahk_id %hideId%
}
AnimateWindowEx(id,mode,speed)
if (hideId := WinExist("ahk_id " hideId))
{ WinShow,ahk_id %hideId%
}
}
}