home *** CD-ROM | disk | FTP | other *** search
/ PC World 2005 April / PCWorld_2005-04_cd.bin / software / vyzkuste / autoit / autoit-v3-setup.exe / Extras / AutoUpdateIt.au3 < prev    next >
Windows Autorun File  |  2005-02-07  |  22KB  |  624 lines

  1. ; =======================================================================
  2. ; AutoUpdateIt
  3. ;
  4. ; Command Line Options:
  5. ;  - AutoUpdateIt.au3 [/release | /beta] [/silent]
  6. ;    - /release   Download latest release
  7. ;    - /beta      Download latest beta
  8. ;    - /silent    Silently auto-install (resets all settings)
  9. ;
  10. ; History:
  11. ;  - 1.33 - Added Retry/Cancel msgbox when cannot connect to receive update file
  12. ;         - Added Progress bar for non-WinXP users
  13. ;  - 1.32 - Changed _CompareVersions again (integer comparison now)
  14. ;  - 1.31 - Rewrote _ClipPath again
  15. ;  - 1.30 - Rewrote a few UDFs (_CompareVersions, _ClipPath)
  16. ;         - Underscored all UDF names
  17. ;         - Removed a misplaced 'Then' screwing up command line options
  18. ;  - 1.21 - Stupid bug fixed (ignored version check for /beta command)
  19. ;         - CompareVersions function works properly now (was seeing 3.0.103.173 as newer than 3.1.0.1)
  20. ;  - 1.20 - Command line parameters added
  21. ;           - /release to check for latest public release
  22. ;           - /beta to check for latest beta
  23. ;           - /silent to install silently (you will lose your compiler and file settings)
  24. ;  - 1.11 - Starts the download when you press one of the download
  25. ;           buttons, resulting in pre-downloading while you choose
  26. ;           where to save the file
  27. ;         - Default name for Beta download includes full version string
  28. ;         - Deletes "au3_update.dat" from temp files after loading data
  29. ;  - 1.10 - Displays release date
  30. ;         - Changed layout of buttons / groups
  31. ;         - Slightly modified error message when server inaccessible
  32. ;  - 1.00 - "Release" / given a version number
  33. ;
  34. ; Forum Thread:
  35. ;  - http://www.autoitscript.com/forum/index.php?showtopic=7547&view=getnewpost
  36. ;
  37. ; =======================================================================
  38.  
  39. #NoTrayIcon
  40. #Include <GUIConstants.au3>
  41.  
  42. ; ========================================
  43. ; Predefine variables
  44. ; ========================================
  45. Global Const $s_Title = 'AutoUpdateIt'
  46. Global Const $s_Version = '1.33'
  47. Global Const $s_DatFile = 'http://www.autoitscript.com/autoit3/update.dat'
  48. Global Const $s_DatFile_Local = @TempDir & '\au3_update.dat'
  49. Global Const $s_Au3UpReg = 'HKCU\Software\AutoIt v3\AutoUpdateIt'
  50.  
  51. Global $i_DownSize, $s_DownPath, $s_DownTemp, $s_DownFolder
  52. Global $i_DatFileLoaded, $i_ValidAu3Path, $i_DnInitiated
  53. Global $s_AutoUpdate, $i_SilentInstall
  54.  
  55. ; ========================================
  56. ; Read registry settings
  57. ; ========================================
  58. Global $s_DefDownDir = RegRead($s_Au3UpReg, 'DownloadDir')
  59. If @error Then
  60.     $s_DefDownDir = @DesktopDir
  61. EndIf
  62.  
  63. Global $s_Au3Path = RegRead('HKLM\Software\AutoIt v3\AutoIt', 'InstallDir')
  64. If Not @error And FileExists($s_Au3Path & '\AutoIt3.exe') Then
  65.     $s_CurrVer = FileGetVersion($s_Au3Path & "\AutoIt3.exe")
  66.     $s_CurrDate = _FriendlyDate(FileGetTime($s_Au3Path & "\AutoIt3.exe", 0, 1))
  67. Else
  68.     $s_Au3Path = 'Installation not found'
  69.     $s_CurrVer = 'Unavailable'
  70. EndIf
  71.  
  72. ; ========================================
  73. ; Check for command line parameters
  74. ; ========================================
  75. If _StringInArray($CmdLine, '/release') Or _StringInArray($CmdLine, '/beta') Then
  76.     Opt('TrayIconHide', 0)
  77.     _Status('Checking for updates')
  78.     InetGet($s_DatFile, $s_DatFile_Local, 1)
  79.     If @InetGetBytesRead = -1 Then
  80.         _Status('Could not connect to site', 'Please check your connection and try again')
  81.         Sleep(4000)
  82.         Exit
  83.     EndIf
  84.     _LoadUpdateData()
  85.     
  86.     If _StringInArray($CmdLine, '/release') And _CompareVersions($s_ReleaseVer, $s_CurrVer) Then
  87.         $s_AutoUpdate = $s_ReleaseFile
  88.         $s_DownTemp = @TempDir & '\autoit-v3-setup.exe'
  89.         $i_DownSize = $i_ReleaseSize
  90.     ElseIf _StringInArray($CmdLine, '/beta') And _CompareVersions($s_BetaVer, $s_CurrVer) Then
  91.         $s_AutoUpdate = $s_BetaFile
  92.         $s_DownTemp = @TempDir & '\autoit-v' & $s_BetaVer & '.exe'
  93.         $i_DownSize = $i_BetaSize
  94.     EndIf
  95.  
  96.     If $s_AutoUpdate Then
  97.         InetGet($s_AutoUpdate, $s_DownTemp, 1, 1)
  98.         $s_DownSize = Round($i_ReleaseSize / 1024) & ' KB'
  99.         While @InetGetActive
  100.             _Status('Downloading update', '', @InetGetBytesRead, $i_DownSize)
  101.         WEnd
  102.         _Status('Download Complete', 'Launching install')
  103.         Sleep(1000)
  104.         If _StringInArray($CmdLine, '/silent') Then
  105.             _Start('"' & $s_DownTemp & '" /S')
  106.         Else
  107.             _Start('"' & $s_DownTemp & '"')
  108.         EndIf
  109.     Else
  110.         _Status('No new versions available')
  111.         Sleep(1000)
  112.     EndIf
  113.     Exit
  114. EndIf
  115.  
  116. ; ========================================
  117. ; GUI - Main Application
  118. ; ========================================
  119. $gui_Main = GuiCreate($s_Title, 350, 310+20)
  120.  
  121. $me_Mn_Help = GuiCtrlCreateMenu('&Help')
  122. $me_Mn_VisitSite = GuiCtrlCreateMenuItem('&Visit the AutoIt3 Website', $me_Mn_Help)
  123. $me_Mn_About = GuiCtrlCreateMenuItem('&About', $me_Mn_Help)
  124.  
  125. GuiCtrlCreateLabel('', 0, 0, 350, 2, $SS_SUNKEN)
  126.  
  127. GuiCtrlCreateGroup('Current Installation Details', 5, 5, 340, 75)
  128. GuiCtrlCreateLabel('Version: ' & $s_CurrVer, 15, 25, 300, 15)
  129. GuiCtrlCreateLabel('Date: ' & $s_CurrDate, 15, 40, 300, 15)
  130. GuiCtrlCreateLabel('Install Path: ' & $s_Au3Path, 15, 55, 300, 15)
  131.  
  132. $gr_Mn_Release = GuiCtrlCreateGroup('Latest Public Release', 5, 85, 165, 60)
  133. $lb_Mn_ReleaseVer = GuiCtrlCreateLabel('Version: Loading...', 15, 105, 145, 15)
  134. $lb_Mn_ReleaseDate = GuiCtrlCreateLabel('Date: Loading...', 15, 120, 145, 15)
  135.  
  136. $gr_Mn_Beta = GuiCtrlCreateGroup('Latest Beta', 180, 85, 165, 60)
  137. $lb_Mn_BetaVer = GuiCtrlCreateLabel('Version: Loading...', 190, 105, 145, 15)
  138. $lb_Mn_BetaDate = GuiCtrlCreateLabel('Date: Loading...', 190, 120, 145, 15)
  139.  
  140. GUIStartGroup() 
  141. $ra_Mn_DoneNotify = GuiCtrlCreateRadio('&Notify when download complete', 5, 155, 340, 15)
  142. $ra_Mn_DoneRun = GuiCtrlCreateRadio('&Autorun install when download complete', 5, 175, 340, 15)
  143.  
  144. ; Check default done option
  145. If RegRead($s_Au3UpReg, 'DoneOption') = 'Run' Then
  146.     GuiCtrlSetState($ra_Mn_DoneRun, $GUI_CHECKED)
  147. Else
  148.     GuiCtrlSetState($ra_Mn_DoneNotify, $GUI_CHECKED)
  149. EndIf
  150.  
  151. $bt_Mn_Close = GuiCtrlCreateButton('&Close', 10, 275, 330, 25)
  152.  
  153. ; ========================================
  154. ; Control Set - Download Buttons
  155. ; ========================================
  156.     
  157. $bt_Mn_ReleaseDl = GuiCtrlCreateButton('Download Public &Release', 5, 195, 165, 30)
  158. GuiCtrlSetState(-1, $GUI_DISABLE)
  159. $lb_Mn_ReleaseSize = GuiCtrlCreateLabel('Size: Loading...', 5, 230, 165, 15, $SS_CENTER)
  160. $lb_Mn_ReleasePage = GuiCtrlCreateLabel('Visit Download Page', 5, 245, 165, 15, $SS_CENTER)
  161. GuiCtrlSetState(-1, $GUI_DISABLE)
  162. GuiCtrlSetFont(-1, 9, 400, 4)
  163. GuiCtrlSetColor(-1, 0x0000ff)
  164. GuiCtrlSetCursor(-1, 0)
  165.  
  166. $bt_Mn_BetaDl = GuiCtrlCreateButton('Download &Beta', 180, 195, 165, 30)
  167. GuiCtrlSetState(-1, $GUI_DISABLE)
  168. $lb_Mn_BetaSize = GuiCtrlCreateLabel('Size: Loading...', 180, 230, 165, 15, $SS_CENTER)
  169. $lb_Mn_BetaPage = GuiCtrlCreateLabel('Visit Download Page', 180, 245, 165, 15, $SS_CENTER)
  170.  
  171. GuiCtrlSetState(-1, $GUI_DISABLE)
  172. GuiCtrlSetFont(-1, 9, 400, 4)
  173. GuiCtrlSetColor(-1, 0x0000ff)
  174. GuiCtrlSetCursor(-1, 0)
  175.  
  176. $a_DownButtons = StringSplit($bt_Mn_ReleaseDl & '.' &_
  177.                              $lb_Mn_ReleaseSize & '.' &_
  178.                              $lb_Mn_ReleasePage & '.' &_
  179.                              $bt_Mn_BetaDl & '.' &_
  180.                              $lb_Mn_BetaSize & '.' &_
  181.                              $lb_Mn_BetaPage, '.')
  182.  
  183. ; ========================================
  184. ; Control Set - Download Display
  185. ; ========================================
  186. $lb_Mn_DwnToTtl = GuiCtrlCreateLabel('Downloading to:', 5, 195, 290, 15, $SS_LEFTNOWORDWRAP)
  187. $lb_Mn_DwnToTxt = GuiCtrlCreateLabel('', 5, 210, 290, 15, $SS_LEFTNOWORDWRAP)
  188.  
  189. $pg_Mn_Progress = GuiCtrlCreateProgress(5, 225, 340, 20)
  190. $lb_Mn_Progress = GuiCtrlCreateLabel('', 5, 250, 290, 15)
  191.  
  192. $bt_Mn_OpenFile = GuiCtrlCreateButton('&Open', 105, 275, 75, 25)
  193. GuiCtrlSetState(-1, $GUI_DISABLE)
  194. $bt_Mn_OpenFolder = GuiCtrlCreateButton('Open &Folder', 185, 275, 75, 25)
  195. GuiCtrlSetState(-1, $GUI_DISABLE)
  196.  
  197. $a_DownDisplay = StringSplit($lb_Mn_DwnToTtl & '.' &_
  198.                              $lb_Mn_DwnToTxt & '.' &_
  199.                              $pg_Mn_Progress & '.' &_
  200.                              $lb_Mn_Progress & '.' &_
  201.                              $bt_Mn_OpenFile & '.' &_
  202.                              $bt_Mn_OpenFolder, '.')
  203.  
  204. _GuiCtrlGroupSetState($a_DownDisplay, $GUI_HIDE)
  205.  
  206. ; ========================================
  207. ; GUI - About
  208. ; ========================================
  209. $gui_About = GuiCreate('About', 300, 120, -1, -1, BitOr($WS_CAPTION, $WS_SYSMENU), -1, $gui_Main)
  210. GuiCtrlCreateLabel($s_Title & ' v' & $s_Version & ' - The AutoIt3 Update Utility' & @LF &_
  211.                    @LF &_
  212.                    'This application is a utility for easily receiving the most ' &_
  213.                    'recent public release or beta version of AutoIt3 available. ' &_
  214.                    'It was written completely in AutoIt3 script by Rob Saunders.', 5, 5, 290, 75)
  215.  
  216. $lb_Ab_VisitSite = GuiCtrlCreateLabel('Visit the AutoIt Website', 5, 80, 145, 15)
  217. GuiCtrlSetFont(-1, 9, 400, 4)
  218. GuiCtrlSetColor(-1, 0x0000ff)
  219. GuiCtrlSetCursor(-1, 0)
  220. GuiCtrlSetTip(-1, 'http://www.autoitscript.com')
  221.  
  222. $lb_Ab_ContactAuthor = GuiCtrlCreateLabel('Contact Rob Saunders', 5, 100, 145, 15)
  223. GuiCtrlSetFont(-1, 9, 400, 4)
  224. GuiCtrlSetColor(-1, 0x0000ff)
  225. GuiCtrlSetCursor(-1, 0)
  226. GuiCtrlSetTip(-1, 'rksaunders@gmail.com')
  227.  
  228. $bt_Ab_Close = GuiCtrlCreateButton('&Close', 220, 90, 75, 25)
  229.  
  230. ; ========================================
  231. ; Application start
  232. ; ========================================
  233.  
  234. ; Show Main Window
  235. GuiSetState(@SW_SHOW, $gui_Main)
  236.  
  237. ; Download update data file
  238. InetGet($s_DatFile, $s_DatFile_Local, 1, 1)
  239.  
  240. ; Harness GUI Events
  241. While 1
  242.     $a_GMsg = GUIGetMsg(1)
  243.  
  244.     If Not @InetGetActive And Not $i_DatFileLoaded Then
  245.         If @InetGetBytesRead = -1 Then
  246.             $i_Res = MsgBox(5+16+8192, 'Error', 'Error connecting to server.' & @LF &_
  247.                                                 'Please verify the following:' & @LF &_
  248.                                                 ' - You can connect to the internet' & @LF &_
  249.                                                 ' - You can access the site http://www.AutoItScript.com' & @LF &_
  250.                                                 ' - Your firewall is not blocking internet access to this program')
  251.             If $i_Res = 4 Then
  252.                 InetGet($s_DatFile, $s_DatFile_Local, 1, 1)
  253.             Else
  254.                 Exit
  255.             EndIf
  256.         Else
  257.             _LoadUpdateData()
  258.             $i_ReleaseSizeKB = Round($i_ReleaseSize / 1024)
  259.             $i_BetaSizeKB = Round($i_BetaSize / 1024)
  260.  
  261.             If _CompareVersions($s_ReleaseVer, $s_CurrVer) Then
  262.                 GuiCtrlSetData($gr_Mn_Release, 'Latest Public Release *New*')
  263.                 GuiCtrlSetColor($gr_Mn_Release, 0x0000ff)
  264.             EndIf
  265.             GuiCtrlSetData($lb_Mn_ReleaseVer, 'Version: ' & $s_ReleaseVer)
  266.             
  267.             If _CompareVersions($s_BetaVer, $s_CurrVer) Then
  268.                 GuiCtrlSetData($gr_Mn_Beta, 'Latest Beta *New*')
  269.                 GuiCtrlSetColor($gr_Mn_Beta, 0x0000ff)
  270.             EndIf
  271.             GuiCtrlSetData($lb_Mn_BetaVer, 'Version: ' & $s_BetaVer)
  272.  
  273.             GuiCtrlSetData($lb_Mn_ReleaseDate, 'Date: ' & _FriendlyDate($i_ReleaseDate))
  274.             GuiCtrlSetData($lb_Mn_BetaDate, 'Date: ' & _FriendlyDate($i_BetaDate))
  275.  
  276.             GuiCtrlSetData($lb_Mn_ReleaseSize, 'Size: ' & $i_ReleaseSizeKB & ' KB')
  277.             GuiCtrlSetData($lb_Mn_BetaSize, 'Size: ' & $i_BetaSizeKB & ' KB')
  278.  
  279.             GuiCtrlSetTip($lb_Mn_ReleasePage, $s_ReleasePage)
  280.             GuiCtrlSetTip($lb_Mn_BetaPage, $s_BetaPage)
  281.             
  282.             GuiCtrlSetState($bt_Mn_ReleaseDl, $GUI_ENABLE)
  283.             GuiCtrlSetState($bt_Mn_BetaDl, $GUI_ENABLE)
  284.             GuiCtrlSetState($lb_Mn_ReleasePage, $GUI_ENABLE)
  285.             GuiCtrlSetState($lb_Mn_BetaPage, $GUI_ENABLE)
  286.  
  287.             $i_DatFileLoaded = 1
  288.         EndIf
  289.     EndIf
  290.  
  291.     If $i_DnInitiated Then
  292.         If @InetGetActive Then
  293.             $i_DnPercent = Int(@InetGetBytesRead / $i_DownSize * 100)
  294.  
  295.             $s_DnBytes = Round(@InetGetBytesRead / 1024) & ' KB'
  296.             $s_DnSize = Round($i_DownSize / 1024) & ' KB'
  297.                 
  298.             GuiCtrlSetData($pg_Mn_Progress, $i_DnPercent)
  299.             GuiCtrlSetData($lb_Mn_Progress, 'Download Progress: ' & $i_DnPercent & '% (' & $s_DnBytes & ' of ' & $s_DnSize & ')')
  300.         Else
  301.             GuiCtrlSetData($pg_Mn_Progress, 100)
  302.             If Not FileMove($s_DownTemp, $s_DownPath, 1) Then
  303.                 MsgBox(16+8192, 'Error', 'Error moving file.')
  304.                 GuiCtrlSetData($lb_Mn_Progress, 'Error')
  305.             Else
  306.                 If GuiCtrlRead($ra_Mn_DoneRun) = $GUI_CHECKED Then
  307.                     _Start('"' & $s_DownPath & '"')
  308.                     Exit
  309.                 Else
  310.                     GuiCtrlSetData($lb_Mn_Progress, 'Download Complete!')
  311.  
  312.                     GuiCtrlSetData($bt_Mn_Close, '&Close')
  313.                     GuiCtrlSetState($bt_Mn_OpenFile, $GUI_ENABLE)
  314.                     GuiCtrlSetState($bt_Mn_OpenFolder, $GUI_ENABLE)
  315.                     $i_Response = MsgBox(4+64+256+8192, $s_Title, 'Download complete!' & @LF &_
  316.                                                                   'Would you like to run the installer now?')
  317.                     If $i_Response = 6 Then
  318.                         _Start('"' & $s_DownPath & '"')
  319.                         Exit
  320.                     EndIf
  321.                 EndIf
  322.             EndIf
  323.             
  324.             $i_DnInitiated = 0
  325.         EndIf
  326.     EndIf
  327.  
  328.     If $a_GMsg[1] = $gui_Main Then
  329.         Select
  330.             ; Radio buttons
  331.             Case $a_GMsg[0] = $ra_Mn_DoneRun
  332.                 RegWrite($s_Au3UpReg, 'DoneOption', 'REG_SZ', 'Run')
  333.  
  334.             Case $a_GMsg[0] = $ra_Mn_DoneNotify
  335.                 RegWrite($s_Au3UpReg, 'DoneOption', 'REG_SZ', 'Notify')
  336.             
  337.             ; Download buttons
  338.             Case $a_GMsg[0] = $bt_Mn_ReleaseDl
  339.                 $tmp = StringInStr($s_ReleaseFile, '/', 0, -1)
  340.                 $s_DefFileName = StringTrimLeft($s_ReleaseFile, $tmp)
  341.                 $i_DownSize = $i_ReleaseSize
  342.                 _DownloadFile($s_ReleaseFile, 'autoit-v3-setup.exe')
  343.  
  344.             Case $a_GMsg[0] = $bt_Mn_BetaDl
  345.                 $tmp = StringInStr($s_BetaFile, '/', 0, -1)
  346.                 $s_DefFileName = StringTrimLeft($s_BetaFile, $tmp)
  347.                 $i_DownSize = $i_BetaSize
  348.                 _DownloadFile($s_BetaFile, 'autoit-v' & $s_BetaVer & '.exe')
  349.  
  350.             ; Download page "hyperlinks"
  351.             Case $a_GMsg[0] = $lb_Mn_ReleasePage
  352.                 _Start($s_ReleasePage)
  353.             
  354.             Case $a_GMsg[0] = $lb_Mn_BetaPage
  355.                 _Start($s_BetaPage)
  356.  
  357.             ; Open buttons
  358.             Case $a_GMsg[0] = $bt_Mn_OpenFile
  359.                 _Start('"' & $s_DownPath & '"')
  360.                 Exit
  361.  
  362.             Case $a_GMsg[0] = $bt_Mn_OpenFolder
  363.                 _Start('"' & EnvGet('windir') & '\explorer.exe" /select,"' & $s_DownPath & '"')
  364.                 Exit
  365.  
  366.             ; Menu items
  367.             Case $a_GMsg[0] = $me_Mn_VisitSite
  368.                 _Start('http://www.autoitscript.com')
  369.  
  370.             Case $a_GMsg[0] = $me_Mn_About
  371.                 GuiSetState(@SW_SHOW, $gui_About)
  372.  
  373.             ; Close buttons
  374.             Case $a_GMsg[0] = $bt_Mn_Close
  375.                 _CancelDownload()
  376.                 
  377.             Case $a_GMsg[0] = $GUI_EVENT_CLOSE
  378.                 _CancelDownload(1)
  379.         EndSelect
  380.     ElseIf $a_GMsg[1] = $gui_About Then
  381.         Select
  382.             Case $a_GMsg[0] = $lb_Ab_VisitSite
  383.                 _Start('http://www.autoitscript.com')
  384.  
  385.             Case $a_GMsg[0] = $lb_Ab_ContactAuthor
  386.                 _Start('"mailto:rksaunders@gmail.com?Subject=AutoIt3 Update Utility"')
  387.                 
  388.             Case $a_GMsg[0] = $GUI_EVENT_CLOSE Or $a_GMsg[0] = $bt_Ab_Close
  389.                 GuiSetState(@SW_HIDE, $gui_About)
  390.         EndSelect
  391.     EndIf
  392. Wend
  393.  
  394. ; ========================================
  395. ; Function Declarations
  396. ; ========================================
  397.  
  398. ; App. specific functions
  399.  
  400. Func _DownloadFile($s_DownUrl, $s_DownName)
  401.     $s_DownTemp = @TempDir & '\' & $s_DownName
  402.     InetGet($s_DownUrl, $s_DownTemp, 1, 1)
  403.  
  404.     $s_DownPath = FileSaveDialog('Save As', $s_DefDownDir, 'Executables (*.exe)', 16, $s_DownName)
  405.     If Not @error Then
  406.         If Not (StringRight($s_DownPath, 4) = '.exe') Then
  407.             $s_DownPath = $s_DownPath & '.exe'
  408.         EndIf
  409.  
  410.         $tmp = StringInStr($s_DownPath, '\', 0, -1)
  411.         $s_DownFolder = StringLeft($s_DownPath, $tmp)
  412.         RegWrite($s_Au3UpReg, 'DownloadDir', 'REG_SZ', $s_DownFolder)
  413.         
  414.         GuiCtrlSetData($lb_Mn_DwnToTxt, _ClipPath($s_DownPath, 55))
  415.         GuiCtrlSetData($lb_Mn_Progress, 'Download Progress: Calculating...')
  416.         
  417.         _GuiCtrlGroupSetState($a_DownButtons, $GUI_HIDE)
  418.         _GuiCtrlGroupSetState($a_DownButtons, $GUI_DISABLE)
  419.         _GuiCtrlGroupSetState($a_DownDisplay, $GUI_SHOW)
  420.         GuiCtrlSetPos($bt_Mn_Close, 265, 275, 75, 25)
  421.         GuiCtrlSetData($bt_Mn_Close, 'Cancel')
  422.         
  423.         $i_DnInitiated = 1
  424.     Else
  425.         InetGet('abort')
  426.         FileDelete($s_DownTemp)
  427.     EndIf
  428. EndFunc
  429.  
  430. Func _CancelDownload($i_Flag = 0)
  431.     If $i_DnInitiated Then
  432.         $i_Response = MsgBox(4+64+256+8192, $s_Title, 'Resuming is not possible.' & @LF &_
  433.                                                       'Your download will be lost.' & @LF &_
  434.                                                       'Continue?')
  435.         If $i_Response = 6 Then
  436.             $i_DnInitiated = 0
  437.             InetGet('abort')
  438.             FileDelete($s_DownTemp)
  439.             If $i_Flag = 1 Then
  440.                 Exit
  441.             EndIf
  442.             
  443.             _GuiCtrlGroupSetState($a_DownDisplay, $GUI_HIDE)
  444.  
  445.             GuiCtrlSetData($bt_Mn_Close, '&Close')
  446.             GuiCtrlSetPos($bt_Mn_Close, 10, 275, 330, 25)
  447.             GuiCtrlSetData($pg_Mn_Progress, 0)
  448.  
  449.             _GuiCtrlGroupSetState($a_DownButtons, $GUI_SHOW)
  450.             _GuiCtrlGroupSetState($a_DownButtons, $GUI_ENABLE)
  451.         EndIf
  452.     Else
  453.         Exit
  454.     EndIf
  455. EndFunc
  456.  
  457. Func _LoadUpdateData()
  458.     Global $s_ReleaseVer, $s_ReleaseFile, $s_ReleasePage, $i_ReleaseSize, $i_ReleaseDate
  459.     Global $s_BetaVer, $s_BetaFile, $s_BetaPage, $i_BetaSize, $i_BetaDate
  460.  
  461.     $s_ReleaseVer = IniRead($s_DatFile_Local, 'AutoIt', 'version', 'Error reading file')
  462.     $s_ReleaseFile = IniRead($s_DatFile_Local, 'AutoIt', 'setup', '')
  463.     $s_ReleasePage = IniRead($s_DatFile_Local, 'AutoIt', 'index', 'http://www.autoitscript.com')
  464.     $i_ReleaseSize = IniRead($s_DatFile_Local, 'AutoIt', 'filesize', 0)
  465.     $i_ReleaseDate = IniRead($s_DatFile_Local, 'AutoIt', 'filetime', 0)
  466.  
  467.     $s_BetaVer = IniRead($s_DatFile_Local, 'AutoItBeta', 'version', 'Error reading file')
  468.     $s_BetaFile = IniRead($s_DatFile_Local, 'AutoItBeta', 'setup', '')
  469.     $s_BetaPage = IniRead($s_DatFile_Local, 'AutoItBeta', 'index', 'http://www.autoitscript.com')
  470.     $i_BetaSize = IniRead($s_DatFile_Local, 'AutoItBeta', 'filesize', 0)
  471.     $i_BetaDate = IniRead($s_DatFile_Local, 'AutoItBeta', 'filetime', 0)
  472.     
  473.     FileDelete($s_DatFile_Local)
  474. EndFunc
  475.  
  476. ; Utility functions
  477.  
  478. Func _Start($s_StartPath)
  479.     If @OSType = 'WIN32_NT' Then
  480.         $s_StartStr = @ComSpec & ' /c start "" '
  481.     Else
  482.         $s_StartStr = @ComSpec & ' /c start '
  483.     EndIf
  484.     Run($s_StartStr & $s_StartPath, '', @SW_HIDE)
  485. EndFunc
  486.  
  487. Func _GuiCtrlGroupSetState(ByRef $a_GroupArray, $i_State)
  488.     For $i = 1 to $a_GroupArray[0]
  489.         GuiCtrlSetState($a_GroupArray[$i], $i_State)
  490.     Next
  491. EndFunc
  492.  
  493. Func _ClipPath($s_Path, $i_ClipLen)
  494.     Local $i_Half, $s_Left, $s_Right
  495.  
  496.     If StringLen($s_Path) > $i_ClipLen Then
  497.         $i_Half = Int($i_ClipLen / 2)
  498.         $s_Left = StringLeft($s_Path, $i_Half)
  499.         $s_Right = StringRight($s_Path, $i_Half)
  500.         $s_Path = $s_Left & '...' & $s_Right
  501.     EndIf
  502.     
  503.     Return $s_Path
  504. EndFunc
  505.  
  506. Func _NumSuffix($i_Num)
  507.     Local $s_Num
  508.     If StringRight($i_Num, 1) = 1 Then
  509.         $s_Num = Int($i_Num) & 'st'
  510.     ElseIf StringRight($i_Num, 1) = 2 Then
  511.         $s_Num = Int($i_Num) & 'nd'
  512.     ElseIf StringRight($i_Num, 1) = 3 Then
  513.         $s_Num = Int($i_Num) & 'rd'
  514.     Else
  515.         $s_Num = Int($i_Num) & 'th'
  516.     EndIf
  517.     
  518.     Return $s_Num
  519. EndFunc
  520.  
  521. Func _FriendlyDate($s_Date)
  522.     Local $a_Months = StringSplit('January,February,March,April,May,June,July,August,September,October,November,December', ',')
  523.     Local $s_Year, $s_Month, $s_Day
  524.     
  525.     $s_Year = StringLeft($s_Date, 4)
  526.     $s_Month = StringMid($s_Date, 5, 2)
  527.     $s_Month = $a_Months[Int(StringMid($s_Date, 5, 2))]
  528.     $s_Day = StringMid($s_Date, 7, 2)
  529.     $s_Day = _NumSuffix(StringMid($s_Date, 7, 2))
  530.  
  531.     Return $s_Month & ' ' & $s_Day & ', ' & $s_Year
  532. EndFunc
  533.  
  534. Func _StringInArray($a_Array, $s_String)
  535.     Local $i_ArrayLen = UBound($a_Array) - 1
  536.  
  537.     For $i = 0 To $i_ArrayLen
  538.         If $a_Array[$i] = $s_String Then
  539.             Return $i
  540.         EndIf
  541.     Next
  542.     SetError(1)
  543.     Return 0
  544. EndFunc
  545.  
  546. Func _CompareVersions($s_Vers1, $s_Vers2, $i_ReturnFlag = 0)
  547.     Local $i, $i_Vers1, $i_Vers2, $i_Top
  548.     Local $a_Vers1 = StringSplit($s_Vers1, '.')
  549.     Local $a_Vers2 = StringSplit($s_Vers2, '.')
  550.  
  551.     $i_Top = $a_Vers1[0]
  552.     If $a_Vers1[0] < $a_Vers2[0] Then
  553.         $i_Top = $a_Vers2[0]
  554.     EndIf
  555.     
  556.     For $i = 1 To $i_Top
  557.         $i_Vers1 = 0
  558.         $i_Vers2 = 0
  559.         If $i <= $a_Vers1[0] Then
  560.             $i_Vers1 = Number($a_Vers1[$i])
  561.         EndIf
  562.         If $i <= $a_Vers2[0] Then
  563.             $i_Vers2 = Number($a_Vers2[$i])
  564.         EndIf
  565.         
  566.         If $i_Vers1 > $i_Vers2 Then
  567.             $v_Return = 1
  568.             ExitLoop
  569.         ElseIf $i_Vers1 < $i_Vers2 Then
  570.             $v_Return = 0
  571.             ExitLoop
  572.         Else
  573.             $v_Return = -1
  574.         EndIf
  575.     Next
  576.  
  577.     If $i_ReturnFlag Then
  578.         Select
  579.             Case $v_Return = -1
  580.                 SetError(1)
  581.                 Return 0
  582.             Case $v_Return = 1
  583.                 Return $s_Vers1
  584.             Case $v_Return = 0
  585.                 Return $s_Vers2
  586.         EndSelect
  587.     ElseIf $v_Return = -1 Then
  588.         SetError(1)
  589.         Return 0
  590.     Else
  591.         Return $v_Return
  592.     EndIf
  593. EndFunc
  594.  
  595. Func _Status($s_MainText, $s_SubText = '', $i_BytesRead = -1, $i_DownSize = -1)
  596.     Global $i_ProgOn
  597.     Global $i_StatusPercent
  598.     
  599.     If @OSVersion = "WIN_XP" Or @OSVersion = "WIN_2000" Or @OSVersion = "WIN_2003" Then
  600.         If $s_SubText <> '' Then 
  601.             $s_SubText = @LF & $s_SubText
  602.         EndIf
  603.         
  604.         If $i_BytesRead = -1 Then
  605.             TrayTip($s_Title, $s_MainText & $s_SubText, 10, 16)
  606.         Else
  607.             $s_DownStatus = Round($i_BytesRead / 1024) & ' of ' & Round($i_DownSize / 1024) & ' KB'
  608.             TrayTip($s_Title, $s_MainText & $s_SubText & @LF & $s_DownStatus, 10, 16)
  609.         EndIf
  610.     Else
  611.         If Not $i_ProgOn Then
  612.             ProgressOn($s_Title, $s_MainText, $s_SubText, -1, -1, 2+16)
  613.             $i_ProgOn = 1
  614.         Else
  615.             If $i_BytesRead = -1 Then
  616.                 ProgressSet($i_StatusPercent, $s_SubText, $s_MainText)
  617.             Else
  618.                 $s_DownStatus = 'Downloading ' & Round($i_BytesRead / 1024) & ' of ' & Round($i_DownSize / 1024) & ' KB'
  619.                 $i_StatusPercent = Round($i_BytesRead / $i_DownSize * 100)
  620.                 ProgressSet($i_StatusPercent, $s_DownStatus, $s_MainText)
  621.             EndIf
  622.         EndIf
  623.     EndIf
  624. EndFunc