Skip to content

Commit

Permalink
switched to cURL; various fixes/improvements (#398)
Browse files Browse the repository at this point in the history
* added -nosplash argument for the run script

* added additional macro - lookup affixes on poeaffix

* added item base data to download at script start

* switched to using curl to download data files on start

* changed some download error handling; added download debug output

* improved additional macros readme; fixed download error handling

* updated some data/notes/version
  • Loading branch information
Eruyome authored Jul 31, 2017
1 parent 21c4804 commit 72aa8fe
Show file tree
Hide file tree
Showing 10 changed files with 170 additions and 44 deletions.
Binary file modified Fallback.exe
Binary file not shown.
32 changes: 22 additions & 10 deletions Run_TradeMacro.ahk
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,25 @@ If (A_AhkVersion < TradeAHKVersionRequired)
ExitApp
}

arguments = %1%
arguments := ""
Loop, %0% ; For each parameter
{
arguments .= " " Trim(%A_Index%)
}

If (!InStr(arguments, "-noelevation", 0)) {
RunAsAdmin()
RunAsAdmin(arguments)
}
If (InStr(arguments, "-nosplash", 0)) {
skipSplash := 1
} Else {
skipSplash := 0
StartSplashScreen()
}

If (!PoEScripts_CreateTempFolder(A_ScriptDir, "PoE-TradeMacro")) {
ExitApp
ExitApp
}
StartSplashScreen()

