forked from HotKeyIt/ahkdll
-
Notifications
You must be signed in to change notification settings - Fork 1
/
CleanUpAndPack.ahk
102 lines (98 loc) · 3.98 KB
/
CleanUpAndPack.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
If (InStr(A_AhkVersion,"1")=1) {
MsgBox Requires AutoHotkey V2 version, script will exit now!
ExitApp
}
SetWorkingDir,% A_ScriptDir
dirs:=[A_ScriptDir "\bin"]
subs:={"Win32w":1,"x64w":1,"Win32a":1,"Win32w_MT":1,"x64w_MT":1,"Win32a_MT":1}
exts:=["lib","exp","pdb","iobj","ipdb"]
for t1,dir in dirs
for t2,ext in exts
LoopFiles % dir "\*." ext,FR
If subs.HasKey(SubStr(A_LoopFileDir,InStr(A_LoopFileDir,"\",1,-1)+1))
FileDelete % A_LoopFileFullPath
for t1,dir in dirs
LoopFiles % dir "\AutoHotkeyDll.dll",FR
If subs.HasKey(SubStr(A_LoopFileDir,InStr(A_LoopFileDir,"\",1,-1)+1))
FileMove,% A_LoopFileFullPath,% RegExReplace(A_LoopFileFullPath,"i)AutoHotkeyDll\.dll","AutoHotkey.dll"),1
RCData:={("bin\Win32a"):["AUTOHOTKEY.DLL","AUTOHOTKEYMINI.DLL"],("bin\Win32w"):["AUTOHOTKEY.DLL","AUTOHOTKEYMINI.DLL"],("bin\x64w"):["AUTOHOTKEY.DLL","AUTOHOTKEYMINI.DLL"],("bin\Win32a_MT"):["AUTOHOTKEY.DLL","AUTOHOTKEYMINI.DLL"],("bin\Win32w_MT"):["AUTOHOTKEY.DLL","AUTOHOTKEYMINI.DLL"],("bin\x64w_MT"):["AUTOHOTKEY.DLL","AUTOHOTKEYMINI.DLL"]}
for k,v in RCData
LoopFiles % A_ScriptDir "\" k "\*.dll"
{
if !hUpdate:=BeginUpdateResource(A_LoopFileFullPath)
{
MsgBox % "Error Begin: " A_LoopFileFullPath "`n" ErrMsg()
ExitApp
}
If !EndUpdateResource(hUpdate,0)
{
MsgBox % "End: " ErrMsg()
ExitApp
}
}
Loop 2 {
idx:=A_Index
for k,o in RCData
{
sourcedir:=A_ScriptDir "\" k "\"
exe:=sourcedir "AutoHotkey" (idx=1?".exe":"SC.bin")
if !hUpdate:=BeginUpdateResource(exe)
{
MsgBox % "Error Begin: " exe "`n" ErrMsg()
ExitApp
}
for k,v in o
{
FileRead, data,% "*c " sourcedir "\" v
FileGetSize, sz,% sourcedir "\" v
sz:=ZipRawMemory(&data, sz, var)
vres:=v="AutoHotkey.dll"?"F903E44B8A904483A1732BA84EA6191F":v="AutoHotkeyMini.dll"?"FC2328B39C194A4788051A3B01B1E7D5":StrUpper(v)
if FindResource(hUpdate,10,vres)
If !UpdateResource(hUpdate,10,vres,1033)
MsgBox % "Delete: " v "-" ErrMsg()
If !UpdateResource(hUpdate,10,vres,1033,&var,sz)
MsgBox % "Update: " v "-" ErrMsg()
FileDelete,% A_ScriptDir "\temp\" v
FileDelete,% A_ScriptDir "\temp\" v ".zip"
}
if idx=1
LoopFiles,% A_ScriptDir "\source\resources\reslib\*.ahk"
{
FileRead, data,% "*c " A_ScriptDir "\source\resources\reslib\" A_LoopFileName
FileGetSize, sz,% A_ScriptDir "\source\resources\reslib\" A_LoopFileName
sz:=ZipRawMemory(&data, sz, var)
if FindResource(hUpdate,"LIB",StrUpper(A_LoopFileName))
If !UpdateResource(hUpdate,"LIB",StrUpper(A_LoopFileName),1033)
MsgBox % "Delete: " StrUpper(A_LoopFileName) "-" ErrMsg()
If !UpdateResource(hUpdate,"LIB",StrUpper(A_LoopFileName),1033,&var,sz)
MsgBox % "Update: " StrUpper(A_LoopFileName) "-" ErrMsg()
}
If !EndUpdateResource(hUpdate,0)
MsgBox End: %ErrMsg()%
}
}
MsgBox Finished
;----------------------------------------------------------------
; Function: ErrMsg
; Get the description of the operating system error
;
; Parameters:
; ErrNum - Error number (default = A_LastError)
;
; Returns:
; String
;
ErrMsg(ErrNum:=""){
if (ErrNum="")
ErrNum := A_LastError
VarSetCapacity(ErrorString, 1024) ;String to hold the error-message.
DllCall("FormatMessage"
, "UINT", 0x00001000 ;FORMAT_MESSAGE_FROM_SYSTEM: The function should search the system message-table resource(s) for the requested message.
, "UINT", 0 ;A handle to the module that contains the message table to search.
, "UINT", ErrNum
, "UINT", 0 ;Language-ID is automatically retreived
, "Str", ErrorString
, "UINT", 1024 ;Buffer-Length
, "str", "") ;An array of values that are used as insert values in the formatted message. (not used)
return return StrReplace(ErrorString,"`r`n",A_Space) ;Replaces newlines by A_Space for inline-output
}