The file downloads successfully, the download window closes successfully, but something never ends.
SW_Download(pUrl,pFile,pTitle="",pGuiNum="") { global If pGuiNum { GuiNum = %pGuiNum%: Gui, %GuiNum%Default } If Not pTitle pTitle := SubStr(pFile,InStr(pFile,"\","-1")+1) thisDownloadSW := SW_Create("Downloading " . pTitle,300,125,pGuiNum) ; Create the window ;Gui, Add, Text, x8 y27 w280 h60 +backgroundtrans, Downloading %pTitle% Gui, Add, Progress, w280 h30 x8 y27 background424242 c282828 vSWDLprogress Gui, Add, Text, xp y+10 h30 +backgroundtrans vSWDLtext1, %pTitle% - Gui, Add, Text, x+5 yp h30 +backgroundtrans w150 vSWDLtext2, SW_Show() Gui, -Resize VarSetCapacity(vt, 4*11), nParam = 31132253353 Loop, Parse, nParam NumPut(RegisterCallback("SW_DownloadProgress", "Fast", A_LoopField, A_Index-1), vt, 4*(A_Index-1)) DllCall("urlmon\URLDownloadToFileA", "Uint", 0, "str", pUrl, "str", pFile, "Uint", 0, "UintP", &vt) WinWaitClose,% "ahk_id " . SteamWin%thisDownloadSW%WinID Return 1 } SW_DownloadProgress(pthis, nProgress = 0, nProgressMax = 0, nStatusCode = 0, pStatusText = 0) { global If (A_EventInfo = 6) { GuiControl,,SWDLprogress,% p := 100 * nProgress//nProgressMax GuiControl,,SWDLtext2,%nProgress% of %nProgressMax% If (p = 100) WinClose,% "ahk_id " . SteamWin%thisDownloadSW%WinID } Return 0 }
Update: OK, actually, it's the WinWaitClose that never ends. But I don't understand it... the download window is successfully closed with WinClose, and WinWaitClose uses the exact same ahk_id for the title. Oh well, I guess the issue is unrelated to the download--thanks for the cool script!
Update 2: Odd, not even this works:
Loop IfWinNotExist,% "ahk_id " . SteamWin%thisDownloadSW%WinID Break Return 1
Something else in this download script must be stopping this from working. If I remove the code that's supposed to wait for the window, the function completes, but it completes immediately without waiting. If I try and wait for the window, it waits indefinitely even after the window is closed. Hmm...
I even tried setting a global variable in the DownloadProgress function when the download completes, and waiting for that variable in the main script. But it never stops waiting, even after the variable should be set. This is odd behavior. Could the callback or DllCall be somehow responsible?
Without waiting for the window to close, or setting a variable upon completion, I don't know how to know when the download is complete. Not to mention, is that going to mean I can't wait for any more windows in the remainder of my script? This is confusing.