-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAddResource.ahk
74 lines (60 loc) · 1.76 KB
/
AddResource.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
#Requires AutoHotkey v2.0-
#NoTrayIcon
#Warn All, Off
;@Ahk2Exe-ConsoleApp
startDir := A_InitialWorkingDir
DllCall("AttachConsole", "int", -1)
FileAppend("`n", "*")
if (A_Args.Length != 2) {
FileAppend(" Usage:`n " . A_ScriptName . " <Resource-to-add> <Destination-binary>`n", "**")
ExitApp(-1)
}
; Check if A_Args is relative
args := A_Args
isRelative := [true, true]
rounds := 0
while ((isRelative[1] or isRelative[2]) and rounds < 3) {
rounds++
relativeCheck()
}
if (isRelative[1] or isRelative[2]) {
FileAppend(" Something went wrong. Check your input!`n", "**")
ExitApp(-1)
}
res2add := args[1]
destbin := args[2]
SplitPath(res2add, resname)
FileAppend(" Adding:`t`"" . res2add . "`"`n To:`t`t`"" . destbin . "`"`n With bame:`t`"" . resname . "`"`n`n", "*")
ResPut(FileRead(res2add, "RAW"), FileGetSize(res2add), destbin, resname)
try succ := ResExist(destbin, StrUpper(resname))
if succ
FileAppend(" Success!`n", "*")
else
FileAppend(" Something went wrong!`n", "*")
DllCall("FreeConsole")
return
relativeCheck() {
global args, isRelative, startDir
for index, arg in args {
if (!FileExist(arg) and !FileExist(".\" . arg) and !FileExist(startDir . "\" . arg)) {
FileAppend(" `"" . arg . "`" doesn't exist!`n", "**")
ExitApp(-1)
}
; better check twice!
SetWorkingDir(A_WinDir)
if FileExist(arg)
isRelative[index] := false
SetWorkingDir(A_MyDocuments)
if FileExist(arg)
isRelative[index] := false
; fix relative path
SetWorkingDir(startDir)
if isRelative[index] {
SplitPath(arg, filename)
try SetWorkingDir(StrReplace(arg, filename, ""))
args[index] := A_WorkingDir . "\" . filename
SetWorkingDir(startDir)
}
}
return
}