forked from aRTy42/POE-ItemInfo
-
Notifications
You must be signed in to change notification settings - Fork 189
/
Copy pathRun_TradeMacro.ahk
164 lines (141 loc) · 5.8 KB
/
Run_TradeMacro.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
; #####################################################################################################################
; # This script merges TradeMacro, TradeMacroInit, PoE-ItemInfo and AdditionalMacros into one script and executes it.
; # We also have to set some global variables and pass them to the ItemInfo/TradeMacroInit scripts.
; # This is to support using ItemInfo as dependancy for TradeMacro.
; #####################################################################################################################
#Include, %A_ScriptDir%\resources\VersionTrade.txt
TradeMsgWrongAHKVersion := "AutoHotkey v" . TradeAHKVersionRequired . " or later is needed to run this script. `n`nYou are using AutoHotkey v" . A_AhkVersion . " (installed at: " . A_AhkPath . ")`n`nPlease go to http://ahkscript.org to download the most recent version."
If (A_AhkVersion < TradeAHKVersionRequired)
{
MsgBox, 16, Wrong AutoHotkey Version, % TradeMsgWrongAHKVersion
ExitApp
}
arguments := ""
Loop, %0% ; For each parameter
{
arguments .= " " Trim(%A_Index%)
}
If (!InStr(arguments, "-noelevation", 0)) {
RunAsAdmin(arguments)
}
If (InStr(arguments, "-nosplash", 0)) {
skipSplash := 1
} Else {
skipSplash := 0
StartSplashScreen()
}
If (!PoEScripts_CreateTempFolder(A_ScriptDir, "PoE-TradeMacro")) {
ExitApp
}
If (InStr(A_ScriptDir, A_Desktop)) {
Msgbox, 0x1010, Invalid Installation Path, Executing PoE-TradeMacro from your Desktop may cause script errors, please choose a different directory.
}
/*
Set ProjectName to create user settings folder in A_MyDocuments
*/
projectName := "PoE-TradeMacro"
FilesToCopyToUserFolder := ["\resources\config\default_config_trade.ini", "\resources\config\default_config.ini", "\resources\ahk\default_AdditionalMacros.txt", "\resources\ahk\default_MapModWarnings.txt"]
overwrittenFiles := PoEScripts_HandleUserSettings(projectName, A_MyDocuments, projectName, FilesToCopyToUserFolder, A_ScriptDir)
isDevelopmentVersion := PoEScripts_isDevelopmentVersion()
userDirectory := A_MyDocuments . "\" . projectName . isDevelopmentVersion
PoEScripts_CompareUserFolderWithScriptFolder(userDirectory, A_ScriptDir, projectName)
/*
merge all scripts into `_TradeMacroMain.ahk` and execute it.
*/
info := ReadFileToMerge(A_ScriptDir "\resources\ahk\POE-ItemInfo.ahk")
tradeInit := ReadFileToMerge(A_ScriptDir "\resources\ahk\TradeMacroInit.ahk")
trade := ReadFileToMerge(A_ScriptDir "\resources\ahk\TradeMacro.ahk")
addMacros := ReadFileToMerge(userDirectory "\AdditionalMacros.txt")
info := "`n`r`n`r" . info . "`n`r`n`r"
addMacros := "#IfWinActive Path of Exile ahk_class POEWindowClass ahk_group PoEexe" . "`n`r`n`r" . addMacros . "`n`r`n`r"
addMacros .= AppendCustomMacros(userDirectory)
CloseScript("_TradeMacroMain.ahk")
CloseScript("_ItemInfoMain.ahk")
FileDelete, %A_ScriptDir%\_TradeMacroMain.ahk
FileDelete, %A_ScriptDir%\_ItemInfoMain.ahk
FileCopy, %A_ScriptDir%\resources\ahk\TradeMacroInit.ahk, %A_ScriptDir%\_TradeMacroMain.ahk
FileAppend, %info% , %A_ScriptDir%\_TradeMacroMain.ahk
FileAppend, %addMacros% , %A_ScriptDir%\_TradeMacroMain.ahk
FileAppend, %trade% , %A_ScriptDir%\_TradeMacroMain.ahk
; set script hidden
FileSetAttrib, +H, %A_ScriptDir%\_TradeMacroMain.ahk
; pass some parameters to TradeMacroInit
Run "%A_AhkPath%" "%A_ScriptDir%\_TradeMacroMain.ahk" "%projectName%" "%userDirectory%" "%isDevelopmentVersion%" "%overwrittenFiles%" "isMergedScript" "%skipSplash%"
ExitApp
; ####################################################################################################################
; # functions
; ####################################################################################################################
CloseScript(Name)
{
DetectHiddenWindows On
SetTitleMatchMode RegEx
IfWinExist, i)%Name%.* ahk_class AutoHotkey
{
WinClose
WinWaitClose, i)%Name%.* ahk_class AutoHotkey, , 2
If ErrorLevel
Return "Unable to close " . Name
Else
Return "Closed " . Name
}
Else
Return Name . " not found"
}
RunAsAdmin(arguments)
{
ShellExecute := A_IsUnicode ? "shell32\ShellExecute":"shell32\ShellExecuteA"
If Not A_IsAdmin
{
If A_IsCompiled
DllCall(ShellExecute, uint, 0, str, "RunAs", str, A_ScriptFullPath . " " . arguments, str, A_WorkingDir, int, 1)
Else
DllCall(ShellExecute, uint, 0, str, "RunAs", str, A_AhkPath, str, """" . A_ScriptFullPath . """" . " " . arguments, str, A_WorkingDir, int, 1)
ExitApp
}
Return arguments
}
StartSplashScreen() {
SplashTextOn, , 20, PoE-TradeMacro, Merging and starting Scripts...
}
AppendCustomMacros(userDirectory)
{
If(!InStr(FileExist(userDirectory "\CustomMacros"), "D")) {
FileCreateDir, %userDirectory%\CustomMacros\
}
appendedMacros := "`n`n"
extensions := "txt,ahk"
Loop %userDirectory%\CustomMacros\*
{
If A_LoopFileExt in %extensions%
{
FileRead, tmp, %A_LoopFileFullPath%
appendedMacros .= "; appended custom macro file: " A_LoopFileName " ---------------------------------------------------"
appendedMacros .= "`n" tmp "`n`n"
}
}
Return appendedMacros
}
ReadFileToMerge(path) {
If (FileExist(path)) {
ErrorLevel := 0
FileRead, file, %path%
If (ErrorLevel = 1) {
; file does not exist (should be caught already)
Msgbox, 4096, Critical file read error, File "%path%" doesn't exist.`n`nClosing Script...
ExitApp
} Else If (ErrorLevel = 2) {
; file is locked or inaccessible
Msgbox, 4096, Critical file read error, File "%path%" is locked or inaccessible.`n`nClosing Script...
ExitApp
} Else If (ErrorLevel = 3) {
; the system lacks sufficient memory to load the file
Msgbox, 4096, Critical file read error, The system lacks sufficient memory to load the file "%path%".`n`nClosing Script...
ExitApp
} Else {
Return file
}
} Else {
Msgbox, 4096, Critical file read error, File "%path%" doesn't exist.`n`nClosing Script...
ExitApp
}
}