/*
Set ProjectName to create user settings folder in A_MyDocuments
Expand Down Expand Up @@ -58,7 +68,7 @@ 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"
Run "%A_AhkPath%" "%A_ScriptDir%\_TradeMacroMain.ahk" "%projectName%" "%userDirectory%" "%isDevelopmentVersion%" "%overwrittenFiles%" "isMergedScript" "%skipSplash%"

ExitApp

Expand All @@ -84,17 +94,19 @@ CloseScript(Name)
Return Name . " not found"
}

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

Return arguments
}

StartSplashScreen() {
Expand Down
2 changes: 1 addition & 1 deletion data_trade/uniques.json

Large diffs are not rendered by default.

16 changes: 8 additions & 8 deletions lib/PoEScripts_Download.ahk
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
}

e := {}
Try {
Try {
commandData := curl
commandHdr := curl
If (binaryDL) {
Expand All @@ -34,8 +34,8 @@
commandData .= "-o """ SavePath """ " ; set target destination and name
}
} Else {
commandData .= " -Ls --compressed " ; follow redirects
commandHdr .= " -ILs " ; follow redirects
commandData .= " -Lks --compressed " ; follow redirects
commandHdr .= " -ILks " ; follow redirects
}
If (StrLen(headers)) {
commandData .= headers
Expand All @@ -58,9 +58,9 @@
If (!binaryDL) {
; Use fallback download if curl fails
If ((not RegExMatch(ioHdr, "i)HTTP\/1.1 200 OK") or e.what) and useFallback) {
DownloadFallback(url, html, e, critical, errorMsg)
DownloadFallback(url, html, e, critical, ioHdr)
} Else If (not RegExMatch(ioHdr, "i)HTTP\/1.1 200 OK" and e.what)) {
ThrowError(e)
ThrowError(e, false, ioHdr)
}
}
; handle binary file downloads
Expand All @@ -80,7 +80,7 @@
html := "Error: Different Size"
}
} Else {
ThrowError(e)
ThrowError(e, false, ioHdr)
}

Return html
Expand Down Expand Up @@ -132,9 +132,9 @@ DownloadFallback(url, ByRef html, e, critical, errorMsg) {
}

ThrowError(e, critical = false, errorMsg = "") {
msg := "Exception thrown (download)!"
msg := "Exception thrown (download)!"
msg .= "`n`nwhat: " e.what "`nfile: " e.file "`nline: " e.line "`nmessage: " e.message "`nextra: " e.extra
msg := StrLen(errorMsg) ? msg "`n`n" errorMsg : msg
msg .= "`n`nwhat: " e.what "`nfile: " e.file "`nline: " e.line "`nmessage: " e.message "`nextra: " e.extra

If (critical) {
MsgBox, 16,, % msg
Expand Down
21 changes: 21 additions & 0 deletions resources/Updates_Trade.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,26 @@
The following is a list of what has been updated, starting with 1.1.0

2.3.6
================================================================================================
Includes changes from previous beta versions:
Replaced the WinHttpRequest library with cURL.
All requests to poe.trade/Github/poe.ninja now support gzip compression. This greatly reduces bandwith usage (and therefore request times).

Rewrote AdditionalMacros.txt:
Hotkeys can be set and enabled/disabled via global variables.
You can completely disable the entire file with all it's hotkeys in the settings menu (ItemInfo tab).
Added a hotkey to open a base item on poeaffix.net.
Added a subfolder "CustomMacros" to the user directory:
This folder is now being created on script start, all files (.txt, .ahk) in there will be appended to AdditionalMacros/TradeMacro.
You can still edit AdditionalMacros, but also add your own macros as seperate files.

Added the "-nosplash" argument for the run script, using it via shortcut/script skips the splashtexts at script start.
Fixed the item parsing for negative mods (for example "-4 maximum charges") and charges in general for Leaguestones failing in some edge cases.
Fixed minimum and maximum dps calculation for uniques being off in some cases (advanced search GUI).
Fixed a bug where some uniques had their lightning damage mod missing (advanced saerch GUI).
Fixed a bug where the maximum value of innate defenses/offenses was being ignored in the request when the minimum value was empty (advanced search).
Rewrote POST request payload generation (much shorter payload).

2.3.5-beta.2
================================================================================================
Replaced WinHttpRequest and the HttpRequest (WinInet.dll) library with cURL.
Expand Down
2 changes: 1 addition & 1 deletion resources/VersionTrade.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
TradeReleaseVersion := "v2.3.5-beta.2"
TradeReleaseVersion := "v2.3.6"
TradeAHKVersionRequired := "1.1.24.01"
67 changes: 66 additions & 1 deletion resources/ahk/POE-ItemInfo.ahk
Original file line number Diff line number Diff line change
Expand Up @@ -9725,7 +9725,7 @@ HighlightItems(broadTerms = false, leaveSearchField = true) {

; Parse the clipboard contents twice.
; If the clipboard contains valid item data before we send ctrl + c to try and parse an item via ctrl + f then don't restore that clipboard data later on.
; This prevents the highlighting funtion to fill search fields with data from previous item parsings/manual data copying since
; This prevents the highlighting function to fill search fields with data from previous item parsings/manual data copying since
; that clipboard data would always be restored again.
Loop, 2 {
If (A_Index = 2) {
Expand Down Expand Up @@ -9927,6 +9927,71 @@ HighlightItems(broadTerms = false, leaveSearchField = true) {
}
}

LookUpAffixes() {
/*
Opens item base on poeaffix.net
*/
IfWinActive, Path of Exile ahk_class POEWindowClass
{
Global Item, Opts, Globals, ItemData

ClipBoardTemp := Clipboard
SuspendPOEItemScript = 1 ; This allows us to handle the clipboard change event

Clipboard :=
Send ^{sc02E} ; ^{c}
Sleep 100

CBContents := GetClipboardContents()
CBContents := PreProcessContents(CBContents)
Globals.Set("ItemText", CBContents)
Globals.Set("TierRelativeToItemLevelOverride", Opts.TierRelativeToItemLevel)
ParsedData := ParseItemData(CBContents)
If (Item.Name) {
dontRestoreClipboard := true
}

If (Item.Name) {
url := "http://poeaffix.net/"
If (RegExMatch(Item.TypeName, "i)Sacrificial Garb")) {
url .= "ch-garb" ; ".html"
} Else {
ev := RegExMatch(ItemData.Stats, "i)Evasion Rating") ? "ev" : ""
ar := RegExMatch(ItemData.Stats, "i)Armour") ? "ar" : ""
es := RegExMatch(ItemData.Stats, "i)Energy Shield") ? "es" : ""
RegExMatch(Item.SubType, "i)Axe|Sword|Mace|Sceptre|Bow|Staff|Wand|Fish", weapon)
RegExMatch(Item.Subtype, "i)Amulet|Ring|Belt|Quiver|Flask", accessory)
RegExMatch(Item.Subtype, "i)Cobalt|Viridian|Crimson", jewel)

suffix := ar . ev . es . weapon . accessory . jewel
StringLower, suffix, suffix

boots := RegExMatch(Item.Subtype, "i)Boots") ? "bt" : ""
chest := RegExMatch(Item.Subtype, "i)BodyArmour") ? "ch" : ""
gloves := RegExMatch(Item.Subtype, "i)Gloves") ? "gl" : ""
helmet := RegExMatch(Item.Subtype, "i)Helmet") ? "hm" : ""
shield := RegExMatch(Item.Subtype, "i)Shield") ? "sh" : ""
ac := StrLen(accessory) ? "ac" : ""
jw := StrLen(jewel) ? "jw" : ""
gripType := Item.GripType != "None" ? Item.GripType : ""

prefix := boots . chest . gloves . helmet . shield . gripType . ac . jw
StringLower, prefix, prefix

url .= prefix "-" suffix ; ".html"
}
openWith := AssociatedProgram("html")
Run, %openWith% -new-tab "%Url%"
}

Sleep, 10
If (!dontRestoreClipboard) {
Clipboard := ClipBoardTemp
}
SuspendPOEItemScript = 0 ; Allow Item info to handle clipboard change event
}
}

