Skip to content

Commit

Permalink
bunch of fixes and error handling improvements (#470)
Browse files Browse the repository at this point in the history
* fixed pre fill max value checkbox; added pseudomod exceptions to always be present

* added context menu option to show assigned hotkeys

* fixed advanced affix lookup

* fixed poeaffix lookup for daggers

* disabled forced 4/3L selection (advanced search)

* added custom macro file example

* custom acros example file improvements

* rewrote file copy to user folder

* example file changes

* example file changes

* example file changes

* example file

* added custom macros example to edit files context menu

* improved run scripts error handling

* added file write check for script dir

* added call to custom macro code execution label

* added more folder permission checks

* more permission check stuff

* file write permission issues error handling

* grammar

* fixed pseudo mods not showing added flat ele dmg

* macro example file rework

* fixed harbinger fragments/maps not being searchable

* code refactoring

* refactored run scripts: one checks version, one does the rest

* added exit app to run scripts

* added q20 pdps to ItemInfo tooltip

* added poe.ninja request fallback and improved AHK version check

* example file

* improve run script compatibility with ahk v2

* added paypal link

* added wiki link to additional macros

* added config key for poeapp search

* update note/version; fix file copy issue when using the dev version
  • Loading branch information
Eruyome authored Sep 1, 2017
1 parent 1c9a122 commit d6f25ce
Show file tree
Hide file tree
Showing 23 changed files with 827 additions and 665 deletions.
3 changes: 0 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,6 @@ backup/*
backup/
test.ahk

config.ini
config_trade.ini

lib/node_modules
lib/npm-debug.log.*
release
Expand Down
Binary file modified Fallback.exe
Binary file not shown.
145 changes: 11 additions & 134 deletions Run_ItemInfo.ahk
Original file line number Diff line number Diff line change
@@ -1,137 +1,14 @@
; ####################################################################################################
; # This script merges PoE-ItemInfo and AdditionalMacros into one script and executes it.
; # We also have to set some global variables and pass them to the ItemInfo script.
; # This is to support using ItemInfo as dependancy for other tools.
; ####################################################################################################
#Include, %A_ScriptDir%\resources\Version.txt
; #####################################################################################################################
; # This script checks if the right AHK version is installed and runs the ItemInfo merge script.
; #####################################################################################################################
#Include %A_ScriptDir%\resources\Version.txt

MsgWrongAHKVersion := "AutoHotkey v" . AHKVersionRequired . " 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 < AHKVersionRequired)
{
MsgBox, 16, Wrong AutoHotkey Version, % MsgWrongAHKVersion
ExitApp
MsgWrongAHKVersion := "AutoHotkey v" . AHKVersionRequired . " or later is needed to run this script. It is important not to run version 2.x. `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 < AHKVersionRequired or A_AhkVersion >= "2.0.00.00")
{
MsgBox, 16, Wrong AutoHotkey Version, % AHKVersionRequired
ExitApp
}

RunAsAdmin()
If (!PoEScripts_CreateTempFolder(A_ScriptDir, "PoE-ItemInfo")) {
ExitApp
}

If (InStr(A_ScriptDir, A_Desktop)) {
Msgbox, 0x1010, Invalid Installation Path, Executing PoE-ItemInfo from your Desktop may cause script errors, please choose a different directory.
}

/*
Set ProjectName to create user settings folder in A_MyDocuments
*/
projectName := "PoE-ItemInfo"
FilesToCopyToUserFolder := ["\resources\config\default_config.ini", "\resources\ahk\default_AdditionalMacros.txt", "\resources\ahk\default_MapModWarnings.txt"]
overwrittenFiles := PoEScripts_HandleUserSettings(projectName, A_MyDocuments, "", FilesToCopyToUserFolder, A_ScriptDir)
isDevelopmentVersion := PoEScripts_isDevelopmentVersion()
userDirectory := A_MyDocuments . "\" . projectName . isDevelopmentVersion

PoEScripts_CompareUserFolderWithScriptFolder(userDirectory, A_ScriptDir, projectName)

/*
merge all scripts into `_ItemInfoMain.ahk` and execute it.
*/
info := ReadFileToMerge(A_ScriptDir "\resources\ahk\POE-ItemInfo.ahk")
addMacros := ReadFileToMerge(userDirectory "\AdditionalMacros.txt")

info := info . "`n`r`n`r"
addMacros := "#IfWinActive Path of Exile ahk_class POEWindowClass ahk_group PoEexe" . "`n`r`n`r" . addMacros
addMacros .= AppendCustomMacros(userDirectory)

CloseScript("ItemInfoMain.ahk")
FileDelete, %A_ScriptDir%\_ItemInfoMain.ahk
FileCopy, %A_ScriptDir%\resources\ahk\POE-ItemInfo.ahk, %A_ScriptDir%\_ItemInfoMain.ahk

FileAppend, %addMacros% , %A_ScriptDir%\_ItemInfoMain.ahk

; set script hidden
FileSetAttrib, +H, %A_ScriptDir%\_ItemInfoMain.ahk
; pass some parameters to ItemInfo
Run "%A_AhkPath%" "%A_ScriptDir%\_ItemInfoMain.ahk" "%projectName%" "%userDirectory%" "%isDevelopmentVersion%" "%overwrittenFiles%"

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()
{
ShellExecute := A_IsUnicode ? "shell32\ShellExecute":"shell32\ShellExecuteA"
If Not A_IsAdmin
{
If A_IsCompiled
DllCall(ShellExecute, uint, 0, str, "RunAs", str, A_ScriptFullPath, str, A_WorkingDir, int, 1)
Else
DllCall(ShellExecute, uint, 0, str, "RunAs", str, A_AhkPath, str, """" . A_ScriptFullPath . """", str, A_WorkingDir, int, 1)
ExitApp
}
}

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
}
}
Run "%A_AhkPath%" "%A_ScriptDir%\resources\ahk\Merge_ItemInfo.ahk" "%A_ScriptDir%"
ExitApp
160 changes: 8 additions & 152 deletions Run_TradeMacro.ahk
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
; #####################################################################################################################
; # 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.
; # This script checks if the right AHK version is installed and runs the TradeMacro merge script.
; #####################################################################################################################
#Include, %A_ScriptDir%\resources\VersionTrade.txt
#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)
TradeMsgWrongAHKVersion := "AutoHotkey v" . TradeAHKVersionRequired . " or later is needed to run this script. It is important not to run version 2.x. `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 or A_AhkVersion >= "2.0.00.00")
{
MsgBox, 16, Wrong AutoHotkey Version, % TradeMsgWrongAHKVersion
ExitApp
MsgBox, 16, Wrong AutoHotkey Version, % TradeMsgWrongAHKVersion
ExitApp
}

arguments := ""
Expand All @@ -18,147 +16,5 @@ 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
}
}
Run "%A_AhkPath%" "%A_ScriptDir%\resources\ahk\Merge_TradeMacro.ahk" "%A_ScriptDir%" %arguments%
ExitApp
1 change: 1 addition & 0 deletions data_trade/currencyData_Fallback_Hardcore.json

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions data_trade/currencyData_Fallback_Standard.json

Large diffs are not rendered by default.

29 changes: 29 additions & 0 deletions lib/PoEScripts_CheckFolderWriteAccess.ahk
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
PoE_Scripts_CheckFolderWriteAccess(Folder, critical = true) {
access := FolderWriteAccess(Folder)

msg := "The script is not able to write any file to " Folder ".`nYour user may not have the necessary permissions. "
msg .= "While it may be possible to manually copy and create files in this folder it doesn't work programmatically.`n`n"
msg .= "The reason for this could be your AntiVir software blocking Autohotkey from modifying files in this directory!"

If (not access) {
If (critical) {
msg .= "`n`nClosing Script..."
Msgbox, 0x1010, Critical permission error, % msg
ExitApp
} Else {
Msgbox, 4096, Permission error, % msg
}
}
Return access
}

FolderWriteAccess(Folder) {
If InStr( FileExist(Folder), "D" ) {
FileAppend,,%Folder%\fa.tmp
rval := ! ErrorLevel
FileDelete, %Folder%\fa.tmp
Return rval
} Return - 1
}


Loading

0 comments on commit d6f25ce

Please sign in to comment.