Advertisement
Tekstbeholder

Autohotkey - PeerBloch Portable startup

Jul 12th, 2016
198
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. ; TWO THINGS YOU NEED TO CHANGE
  2. ;  1. The path to "PeerBlockPortable.exe"
  3. ;  2. Possible size of errormessage windows. Use Windows spy to get those.
  4.  
  5. Global peerBlockExePath
  6.  
  7. ; You will need to change this to wherever the program is located.
  8. peerBlockExePath := "E:\PeerBlockPortable\P<eerBlockPortable.exe"
  9.  
  10. ; Make sure that the executable given above actually exist.
  11. IfNotExist, %peerBlockExePath%
  12. {
  13.     MsgBox, 0, ERROR, The following path is given`, but this given path doesn't exist:`n `"%peerBlockExePath%`"`n`n  Now quit!
  14.     ExitApp, 1
  15. }
  16.  
  17. ; Check if one of the known processes is already launched
  18. Process, Exist, PeerBlockPortable.exe
  19. If errorlevel
  20. {
  21.     TrayTip, The program is already running, The process `"PeerBlockPortable.exe`" was running BEFORE the script started`n`n Quits in two seconds.
  22.     Sleep 2000
  23.     ExitApp
  24. }
  25.  
  26. Process, Exist, peerblock.exe
  27. If errorlevel
  28. {
  29.     TrayTip, The program is already running, The process `"peerblock.exe`" was running BEFORE the script started`n`n Quits in two seconds.
  30.     Sleep 2000
  31.     ExitApp
  32. }
  33.  
  34.  
  35.  
  36.  
  37. tryStartAgain:
  38. ; Restarting. It goes back here if restart attempt is caused by the errormessage "Application was not properly closed" (not quite correct quoted)
  39. ; That issue is the reason why I made this script in first place.
  40. Run, %peerBlockExePath%
  41. TrayTip, Attempt to start PeerBloch portable, There is executed a command to start the program:`n`n`"%peerBlockExePath%`"
  42.  
  43. ; Changes to 1 when the launcher is finnished
  44. launcherHasFinished := 0
  45.  
  46. ; Looks for error messages and nag boxes.
  47. ; Must run for 30 seconds - 10 seconds is too little, because then the nag boxes tends to wait for longer time at Windows startup.
  48. hovedLoop:
  49. Loop, 300
  50. {
  51.    
  52.     portableAppsErrormsgStatus := sjekkStatusFeilmelding()
  53.     ;TrayTip, Feilboks status, Status nr er %portableAppsErrormsgStatus%
  54.    
  55.     ; Når nag-vindu er funnet, så skal det ikke brukes unødige ressurser til å sjekke for vinduer som
  56.     ; VET ikke vil komme.
  57.     If !launcherHasFinished
  58.     {
  59.         If (portableAppsErrormsgStatus = 1) {
  60.             WinActivate, PeerBlock Portable (PortableApps.com Launcher)
  61.             Sleep, 100
  62.             Click 363, 103  ; På OK-boksen
  63.             Sleep 500
  64.             Goto, tryStartAgain
  65.         }
  66.        
  67.         If (portableAppsErrormsgStatus = 2) {
  68.             WinActivate, PeerBlock Portable (PortableApps.com Launcher)
  69.             Sleep, 100
  70.             Click 301, 102  ; På OK-boksen
  71.             Sleep 500
  72.             Goto, tryStartAgain
  73.         }
  74.        
  75.         If (portableAppsErrormsgStatus = 3) {
  76.             WinActivate, PeerBlock Portable (PortableApps.com Launcher)
  77.             Sleep, 100
  78.             Click 304, 101  ; På OK-boksen
  79.             Sleep 1000  ; trenger lengre tid pga oppstart kom for tett innpå forrige session.
  80.             Goto, tryStartAgain
  81.         }
  82.     }
  83.    
  84.    
  85.     ; 23.05.2016 - NAG vindu for den vil ha betaling for oppdatering av lister....
  86.     ;If WinExist("List Update Error Detected")
  87.     ; 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.
  88.     While, WinExist("List Update Error Detected")
  89.     {
  90.         WinActivate
  91.         Sleep 20
  92.         ;Send {Alt down}o{Alt up}   ; Aktiverer OK knappen [Often fails while Windows still ot finnish loading startup apps]
  93.         klikkReturnFaster(330,252)  ; OK knappen
  94.         Sleep 20
  95.         If (A_index > 50) {
  96.             MsgBox, 0, Kunne ikke, Ahk var ikke i stand til å få avsluttet NAG-boksen ved kun å sende Alt+O.
  97.             Break
  98.         }
  99.     }
  100.    
  101.    
  102.     ; Detects the error mesage box that have the button - Visible text == "Close -"
  103.     ; Check 2
  104.     ; I've learn that the below WinExist syntax can compare to a pseudo code similar to : If( window.name == Updating && window.visibleText.contains("Close -") )
  105.     While, WinExist("Updating", "Close -")
  106.     {
  107.         launcherHasFinished := 1
  108.         IfWinExist, List Update Error Detected  ; That error message will always be on top over other boxes when it appear.
  109.             Break
  110.         WinActivate
  111.         Sleep 20
  112.         klikkReturnFaster(160,314)  ; "Close"
  113.         Sleep 20
  114.         If (A_index > 30) {
  115.             MsgBox, 0, Could not close, Ahk was somehow not able to close the error message despite 30 tries.
  116.             Break, hovedLoop
  117.         }
  118.     }
  119.     Sleep 120
  120. }
  121.  
  122.  
  123. ; Check if the active window have a size that matches known size for error messages.
  124. ; Return values
  125. ; 0 - No error messages open at this point
  126. ; 1 - Portableapps error message - size variant 1
  127. ; 2 - Portableapps error message - size variant 2
  128. sjekkStatusFeilmelding() {
  129.    
  130.     IfWinExist, PeerBlock Portable (PortableApps.com Launcher)
  131.     {
  132.         ; Samle informasjon om vindu (navn angitt)
  133.         WinGetPos, X, Y, Width, Height, PeerBlock Portable (PortableApps.com Launcher)
  134.         ; PeerBlock Portable did not close properly last time it was run and will now clean up. Please then start PeerBlock Portable again manually.
  135.         If (Height=126 || Height=119) {
  136.             If (Width=726)
  137.                 Return 1
  138.             Else If (Width=608)
  139.                 Return 2
  140.             Else If (Width=606)
  141.                 Return 3
  142.         }
  143.         Else
  144.             Return 0
  145.     }
  146. }
  147.  
  148.  
  149. ; It works like regular Click, exept it put mouse pointer back to its original position on screen.
  150. klikkReturnFaster(xvar, yvar) {
  151.     MouseGetPos, musX, musY
  152.     MouseMove, xvar, yvar, 0
  153.     Send {LButton}
  154.     MouseMove, musX, musY, 0
  155. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement