Code: Select all
$url = "http://something.com/filename.exe"
$url2 = "http://something.com/filename.exe" ;second location if first fails
If InetGetSize($url) <> FileGetSize(@ScriptFullPath) and InetGetSize($url) > 10000 and $cmdline[0] = 0 Then  
   self_update($url) 
elseIf InetGetSize($url2) <> FileGetSize(@ScriptFullPath) and InetGetSize($url2) > 10000 and $cmdline[0] = 0 Then  
   self_update($url2) 
EndIf
Func self_update($update_url = "")
      		
		$upd_dlsize = InetGetSize($update_url)
		
		ProgressOn("Nadgradnja ", "Nadgradnja programa ", "")
		Sleep(500)
		
		$upd_get = InetGet($update_url, @ScriptFullPath & ".new", 1, 1)
		Do
			ProgressSet(Round(InetGetInfo($upd_get, 0) / ($upd_dlsize / 100), 0), Floor(InetGetInfo($upd_get, 0) / 1024) & "kB od " & Floor($upd_dlsize / 1024) & "kB prenešeno." & @CRLF & "Prosimo počakajte...")
			Sleep(200)
		Until InetGetInfo($upd_get, 2)
			ProgressSet(Round(InetGetInfo($upd_get, 0) / ($upd_dlsize / 100), 0), Floor(InetGetInfo($upd_get, 0) / 1024) & "kB od " & Floor($upd_dlsize / 1024) & "kB prenešeno." & @CRLF & "Končano!")
		Sleep(1000)
				
        Local $batchPath = @ScriptDir & '\update.bat'
        Local $batchFile =  "ping localhost -n 2 > nul" & @CRLF _ ;not sure what you're doing here. Giving the script time to exit?
                          & ":loop" & @CRLF _ ;specify the start of a zone
                          & 'del /Q "' & @ScriptFullPath & '"' & @CRLF _ ;the quotes are needed for long filepaths, and filepaths with spaces. The @SciptfullPath is for flexibility
                          & 'if exist "' & @ScriptFullPath & '" goto loop' & @CRLF _ ;if the delete failed, try again
                          & 'move "' & @ScriptFullPath & '.new" "' & @ScriptFullPath & '"' & @CRLF _ ;this is why I changed the new file's name.
                          & '"' & @ScriptFullPath & '"' & @CRLF _
						  & 'del /Q "' & $batchPath & '"' & @CRLF _
                          & "exit"
						  
        FileWrite($batchPath,$batchFile)
        Run($batchPath, "", @SW_HIDE) ;
        Exit
EndFunc
Code: Select all
#include "updateme.au3"

 
						
