From bee483d44b7081f296bb06d4f9fd02f6957d44db Mon Sep 17 00:00:00 2001 From: zilmar Date: Tue, 29 Sep 2015 13:45:25 +1000 Subject: [PATCH] try to get the script more stable in posting --- Source/Script/upload_beta.vbs | 108 +++++++++++++++++++++++++++++----- 1 file changed, 94 insertions(+), 14 deletions(-) diff --git a/Source/Script/upload_beta.vbs b/Source/Script/upload_beta.vbs index 3429dd48a..95e785d3d 100644 --- a/Source/Script/upload_beta.vbs +++ b/Source/Script/upload_beta.vbs @@ -6,21 +6,41 @@ if WScript.Arguments.Count < 3 then WScript.Quit end if -Set IE = WScript.CreateObject("InternetExplorer.Application", "IE_") +Set IE = CreateIeWindow() +WScript.StdOut.WriteLine IE.HWND IE.Visible = True Login IE PostThread IE IE.Quit +function CreateIeWindow () + Set IE = WScript.CreateObject("InternetExplorer.Application", "IE_") + if IE is nothing then + WScript.StdOut.WriteLine "Failed to create InternetExplorer.Application" + WScript.Quit + end if + IE.Visible = True + + WScript.StdOut.WriteLine IE.HWND + Set CreateIeWindow = IE +End Function + Sub Wait(IE) Dim complete complete = False + WScript.StdOut.WriteLine "Waiting for IE" + For count = 0 to 1000 + WScript.StdOut.WriteLine "before sleep" WScript.Sleep 100 - WScript.StdOut.WriteLine count & ": IE.ReadyState: " & IE.ReadyState - if IE.ReadyState >= 4 then + WScript.StdOut.WriteLine "after sleep" + if IE is nothing then + WScript.StdOut.WriteLine "after sleep" + end if + WScript.StdOut.WriteLine count & ": IE.readyState: " & IE.readyState + if IE.readyState >= 4 then WScript.StdOut.WriteLine count & ": IE.Busy: " & IE.Busy if not IE.Busy then WScript.StdOut.WriteLine count & ": IE.document.readyState: " & IE.document.readyState @@ -36,23 +56,65 @@ Sub Wait(IE) WScript.StdOut.WriteLine "Failed to wait for IE" WScript.Quit end if + WScript.StdOut.WriteLine "IE Done" End Sub +Function FindIeWindow(ieID) + on error resume next + set IE = nothing + + Set Shell = CreateObject("Shell.Application") + For i = 0 to Shell.Windows.Count -1 + set Win = Shell.Windows.Item(i) + WScript.StdOut.WriteLine i & ": " & TypeName(win.Document) + + If TypeName(win.Document) = "HTMLDocument" Then + WScript.StdOut.WriteLine "uniqueID: @" & win.HWND & "@" & ieID & "@" + if win.HWND = ieID then + WScript.StdOut.WriteLine "matched" + set IE = win + end if + End If + if not IE is nothing then + exit for + end if + Next + set FindIeWindow = IE + + if IE is nothing then + WScript.StdOut.WriteLine "Failed to find navigating window" + else + WScript.StdOut.WriteLine "HWND : " & IE.HWND + end if +End Function + Sub Navigate(IE, url) - WScript.StdOut.WriteLine "Navigating to: " & url + dim ieId + ieID = IE.HWND + WScript.StdOut.WriteLine "Navigating (" & IE.HWND & ") to: " & url IE.Navigate url + WScript.Sleep 100 + set IE = FindIeWindow(ieID) Wait IE End Sub Sub ValidateLoggedIn(IE) + WScript.StdOut.WriteLine "ValidateLoggedIn - 1" WScript.StdOut.WriteLine "ValidateLoggedIn start" + WScript.StdOut.WriteLine "ValidateLoggedIn - 2" Navigate IE, "http://forum.pj64-emu.com/" + WScript.StdOut.WriteLine "ValidateLoggedIn - 3" Wait IE + WScript.StdOut.WriteLine "ValidateLoggedIn - 4" Dim LoggedIn LoggedIn = False + WScript.StdOut.WriteLine "ValidateLoggedIn - 5" Set NodeList = IE.document.getElementsByTagName("a") + WScript.StdOut.WriteLine "ValidateLoggedIn - 6" + WScript.StdOut.WriteLine "Got Node list" For Each Elem In NodeList + WScript.StdOut.WriteLine Elem.href if lcase(Mid(Elem.href,1,39)) = "http://forum.pj64-emu.com/member.php?u=" then if lcase(Mid(Elem.parentElement.innerHTML,1,11)) = "welcome,