; ########### TIMERS ############

; Tick every 100 ms
Expand Down
2 changes: 1 addition & 1 deletion resources/ahk/TradeMacro.ahk
Original file line number Diff line number Diff line change
Expand Up @@ -1304,7 +1304,7 @@ TradeFunc_DoCurrencyRequest(currencyName = "", openSearchInBrowser = false, init
}

; Open given Url with default Browser
TradeFunc_OpenUrlInBrowser(Url){
TradeFunc_OpenUrlInBrowser(Url) {
Global TradeOpts

openWith :=
Expand Down
28 changes: 17 additions & 11 deletions resources/ahk/TradeMacroInit.ahk
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,10 @@ If (A_AhkVersion < TradeAHKVersionRequired)
Menu, Tray, Icon, %A_ScriptDir%\resources\images\poe-trade-bl.ico
Menu, Tray, Add, Open Wiki/FAQ, OpenGithubWikiFromMenu

TradeFunc_StartSplashScreen()
argumentSkipSplash = %6%
If (not argumentSkipSplash) {
TradeFunc_StartSplashScreen()
}

; empty clipboard on start to fix first search searching random stuff
Clipboard := ""
Expand Down Expand Up @@ -1273,26 +1276,29 @@ TradeFunc_ParseSearchFormOptions() {

TradeFunc_DownloadDataFiles() {
; disabled while using debug mode
owner := TradeGlobals.Get("GithubUser", "POE-TradeMacro")
repo := TradeGlobals.Get("GithubRepo", "POE-TradeMacro")
url := "https://raw.githubusercontent.com/" . owner . "/" . repo . "/master/data_trade/"
dir = %A_ScriptDir%\data_trade
bakDir = %A_ScriptDir%\data_trade\old_data_files
files := ["boot_enchantment_mods.txt","crafting_bases.txt","glove_enchantment_mods.txt","helmet_enchantment_mods.txt","item_corrupted_mods.txt","mods.json","uniques.json", "relics.json"]
owner := TradeGlobals.Get("GithubUser", "POE-TradeMacro")
repo := TradeGlobals.Get("GithubRepo", "POE-TradeMacro")
url := "https://raw.githubusercontent.com/" . owner . "/" . repo . "/master/data_trade/"
dir = %A_ScriptDir%\data_trade
bakDir = %A_ScriptDir%\data_trade\old_data_files
files := ["boot_enchantment_mods.txt", "crafting_bases.txt", "glove_enchantment_mods.txt", "helmet_enchantment_mods.txt"
, "mods.json", "uniques.json", "relics.json", "item_bases_armour.json", "item_bases_weapon.json"]

; create .bak files and download (overwrite) data files
; if downlaoded file exists move .bak-file to backup folder, otherwise restore .bak-file
; if downloaded file exists move .bak-file to backup folder, otherwise restore .bak-file
Loop % files.Length() {
file := files[A_Index]
filePath = %dir%\%file%
FileCopy, %filePath%, %filePath%.bak
UrlDownloadToFile, %url%%file%, %filePath%
FileCopy, %filePath%, %filePath%.bak
output := PoEScripts_Download(url . file, postData := "", reqHeaders := "", options := "", false)
FileDelete, %filePath%
FileAppend, %output%, %filePath%

Sleep,50
If (FileExist(filePath) and not ErrorLevel) {
FileMove, %filePath%.bak, %bakDir%\%file%
}
Else {
Else {
FileMove, %dir%\%file%.bak, %dir%\%file%
}
ErrorLevel := 0
Expand Down
44 changes: 33 additions & 11 deletions resources/ahk/default_AdditionalMacros.txt
Original file line number Diff line number Diff line change
@@ -1,21 +1,38 @@
;###########------------------- Additional Macros ---------------------###########
;# Use the global variables to enable/disable hotkeys and set a key combination. #
;# #
;# You can also add your own macros here, but adding your own files in the #
;# subfolder "CustomMacros\" is the more preferable solution. All files there #
;# will be appended/included. Please make sure that any issues that you are #
;# experiencing aren't related to your own macros before reporting them. #
;# #
;# Hotkeys you can use: https://autohotkey.com/docs/KeyList.htm #
;# Autohotkey Quick Reference: https://autohotkey.com/docs/AutoHotkey.htm #
;###########-----------------------------------------------------------###########
;###########----------------------- Additional Macros -------------------------###########
;# Use the global variables to enable/disable hotkeys and set a key combination. #
;# #
;# You can also add your own macros here, but adding your own files in the subfolder #
;# "CustomMacros\" is the more preferable solution. All files there will be appended. #
;# Please make sure that any issues that you are experiencing aren't related to your own #
;# macros before reporting them. #
;# For example, paste the line "^Space::SendInput {Enter}/oos{Enter}" in an ".ahk" file, #
;# place it in the CustomMacros folder and you have your macro ready. It's that easy. #
;# #
;# Hotkeys you can use: https://autohotkey.com/docs/KeyList.htm. #
;# Autohotkey Quick Reference: https://autohotkey.com/docs/AutoHotkey.htm. #
;# Using a hotkey in your custom macro that is assigned in this scrip but set to "off" #
;# won't work since that hotkey exists but is disabled. Use the hotkey command to #
;# overwrite and enable it: https://autohotkey.com/docs/commands/Hotkey.htm. #
;# #
;# Declaring variables or executing code outside of functions, labels or hotkeys won't #
;# work in AdditionalMacros or your custom macros. Read more about it here: #
;# https://autohotkey.com/docs/Scripts.htm#auto (script auto-execute section). #
;# Function calls via hotkeys work though. #
;# #
;# AutoHotkey IDE's and Editor setups (NotePad++, Sublime, Vim): #
;# https://github.com/ahkscript/awesome-AutoHotkey#integrated-development-environment #
;# #
;# Curated list of awesome AHK libs, lib distributions, scripts, tools and resources: #
;# https://github.com/ahkscript/awesome-AutoHotkey #
;###########-------------------------------------------------------------------###########

AM_AssignHotkeys:
; Assign and enable/disable the hotkeys here
global AM_TogglePOEItemScript := ["on", "Pause"]
global AM_Minimize := ["on", "#D"]
global AM_HighlightItems := ["on", "^F"]
global AM_HighlightItemsAlt := ["on", "^!F"]
global AM_LookUpAffixes := ["on", "^L"]
global AM_CloseScripts := ["off", "^Escape"]
global AM_KickYourself := ["off", "F4", "Input your character name here"]
global AM_Hideout := ["on", "F5"]
Expand All @@ -31,6 +48,7 @@ AM_AssignHotkeys:
Hotkey, % AM_Minimize[2] , AM_Minimize_HKey , % AM_Minimize[1]
Hotkey, % AM_HighlightItems[2] , AM_HighlightItems_HKey , % AM_HighlightItems[1]
Hotkey, % AM_HighlightItemsAlt[2] , AM_HighlightItemsAlt_HKey , % AM_HighlightItemsAlt[1]
Hotkey, % AM_LookUpAffixes[2] , AM_LookUpAffixes_HKey , % AM_LookUpAffixes[1]
Hotkey, % AM_CloseScripts[2] , AM_CloseScripts_HKey , % AM_CloseScripts[1]
Hotkey, % AM_KickYourself[2] , AM_KickYourself_HKey , % AM_KickYourself[1]
Hotkey, % AM_Hideout[2] , AM_Hideout_HKey , % AM_Hideout[1]
Expand Down Expand Up @@ -64,6 +82,10 @@ AM_HighlightItemsAlt_HKey:
HighlightItems(true,true) ; Ctrl+Alt+F uses much broader search terms for the highlight function.
Return

AM_LookUpAffixes_HKey:
LookUpAffixes() ; Opens poeaffix.net in your browser, navigating to the item that you're hovering over.
Return

AM_CloseScripts_HKey:
CloseScripts() ; Ctrl+Esc closes all running scripts specified by (and including) ItemInfo or TradeMacro.
Return
Expand Down

0 comments on commit 72aa8fe

Please sign in to comment.