Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ; TWO THINGS YOU NEED TO CHANGE
- ; 1. The path to "PeerBlockPortable.exe"
- ; 2. Possible size of errormessage windows. Use Windows spy to get those.
- Global peerBlockExePath
- ; You will need to change this to wherever the program is located.
- peerBlockExePath := "E:\PeerBlockPortable\P<eerBlockPortable.exe"
- ; Make sure that the executable given above actually exist.
- IfNotExist, %peerBlockExePath%
- {
- MsgBox, 0, ERROR, The following path is given`, but this given path doesn't exist:`n `"%peerBlockExePath%`"`n`n Now quit!
- ExitApp, 1
- }
- ; Check if one of the known processes is already launched
- Process, Exist, PeerBlockPortable.exe
- If errorlevel
- {
- TrayTip, The program is already running, The process `"PeerBlockPortable.exe`" was running BEFORE the script started`n`n Quits in two seconds.
- Sleep 2000
- ExitApp
- }
- Process, Exist, peerblock.exe
- If errorlevel
- {
- TrayTip, The program is already running, The process `"peerblock.exe`" was running BEFORE the script started`n`n Quits in two seconds.
- Sleep 2000
- ExitApp
- }
- tryStartAgain:
- ; Restarting. It goes back here if restart attempt is caused by the errormessage "Application was not properly closed" (not quite correct quoted)
- ; That issue is the reason why I made this script in first place.
- Run, %peerBlockExePath%
- TrayTip, Attempt to start PeerBloch portable, There is executed a command to start the program:`n`n`"%peerBlockExePath%`"
- ; Changes to 1 when the launcher is finnished
- launcherHasFinished := 0
- ; Looks for error messages and nag boxes.
- ; Must run for 30 seconds - 10 seconds is too little, because then the nag boxes tends to wait for longer time at Windows startup.
- hovedLoop:
- Loop, 300
- {
- portableAppsErrormsgStatus := sjekkStatusFeilmelding()
- ;TrayTip, Feilboks status, Status nr er %portableAppsErrormsgStatus%
- ; Når nag-vindu er funnet, så skal det ikke brukes unødige ressurser til å sjekke for vinduer som
- ; VET ikke vil komme.
- If !launcherHasFinished
- {
- If (portableAppsErrormsgStatus = 1) {
- WinActivate, PeerBlock Portable (PortableApps.com Launcher)
- Sleep, 100
- Click 363, 103 ; På OK-boksen
- Sleep 500
- Goto, tryStartAgain
- }
- If (portableAppsErrormsgStatus = 2) {
- WinActivate, PeerBlock Portable (PortableApps.com Launcher)
- Sleep, 100
- Click 301, 102 ; På OK-boksen
- Sleep 500
- Goto, tryStartAgain
- }
- If (portableAppsErrormsgStatus = 3) {
- WinActivate, PeerBlock Portable (PortableApps.com Launcher)
- Sleep, 100
- Click 304, 101 ; På OK-boksen
- Sleep 1000 ; trenger lengre tid pga oppstart kom for tett innpå forrige session.
- Goto, tryStartAgain
- }
- }
- ; 23.05.2016 - NAG vindu for den vil ha betaling for oppdatering av lister....
- ;If WinExist("List Update Error Detected")
- ; 24.05.2016 - Viser seg at scriptet feiler, lykkes ikke med å få bort nag-vinduet i alle tilfeller. Spesielt under oppstart hvor vinduet henger litt.
- While, WinExist("List Update Error Detected")
- {
- WinActivate
- Sleep 20
- ;Send {Alt down}o{Alt up} ; Aktiverer OK knappen [Often fails while Windows still ot finnish loading startup apps]
- klikkReturnFaster(330,252) ; OK knappen
- Sleep 20
- If (A_index > 50) {
- MsgBox, 0, Kunne ikke, Ahk var ikke i stand til å få avsluttet NAG-boksen ved kun å sende Alt+O.
- Break
- }
- }
- ; Detects the error mesage box that have the button - Visible text == "Close -"
- ; Check 2
- ; I've learn that the below WinExist syntax can compare to a pseudo code similar to : If( window.name == Updating && window.visibleText.contains("Close -") )
- While, WinExist("Updating", "Close -")
- {
- launcherHasFinished := 1
- IfWinExist, List Update Error Detected ; That error message will always be on top over other boxes when it appear.
- Break
- WinActivate
- Sleep 20
- klikkReturnFaster(160,314) ; "Close"
- Sleep 20
- If (A_index > 30) {
- MsgBox, 0, Could not close, Ahk was somehow not able to close the error message despite 30 tries.
- Break, hovedLoop
- }
- }
- Sleep 120
- }
- ; Check if the active window have a size that matches known size for error messages.
- ; Return values
- ; 0 - No error messages open at this point
- ; 1 - Portableapps error message - size variant 1
- ; 2 - Portableapps error message - size variant 2
- sjekkStatusFeilmelding() {
- IfWinExist, PeerBlock Portable (PortableApps.com Launcher)
- {
- ; Samle informasjon om vindu (navn angitt)
- WinGetPos, X, Y, Width, Height, PeerBlock Portable (PortableApps.com Launcher)
- ; PeerBlock Portable did not close properly last time it was run and will now clean up. Please then start PeerBlock Portable again manually.
- If (Height=126 || Height=119) {
- If (Width=726)
- Return 1
- Else If (Width=608)
- Return 2
- Else If (Width=606)
- Return 3
- }
- Else
- Return 0
- }
- }
- ; It works like regular Click, exept it put mouse pointer back to its original position on screen.
- klikkReturnFaster(xvar, yvar) {
- MouseGetPos, musX, musY
- MouseMove, xvar, yvar, 0
- Send {LButton}
- MouseMove, musX, musY, 0
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement