Advertisement
Guest User

update_gw2

a guest
Jun 11th, 2015
316
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 2.10 KB | None | 0 0
  1. #! /usr/bin/env zsh
  2.  
  3. ######################
  4. ##### EDIT THIS: #####
  5. ######################
  6.  
  7. local GW2_PATH="$HOME/.wine/drive_c/Program Files/Guild Wars 2"
  8.  
  9. ####################################
  10. ##### DON'T EDIT BELOW HERE ^^ #####
  11. ####################################
  12.  
  13. # Variables:
  14. local CNT=0
  15. local CRASH_CHECK
  16. local CRASH_WINDOW
  17. local UPDATED=0
  18. local WINEDEBUG
  19. # Time between checks. Easy to edit.
  20. local TIME_CHECKS=10
  21.  
  22. # Before anything... Check if xdotool is avaible.
  23. if [[ ! $(command -v xdotool) ]]; then
  24.   print "This script requires xdotool to work properly. Aborting."
  25.   return -1
  26. fi
  27.  
  28. # Enter Gw2's directory:
  29. cd $GW2_PATH
  30.  
  31. # Let's print a stat message:
  32. print "Guild Wars 2 updater running. Press ctrl+c to stop it."
  33.  
  34. # We'll keep doing this until Gw2 has been updated.
  35. while [[ $UPDATED == 0 ]]; do
  36.  
  37.   # Ok, we start Gw2 so it can update.
  38.   WINEDEBUG=-all wine Gw2.exe -dx9single -image &
  39.  
  40.   # Keep track of the number of iterations:
  41.   CNT=$(($CNT + 1))
  42.   print "Iteration $CNT..."
  43.  
  44.   # Let's wait the default time vefore starting the checks.
  45.   sleep $TIME_CHECKS
  46.  
  47.   # Set the check variable for the loop
  48.   CRASH_CHECK=0
  49.   # As long as Gw2.exe is running, we'll keep checking:
  50.   while [[ ! "$(pidof Gw2.exe)" == "" ]]; do
  51.     # Ok, Gw2.exe is running. Did it crash?
  52.     CRASH_WINDOW=$(xdotool search --name "Gw2.exe")
  53.     if [[ ! $CRASH_WINDOW == "" ]]; then
  54.       # Ok, it crashed, so...
  55.       # 1. Let's close the crash report window.
  56.       xdotool windowfocus $CRASH_WINDOW
  57.       xdotool key Escape
  58.       # 2. Let's note that it did crash.
  59.       CRASH_CHECK=1
  60.     else
  61.       # It didn't crash, so it's still updating! Let's give it some time...
  62.       sleep $TIME_CHECKS
  63.     fi
  64.   done
  65.  
  66.   # At this point, no wineserver should be running. But just in case...
  67.   sleep 3
  68.   sync
  69.   wineserver -k
  70.  
  71.   # Update check: Gw2.exe isn't running. Did it crash or did it update correctly?
  72.   if [[ $CRASH_CHECK == 0 ]]; then
  73.     # Gw2 updated succesfully!
  74.     UPDATED=1
  75.   fi
  76.  
  77. done
  78.  
  79. # Unset variables
  80. unset CNT CRASH_CHECK CRASH_WINDOW UPDATED WINEDEBUG TIME_CHECKS
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement