Sign in to follow this  
Followers 0
Fran

GUI sleep without sleeping

15 posts in this topic

Hi there.

I have a script that downloads and installs something, but if the user forgets to click 'download' I want to automatically continue after 10 seconds.

I've got that part right, but my problem is, that in that time I want the user to still be able to interact with the GUI (ie. click the 'back', 'cancel', 'close' buttons), but I can only get the Do Until to work with one button.

I hope I'm explaining myself correctly.

I want the GUI to sleep without really sleeping.

Here is my code:

#include <Date.au3>
$tCur = _Date_Time_GetTickCount()
Do
    $tNew = _Date_Time_GetTickCount()
    If ($tNew - $tCur) = 10000 Then ExitLoop
Until GUIGetMsg() = $but1 ;Or $but3 Or $GUI_EVENT_CLOSE Or $but2

Share this post


Link to post
Share on other sites



Fran,

Try something along these lines:

$iBegin = TimerInit()

While TimerDiff($iBegin) < 10000
    
    Switch GUIGetMsg() 
        Case $GUI_EVENT_CLOSE
            ; Whatever you want to do here
        Case $but1 ; and so on for $but2 and $but3
            ; Whatever you want to do here
    EndSwitch
    
WEnd

; Start the download

You stay in the loop until the 10 secs are up and then exit the loop to start the download - during this time the buttons work as normal.

All clear? :graduated:

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites

mmm... the gui is a bit more complex than that.

If you wouldn't mind... Below is the full script to give you an idea.

#RequireAdmin
#Region ;**** Directives created by AutoIt3Wrapper_GUI ****
#AutoIt3Wrapper_icon=..\_resources\images\App_updater.ico
#AutoIt3Wrapper_outfile=RS_Updater.exe
#AutoIt3Wrapper_Res_Fileversion=1.0.0.3
#AutoIt3Wrapper_Res_Fileversion_AutoIncrement=p
#AutoIt3Wrapper_Res_requestedExecutionLevel=requireAdministrator
#EndRegion ;**** Directives created by AutoIt3Wrapper_GUI ****
#cs ----------------------------------------------------------------------------

    AutoIt Version: 3.3.6.1
    Author:         Francisca Carstens

    Script Function:
    Check if RapidStudio Windows Client installed version corresponds to newest upgrade available on www.rapidstudio.co.za

UPDATER
    Changes from version 1.0.0.1 to 1.0.0.2
    -   In previous version more than one updater could run at one time. Changed so that only one process may exist.
    added #include <Misc.au3> with user defined function _Singleton()
    -   Now including images using fileinstall() in the setup.exe
    -   Royalty text not displaying.  Now including with fileinstall() function.
    -   fran@bowens.co.za email address pre filled in, text changed to email address entered into the registry at setup time.

    Changes from version 1.0.0.2 to 1.0.0.3
    BUGS:
    -   Royalty text and images still not displaying.  $rgApp was declared incorrectly.
    FEATURE REQUESTS:
    -   After install launch updater GUI (not only in system tray) - get variable $fromsetup = 1
            Prompts with message boxes instead of just the TrayTips.
    -   Auto download after 10 seconds >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
    -   Add button on download screen 'Minimise to Tray' ('back' button) >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>


#ce ----------------------------------------------------------------------------

#Region -> Includes
#include <Constants.au3>
#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <EditConstants.au3>
#include <WindowsConstants.au3>
#include <GuiStatusBar.au3>
#include <ProgressConstants.au3>
#include <Timers.au3>
#include <GuiButton.au3>
#include <Misc.au3>
#include <Date.au3>
#EndRegion -> Includes
If _Singleton("RS_Updater", 1) = 0 Then Exit ;make sure only one copy of the script is running

#Region -> Options
Opt("TrayAutoPause", 0)
Opt("TrayIconHide", 0)
Opt("TrayOnEventMode", 1)
Opt("TrayMenuMode", 3)
#EndRegion -> Options
#Region -> Declarations
$min = 0
$fromsetup = 0
For $x = 1 to $CmdLine[0]
    $fromsetup = $CmdLine[1]
Next

$instProgram = 'RapidStudio Software Updater'
$instLicense = FileRead(@ScriptDir & "\resources\license.txt")
Local $appath, $verl, $verr, $App = 'RapidStudio', $numRP = 10
Local $vStatus ; Version Status... 1=up to date, 2=not newest, 3=version 5 (not upgradable)
Local $message
Local $goto = 2, $backto, $finish = 0, $downloadfinish = 0
Local $StatusBar, $hDownload, $nBytes, $nRead, $nSize, $calc, $file = @TempDir & '\RapidStudio_rsupdate', $url = 'http://update.rapidstudio.co.za'
Local $starttime, $speed
Local $prog = 0
Local $stop = 0
Global $silent = 1
_RegRead() ;does RapidStudio installation exist on user PC?
$program = $appath & "\MPR500 Pro 5\AlbumMaker.exe"
$verl = RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\RapidStudio_RapidStudio", "AppVersion")
$useremail = RegRead("HKEY_CURRENT_USER\Software\RapidStudio_Updater\", "Email")
$AppFolderUpdater = RegRead("HKEY_CURRENT_USER\Software\RapidStudio_Updater\", "AppFolder")
$rgApp = 'RS Updater'
$AppConfigFolder = $AppFolderUpdater & "\" & $rgApp & "\config"
;~ ShellExecuteWait (@scriptdir & "\test.exe",$silent) ; to execute upgrade in silent mode
#EndRegion -> Declarations
#Region -> Tray Items
TrayCreateItem("Exit")
TrayItemSetOnEvent(-1, "_On_Exit")
#EndRegion -> Tray Items

#Region -> GUI Items
$gui = GUICreate($instProgram, 500, 361, -1, -1, $GUI_SS_DEFAULT_GUI)
GUISetFont("", 400, "", "Tahoma", "", 5)

#Region -> Screen 1: Welcome Screen
$bkg1 = GUICtrlCreateGraphic(0, 0, 500, 314)
GUICtrlSetBkColor(-1, 0xFFFFFF)
$pic1 = GUICtrlCreatePic($AppConfigFolder & "\images\setup_leftpic1.jpg", 0, 0, 163, 314)
$tWelcomeHead = GUICtrlCreateLabel("Welcome to the " & $instProgram & " Wizard", 180, 18, 300, 50)
GUICtrlSetFont(-1, 13.2, 700, "", "Arial", 5)
GUICtrlSetBkColor(-1, 0xFFFFFF)
$tWelcomeBody = GUICtrlCreateLabel("This wizard will guide you through the download and installation of the newest RapidStudio software update available." & @LF & @LF & "It is recommended that you close all other applications before you continue. This will make it possible to update relevant system files without having to reboot your computer." & @LF & @LF & "Click Next to continue.", 180, 68, 300, 200)
GUICtrlSetBkColor(-1, 0xFFFFFF)
$but1 = GUICtrlCreateButton("&Next >", 326, 325, 74, 23, $BS_DEFPUSHBUTTON)
$but2 = GUICtrlCreateButton("&Cancel", 412, 325, 74, 23)
$divBottom1 = GUICtrlCreateGraphic(0, 314, 510, 1, $SS_ETCHEDHORZ)
$but3 = GUICtrlCreateButton("< &Back", 326 - 74 - 2, 325, 74, 23)
GUICtrlSetState(-1, $GUI_HIDE)
#EndRegion -> Screen 1: Welcome Screen
#Region -> Screen 2: Download
$bkg2 = GUICtrlCreateGraphic(0, 0, 500, 60)
GUICtrlSetBkColor(-1, 0xfeb916)
GUICtrlSetState(-1, $GUI_HIDE)
$logo = GUICtrlCreatePic($AppConfigFolder & '\images\logo_updater.jpg', 440, 0, 60, 60)
GUICtrlSetState(-1, $GUI_HIDE)
$divTop = GUICtrlCreateGraphic(0, 60, 500, 1, $SS_GRAYFRAME)
GUICtrlSetState(-1, $GUI_HIDE)
$tDownloadHead = GUICtrlCreateLabel("Download " & $App & " " & $verr & ".", 15, 10, 300, 20)
GUICtrlSetFont(-1, 8.5, 800, "", "Tahoma")
GUICtrlSetBkColor(-1, 0xfeb916)
GUICtrlSetState(-1, $GUI_HIDE)
$tDownloadHead2 = GUICtrlCreateLabel("", 25, 30, 410, 30)
GUICtrlSetBkColor(-1, 0xfeb916)
GUICtrlSetFont(-1, 8.5, 400, "", "Tahoma")
GUICtrlSetState(-1, $GUI_HIDE)
$tDownloadBody = GUICtrlCreateLabel("", 25, 75, 450, 20)
GUICtrlSetState(-1, $GUI_HIDE)
$divBottom2 = GUICtrlCreateGraphic(0, 314, 500, 1, $SS_ETCHEDHORZ)
GUICtrlSetState(-1, $GUI_HIDE)
$ProgressDownload = GUICtrlCreateProgress(25, 90, 450, 20, $PBS_SMOOTH)
GUICtrlSetState(-1, $GUI_HIDE)
#EndRegion -> Screen 2: Download
#Region -> Screen 3: Royalty Points
$tRoyaltyHead = GUICtrlCreateLabel("Royalty Points", 15, 10, 300, 20)
GUICtrlSetFont(-1, 8.5, 800, "", "Tahoma")
GUICtrlSetBkColor(-1, 0xfeb916)
GUICtrlSetState(-1, $GUI_HIDE)
$tRoyaltyHead2 = GUICtrlCreateLabel("Please confirm your email address to claim your Royalty Points.", 25, 30, 410, 30)
GUICtrlSetBkColor(-1, 0xfeb916)
GUICtrlSetFont(-1, 8.5, 400, "", "Tahoma")
GUICtrlSetState(-1, $GUI_HIDE)
$tRoyaltyBody1 = GUICtrlCreateLabel("Please enter your email address to continue.", 25, 75, 450, 20)
GUICtrlSetState(-1, $GUI_HIDE)
$input = GUICtrlCreateInput("Enter your email address here", 25, 90, 225, 20)
;~ $input = GUICtrlCreateInput("fran@bowens.co.za", 25, 90, 225, 20)
GUICtrlSetState(-1, $GUI_HIDE)
GUICtrlSetTip(-1, "Enter your email address (ex. joe.soap@email.com)")
FileInstall('..\_resources\royalty.txt',$AppConfigFolder & "\royalty.txt")
$tRoyaltyBody = GUICtrlCreateEdit(FileRead($AppConfigFolder & "\royalty.txt"), 25, 115, 450, 175, BitOR($ES_MULTILINE, $ES_READONLY, $WS_VSCROLL))
GUICtrlSetState(-1, $GUI_HIDE)
;~ GUICtrlSetFont(-1, 8.5, 400, "", "Lucida Console", 5)
GUICtrlSetBkColor(-1, 0xFFFFFF)
#EndRegion -> Screen 3: Royalty Points
#EndRegion -> GUI Items


#Region -> Pre GUI checks
Ping('www.google.com')
If @error Then Ping('www.google.com')
If @error Then
    MsgBox(0, '', 'You are not connected to the internet!') ;for testing
    $installdir = @ProgramFilesDir & "\RapidStudio_Updater"
    RunWait('schtasks /delete /TN "RapidStudio Updater" /F', '', @SW_HIDE)
    RunWait('schtasks /create /RU SYSTEM /SC daily /TN "RapidStudio Updater" /TR "' & $installdir & '\Updater.exe"', '', @SW_HIDE)
    Exit
EndIf
$oHTTP = ObjCreate("winhttp.winhttprequest.5.1")
$oHTTP.Open("GET", "http://www.rapidstudio.info/rsupdater/index.php?useremail=" & $useremail & "&update=1&version=" & $verl)
$oHTTP.Send()
$HTMLSource = $oHTTP.Responsetext
$aSource = StringSplit($HTMLSource, ",")
$verr = $aSource[2]
$releasedate = $aSource[3]
ConsoleWrite("Remote Version:" & @TAB & $verr & @CRLF & "Release Date:" & @TAB & $releasedate & @CRLF) ;for testing
_CheckVersion($verl, $verr)
If $vStatus = 1 Then
    If $fromsetup = 1 Then
    MsgBox(4160, "RapidStudio Updater", "RapidStudio is up to date.")
    Else
    TrayTip("RapidStudio Updater", "RapidStudio is up to date.", 5, 1)
    Sleep(5000)
    EndIf
    Exit
EndIf

If $vStatus = 3 Then
    TrayTip("RapidStudio Updater", "Your version is too old to upgrade." & @CRLF & "Please phone support on 011 225 0522", 5, 1)
    Sleep(5000)
    Exit
EndIf
#EndRegion -> Pre GUI checks

TraySetOnEvent($TRAY_EVENT_PRIMARYUP, "_On_Tray_Show")
TraySetClick(16)
TrayTip("RapidStudio Updater", "New update available for RapidStudio.", 5, 1)
TraySetToolTip("RapidStudio - Updater")
TraySetState(4)



;~  $msg = MsgBox(4 + 64 + 8192 + 262144, $instProgram, "There is a new version of RapidStudio available!" & @CRLF & @CRLF & "Would you like to upgrade now?")
;~  If $msg = 7 Then Exit

_Main()

Func _Main()

    GUISetState(@SW_HIDE)
    If $fromsetup = 1 Then
    If MsgBox(4096 + 52, "RapidStudio Updater", "New update available for RapidStudio." & @CRLF & @CRLF & "Update Now?") = 6 Then
    _On_Tray_Show()
    Else
    GUISetState(@SW_HIDE)
EndIf
EndIf
    While 1
        Switch GUIGetMsg()
            Case $GUI_EVENT_CLOSE, $but2
                If $finish = 0 Then
                    If $goto = 3 Then ;download is busy
                        _Exit()
                    Else
                        If MsgBox(52 + 4096, $instProgram, "Are you sure you want to quit " & $instProgram & "?") = 6 Then _Hide_GUI()
                        ;Hide gui, but keep showing tray icon, so if the user clicks on the tray icon, function _Main() will be called again... or something like that.
;~                      EndIf
                    EndIf
                Else
                    Exit
                EndIf

            Case $but1
                If $goto = 2 Then ;goto Stage 2: Prepare to Download Upgrade
                    GUICtrlSetState($bkg1, $GUI_HIDE)
                    GUICtrlSetState($pic1, $GUI_HIDE)
                    GUICtrlSetState($tWelcomeHead, $GUI_HIDE)
                    GUICtrlSetState($tWelcomeBody, $GUI_HIDE)
                    GUICtrlSetState($divBottom1, $GUI_HIDE)

                    GUICtrlSetData($tDownloadHead, "Download " & $App & " " & $verr & " Upgrade.")
                    GUICtrlSetData($tDownloadHead2, "Download the newest version of " & $App & ".")
                    GUICtrlSetData($tDownloadBody, "Click Download to start the download for " & $App & " " & $verr & " Upgrade.")
                    GUICtrlSetState($bkg2, $GUI_SHOW)
                    GUICtrlSetState($logo, $GUI_SHOW)
                    GUICtrlSetState($divTop, $GUI_SHOW)
                    GUICtrlSetState($divBottom2, $GUI_SHOW)
                    GUICtrlSetState($tDownloadBody, $GUI_SHOW)
                    GUICtrlSetState($tDownloadHead, $GUI_SHOW)
                    GUICtrlSetState($tDownloadHead2, $GUI_SHOW)
                    GUICtrlSetState($ProgressDownload, $GUI_SHOW)
                    GUICtrlSetData($but1, '&Download >')
                    GUICtrlSetState($but3, $GUI_SHOW)
                    $backto = 1
                    $goto = 2.5
$tCur = _Date_Time_GetTickCount()
                    Do
                    $tNew = _Date_Time_GetTickCount()
                    If ($tNew - $tCur) = 10000 Then ExitLoop
                Until GUIGetMsg() = $but1 ;Or $but3 Or $GUI_EVENT_CLOSE Or $but2 <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
                    $backto = 0
                    GUICtrlSetState($but1, $GUI_DISABLE)
                    GUICtrlSetState($but2, $GUI_DISABLE)
                    GUICtrlSetState($but3, $GUI_DISABLE)
                    Sleep(100)
                    GUICtrlSetState($but1, $GUI_HIDE)
                    GUICtrlSetState($but2, $GUI_HIDE)
                    GUICtrlSetState($but3, $GUI_HIDE)
                    GUICtrlSetState($divBottom2, $GUI_HIDE)
                    Sleep(100)
                    GUICtrlSetData($tDownloadBody, "Downloading...")
                    DirCreate($file)
                    $StatusBar = _GUICtrlStatusBar_Create($gui)
                    _GUICtrlStatusBar_SetText($StatusBar, "Ready")
                    Start_DL($url, $file)
                    $goto = 3

                ElseIf $goto = 2.5 Then ;goto Stage 2.5: Download Upgrade
                    $backto = 0
                    GUICtrlSetState($but1, $GUI_DISABLE)
                    GUICtrlSetState($but2, $GUI_DISABLE)
                    GUICtrlSetState($but3, $GUI_DISABLE)
                    Sleep(100)
                    GUICtrlSetState($but1, $GUI_HIDE)
                    GUICtrlSetState($but2, $GUI_HIDE)
                    GUICtrlSetState($but3, $GUI_HIDE)
                    GUICtrlSetState($divBottom2, $GUI_HIDE)
                    Sleep(100)
                    GUICtrlSetData($tDownloadBody, "Downloading...")
                    DirCreate($file)
                    $StatusBar = _GUICtrlStatusBar_Create($gui)
                    _GUICtrlStatusBar_SetText($StatusBar, "Ready")
                    Start_DL($url, $file)
                    $goto = 3

                ElseIf $goto = 3 Then ;goto Stage 3: Royalty Points
                    _GUICtrlStatusBar_Destroy($StatusBar)
                    GUICtrlSetState($ProgressDownload, $GUI_HIDE)
                    GUICtrlSetState($tDownloadBody, $GUI_HIDE)
                    GUICtrlSetState($divBottom2, $GUI_SHOW)
                    GUICtrlSetState($tRoyaltyBody, $GUI_SHOW)
                    GUICtrlSetState($tRoyaltyBody1, $GUI_SHOW)
                    GUICtrlSetState($tRoyaltyHead, $GUI_SHOW)
                    GUICtrlSetState($tRoyaltyHead2, $GUI_SHOW)
                    GUICtrlSetData($but1, '&Next >')
                    GUICtrlSetState($but1, $GUI_ENABLE)
                    GUICtrlSetState($but1, $GUI_SHOW)
                    GUICtrlSetState($but2, $GUI_SHOW)
                    GUICtrlSetState($but3, $GUI_SHOW)
                    GUICtrlSetState($but2, $GUI_ENABLE)
                    GUICtrlSetData($input, $useremail)
                    GUICtrlSetState($input, $GUI_SHOW)
                    GUICtrlSetState($input, $GUI_FOCUS)
                    $goto = 4


                ElseIf $goto = 4 Then ;goto Stage 4: Launch upgrade.exe
                    GUISetState(@SW_HIDE)
                    RunWait($file & "\" & "RapidStudio Upgrade.exe")

                    $verlNEW = RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\RapidStudio_RapidStudio", "AppVersion")

                    If $verl < $verlNEW Then
                        $oHTTP = ObjCreate("winhttp.winhttprequest.5.1")
                        $oHTTP.Open("GET", "http://www.rapidstudio.info/rsupdater/index.php?useremail=" & $useremail & "&update=1&upgraded=1&version=" & $verl)
                        $oHTTP.Send()
                        $HTMLSource = $oHTTP.Responsetext
                        $aSource = StringSplit($HTMLSource, ",")
                        $verr = $aSource[2]
                        $releasedate = $aSource[3]
                        ConsoleWrite("Remote Version:" & @TAB & $verr & @CRLF & "Release Date:" & @TAB & $releasedate & @CRLF) ;for testing
                        MsgBox(0, '', 'You have been awarded ' & $numRP & ' Royalty Points for upgrading RapidStudio to version ' & $verl)
                        $finish = 1
                    ElseIf $verl = $verlNEW Then
                        $oHTTP = ObjCreate("winhttp.winhttprequest.5.1")
                        $oHTTP.Open("GET", "http://www.rapidstudio.info/rsupdater/index.php?useremail=" & $useremail & "&update=1&upgraded=0&version=" & $verl)
                        $oHTTP.Send()
                        $HTMLSource = $oHTTP.Responsetext
                        $aSource = StringSplit($HTMLSource, ",")
                        $verr = $aSource[2]
                        $releasedate = $aSource[3]
                        ConsoleWrite("Remote Version:" & @TAB & $verr & @CRLF & "Release Date:" & @TAB & $releasedate & @CRLF) ;for testing
                        MsgBox(0, '', 'You have been awarded ' & 0 & ' Royalty Points for upgrading RapidStudio to version ' & $verl)
                        $finish = 2 ;upgrade not successful

                    EndIf
                    ExitLoop

                EndIf

            Case $but3
                If $backto = 1 Then ;go backto Screen 1: Welcome
                    GUICtrlSetState($bkg2, $GUI_HIDE)
                    GUICtrlSetState($divTop, $GUI_HIDE)
                    GUICtrlSetState($logo, $GUI_HIDE)
                    GUICtrlSetState($divBottom2, $GUI_HIDE)
                    GUICtrlSetState($tDownloadBody, $GUI_HIDE)
                    GUICtrlSetState($tDownloadHead, $GUI_HIDE)
                    GUICtrlSetState($tDownloadHead2, $GUI_HIDE)
                    GUICtrlSetState($ProgressDownload, $GUI_HIDE)
                    GUICtrlSetData($but1, '&Next >')
                    GUICtrlSetState($but3, $GUI_HIDE)


                    GUICtrlSetState($bkg1, $GUI_SHOW)
                    GUICtrlSetState($pic1, $GUI_SHOW)
                    GUICtrlSetState($tWelcomeHead, $GUI_SHOW)
                    GUICtrlSetState($tWelcomeBody, $GUI_SHOW)
                    GUICtrlSetState($divBottom1, $GUI_SHOW)
                    $goto = 2

                EndIf

            Case $GUI_EVENT_MINIMIZE
                GUISetState(@SW_HIDE)
                $min = 1

        EndSwitch
    WEnd
    RunWait('schtasks /delete /TN "RapidStudio Updater" /F', '', @SW_HIDE)
    RunWait('schtasks /create /RU SYSTEM /SC weekly /TN "RapidStudio Updater" /TR "' & $AppFolderUpdater & '\Updater.exe"', '', @SW_HIDE)

    Exit
EndFunc   ;==>_Main

#Region -> Functions
Func _On_Tray_Show()
    ; Left clicking the tray icon shows the GUI
    GUISetState(@SW_SHOW)
    TraySetState(8)
EndFunc   ;==>_On_Tray_Show

Func _On_Exit()
    ; Exit the script
    Exit
EndFunc   ;==>_On_Exit
Func _Hide_GUI()
    GUICtrlSetState($bkg2, $GUI_HIDE)
    GUICtrlSetState($divTop, $GUI_HIDE)
    GUICtrlSetState($divBottom2, $GUI_HIDE)
    GUICtrlSetState($tDownloadBody, $GUI_HIDE)
    GUICtrlSetState($tDownloadHead, $GUI_HIDE)
    GUICtrlSetState($tDownloadHead2, $GUI_HIDE)
    GUICtrlSetState($ProgressDownload, $GUI_HIDE)
    GUICtrlSetData($but1, '&Next >')
    GUICtrlSetState($but3, $GUI_HIDE)
    GUICtrlSetState($tRoyaltyBody, $GUI_HIDE)
    GUICtrlSetState($tRoyaltyBody1, $GUI_HIDE)
    GUICtrlSetState($tRoyaltyHead, $GUI_HIDE)
    GUICtrlSetState($tRoyaltyHead2, $GUI_HIDE)
    GUICtrlSetState($input, $GUI_HIDE)
    _GUICtrlStatusBar_Destroy($StatusBar)

    GUICtrlSetState($bkg1, $GUI_SHOW)
    GUICtrlSetState($pic1, $GUI_SHOW)
    GUICtrlSetState($tWelcomeHead, $GUI_SHOW)
    GUICtrlSetState($tWelcomeBody, $GUI_SHOW)
    GUICtrlSetState($divBottom1, $GUI_SHOW)
    GUICtrlSetState($but1, $GUI_SHOW)
    GUICtrlSetState($but1, $GUI_ENABLE)
    GUICtrlSetState($but1, $GUI_FOCUS)
    GUICtrlSetState($but2, $GUI_SHOW)
    GUICtrlSetState($but2, $GUI_ENABLE)
    $goto = 2

    GUISetState(@SW_HIDE)
    TrayTip("RapidStudio Updater", "New update available for RapidStudio.", 5, 1)
EndFunc   ;==>_Hide_GUI
Func _RegRead()
    RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\RapidStudio_RapidStudio", "")
    If @error > 0 Then
        ;Key does not exist
        MsgBox(16, "RapidStudio Updater Message", "RapidStudio is not installed on this computer." & @CRLF & "Please call support on 011 225 0522 if you require assistance.", 5000)
        RunWait('schtasks /delete /TN "RapidStudio Updater" /F', '', @SW_HIDE)
        Exit
    Else
        ;Key does exist
        $appath = RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\RapidStudio_RapidStudio", "AppFolder")
;~      MsgBox(4096, "Success", "RapidStudio is installed in the following directory:" & @CRLF & $appath) ; for testing
    EndIf
EndFunc   ;==>_RegRead

Func _CheckVersion($verl, $verr)
    $averl = StringSplit($verl, ".")
    $averr = StringSplit($verr, ".")
    If $verl = $verr Then
        $vStatus = 1
;~      MsgBox(262144, "Message", "Your " & $App & " installation is up to date." & @LF & "Version: " & $verl)

    ElseIf ($averl[1] < $averr[1]) Then
        $vStatus = 3
;~      If MsgBox(52 + 262144, "Message", "There is a newer version of RapidStudio available, but the upgrade is not compatible with the version you are currently running. " & @LF & @LF & "Your version:" & @TAB & $verl & @LF & "New version:" & @TAB & $verr & @LF & @LF & "Would you like to download the fresh install of version " & $verr & " ?") = 6 Then
;~          MsgBox(0, "result", "Download full installation.")
;~      EndIf
    ElseIf ($verl < $verr) Then
        $vStatus = 2
;~      If MsgBox(68+ 262144, "Message", "Your " & $App & " installation is not up to date." & @LF & "Version: " & $verl & @CRLF & @CRLF &"Download the newer version? " & $verr) = 6 Then
;~      MsgBox(0, "result", "Download upgrade.")
;~      $upgraded = 1
;~      EndIf
    EndIf

EndFunc   ;==>_CheckVersion


Func Start_DL($url, $file)
    If $url <> "" And $file <> "" Then
        $file &= "\" & "RapidStudio Upgrade.exe"
        $nSize = InetGetSize($url)
        $hDownload = InetGet($url, $file, 1, 1)
        AdlibRegister("DL_Check", 50)
        $starttime = TimerInit()
    EndIf
EndFunc   ;==>Start_DL

Func DL_Check()
    If InetGetInfo($hDownload, 2) Then
        InetClose($hDownload)
        $nRead = $nSize
        $calc = Int(100 * $nRead / $nSize)
        GUICtrlSetData($ProgressDownload, $calc)
        _GUICtrlStatusBar_SetText($StatusBar, Round($nSize / 1024 / 1024, 2) & " MB" & @TAB & "100 %" & @TAB & $speed & " KBs / second")
        Sleep(2000)
        _GUICtrlStatusBar_Destroy($StatusBar)
        $goto = 3
        _GUICtrlButton_Click($but1)

    ElseIf $stop Then
        InetClose($hDownload)
;~      GUICtrlSetState($Start_DL, $GUI_ENABLE)
;~      GUICtrlSetState($Stop_DL, $GUI_DISABLE)
        GUICtrlSetData($ProgressDownload, 0)
        _GUICtrlStatusBar_SetText($StatusBar, "Ready")
        FileDelete($file)
        $stop = 0
        AdlibUnRegister("DL_Check")
    Else
        $nRead = InetGetInfo($hDownload, 0)
        $calc = Int(100 * $nRead / $nSize)
        GUICtrlSetData($ProgressDownload, $calc)
        $speed = Round(($nRead / 1024) / (_Timer_Diff($starttime) / 1000))
        _GUICtrlStatusBar_SetText($StatusBar, Round($nRead / 1024 / 1024, 2) & " / " & Round($nSize / 1024 / 1024, 2) & " MB" & @TAB & $calc & " %" & @TAB & $speed & " KBs / second")

    EndIf
EndFunc   ;==>DL_Check

Func Stop_DL()
    If MsgBox(8196, "Cancel", "Are you sure you want to cancel the download?") = 6 Then $stop = 1
EndFunc   ;==>Stop_DL

Func _Exit()
    If $nRead < $nSize Then
        If MsgBox(8196, "Exit", "The download is not complete. Are you sure you want to exit?") = 6 Then
            InetClose($hDownload)
            FileDelete($file)
            _Hide_GUI()
        EndIf
    Else
        _Hide_GUI()
    EndIf
EndFunc   ;==>_Exit

#EndRegion -> Functions

Share this post


Link to post
Share on other sites

Replace the lines (252+) with this code

...
$backto = 1
$goto = 2.5
$tCur = TimerInit()
Do
    If TimerDiff($tCur) > 10000 Then ExitLoop
Until GUIGetMsg() = $but1 ;Or $but3 Or $GUI_EVENT_CLOSE Or $but2 <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
$backto = 0
...

and it should work! :graduated:

Br,

UEZ


Please don't send me any personal message and ask for support! I will not reply!

Selection of finest graphical examples at Codepen.io

The own fart smells best!
Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!
¯\_(ツ)_/¯

Share this post


Link to post
Share on other sites

@UEZ: mmmm... it doesn't work

@Melba: I just don't think I can have my Timer around the Switch() otherwise it's pointless, because it could take the user more than 10 seconds to get to that point.

I don't understand why I can't have a line like this:

Do
;whatever
Until $i = 4 Or $i = 5 Or $i = 6    ;<<<<<<<<<<<<<<

Share this post


Link to post
Share on other sites

Here your full code that is working for me (I deactivated some lines to get it run)!

#RequireAdmin
#Region ;**** Directives created by AutoIt3Wrapper_GUI ****
#AutoIt3Wrapper_icon=..\_resources\images\App_updater.ico
#AutoIt3Wrapper_outfile=RS_Updater.exe
#AutoIt3Wrapper_Res_Fileversion=1.0.0.3
#AutoIt3Wrapper_Res_Fileversion_AutoIncrement=p
#AutoIt3Wrapper_Res_requestedExecutionLevel=requireAdministrator
#EndRegion ;**** Directives created by AutoIt3Wrapper_GUI ****
#cs ----------------------------------------------------------------------------

    AutoIt Version: 3.3.6.1
    Author:         Francisca Carstens

    Script Function:
    Check if RapidStudio Windows Client installed version corresponds to newest upgrade available on www.rapidstudio.co.za

UPDATER
    Changes from version 1.0.0.1 to 1.0.0.2
    -   In previous version more than one updater could run at one time. Changed so that only one process may exist.
    added #include <Misc.au3> with user defined function _Singleton()
    -   Now including images using fileinstall() in the setup.exe
    -   Royalty text not displaying.  Now including with fileinstall() function.
    -   fran@bowens.co.za email address pre filled in, text changed to email address entered into the registry at setup time.

    Changes from version 1.0.0.2 to 1.0.0.3
    BUGS:
    -   Royalty text and images still not displaying.  $rgApp was declared incorrectly.
    FEATURE REQUESTS:
    -   After install launch updater GUI (not only in system tray) - get variable $fromsetup = 1
            Prompts with message boxes instead of just the TrayTips.
    -   Auto download after 10 seconds >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
    -   Add button on download screen 'Minimise to Tray' ('back' button) >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>


#ce ----------------------------------------------------------------------------

#Region -> Includes
#include <Constants.au3>
#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <EditConstants.au3>
#include <WindowsConstants.au3>
#include <GuiStatusBar.au3>
#include <ProgressConstants.au3>
#include <Timers.au3>
#include <GuiButton.au3>
#include <Misc.au3>
#include <Date.au3>
#EndRegion -> Includes
If _Singleton("RS_Updater", 1) = 0 Then Exit ;make sure only one copy of the script is running

#Region -> Options
Opt("TrayAutoPause", 0)
Opt("TrayIconHide", 0)
Opt("TrayOnEventMode", 1)
Opt("TrayMenuMode", 3)
#EndRegion -> Options
#Region -> Declarations
$min = 0
$fromsetup = 0
For $x = 1 to $CmdLine[0]
    $fromsetup = $CmdLine[1]
Next

$instProgram = 'RapidStudio Software Updater'
$instLicense = FileRead(@ScriptDir & "\resources\license.txt")
Local $appath, $verl, $verr, $App = 'RapidStudio', $numRP = 10
Local $vStatus ; Version Status... 1=up to date, 2=not newest, 3=version 5 (not upgradable)
Local $message
Local $goto = 2, $backto, $finish = 0, $downloadfinish = 0
Local $StatusBar, $hDownload, $nBytes, $nRead, $nSize, $calc, $file = @TempDir & '\RapidStudio_rsupdate', $url = 'http://update.rapidstudio.co.za'
Local $starttime, $speed
Local $prog = 0
Local $stop = 0
Global $silent = 1
;~ _RegRead() ;does RapidStudio installation exist on user PC?
$program = $appath & "\MPR500 Pro 5\AlbumMaker.exe"
$verl = RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\RapidStudio_RapidStudio", "AppVersion")
$useremail = RegRead("HKEY_CURRENT_USER\Software\RapidStudio_Updater\", "Email")
$AppFolderUpdater = RegRead("HKEY_CURRENT_USER\Software\RapidStudio_Updater\", "AppFolder")
$rgApp = 'RS Updater'
$AppConfigFolder = $AppFolderUpdater & "\" & $rgApp & "\config"
;~ ShellExecuteWait (@scriptdir & "\test.exe",$silent) ; to execute upgrade in silent mode
#EndRegion -> Declarations
#Region -> Tray Items
TrayCreateItem("Exit")
TrayItemSetOnEvent(-1, "_On_Exit")
#EndRegion -> Tray Items

#Region -> GUI Items
$gui = GUICreate($instProgram, 500, 361, -1, -1, $GUI_SS_DEFAULT_GUI)
GUISetFont("", 400, "", "Tahoma", "", 5)

#Region -> Screen 1: Welcome Screen
$bkg1 = GUICtrlCreateGraphic(0, 0, 500, 314)
GUICtrlSetBkColor(-1, 0xFFFFFF)
$pic1 = GUICtrlCreatePic($AppConfigFolder & "\images\setup_leftpic1.jpg", 0, 0, 163, 314)
$tWelcomeHead = GUICtrlCreateLabel("Welcome to the " & $instProgram & " Wizard", 180, 18, 300, 50)
GUICtrlSetFont(-1, 13.2, 700, "", "Arial", 5)
GUICtrlSetBkColor(-1, 0xFFFFFF)
$tWelcomeBody = GUICtrlCreateLabel("This wizard will guide you through the download and installation of the newest RapidStudio software update available." & @LF & @LF & "It is recommended that you close all other applications before you continue. This will make it possible to update relevant system files without having to reboot your computer." & @LF & @LF & "Click Next to continue.", 180, 68, 300, 200)
GUICtrlSetBkColor(-1, 0xFFFFFF)
$but1 = GUICtrlCreateButton("&Next >", 326, 325, 74, 23, $BS_DEFPUSHBUTTON)
$but2 = GUICtrlCreateButton("&Cancel", 412, 325, 74, 23)
$divBottom1 = GUICtrlCreateGraphic(0, 314, 510, 1, $SS_ETCHEDHORZ)
$but3 = GUICtrlCreateButton("< &Back", 326 - 74 - 2, 325, 74, 23)
GUICtrlSetState(-1, $GUI_HIDE)
#EndRegion -> Screen 1: Welcome Screen
#Region -> Screen 2: Download
$bkg2 = GUICtrlCreateGraphic(0, 0, 500, 60)
GUICtrlSetBkColor(-1, 0xfeb916)
GUICtrlSetState(-1, $GUI_HIDE)
$logo = GUICtrlCreatePic($AppConfigFolder & '\images\logo_updater.jpg', 440, 0, 60, 60)
GUICtrlSetState(-1, $GUI_HIDE)
$divTop = GUICtrlCreateGraphic(0, 60, 500, 1, $SS_GRAYFRAME)
GUICtrlSetState(-1, $GUI_HIDE)
$tDownloadHead = GUICtrlCreateLabel("Download " & $App & " " & $verr & ".", 15, 10, 300, 20)
GUICtrlSetFont(-1, 8.5, 800, "", "Tahoma")
GUICtrlSetBkColor(-1, 0xfeb916)
GUICtrlSetState(-1, $GUI_HIDE)
$tDownloadHead2 = GUICtrlCreateLabel("", 25, 30, 410, 30)
GUICtrlSetBkColor(-1, 0xfeb916)
GUICtrlSetFont(-1, 8.5, 400, "", "Tahoma")
GUICtrlSetState(-1, $GUI_HIDE)
$tDownloadBody = GUICtrlCreateLabel("", 25, 75, 450, 20)
GUICtrlSetState(-1, $GUI_HIDE)
$divBottom2 = GUICtrlCreateGraphic(0, 314, 500, 1, $SS_ETCHEDHORZ)
GUICtrlSetState(-1, $GUI_HIDE)
$ProgressDownload = GUICtrlCreateProgress(25, 90, 450, 20, $PBS_SMOOTH)
GUICtrlSetState(-1, $GUI_HIDE)
#EndRegion -> Screen 2: Download
#Region -> Screen 3: Royalty Points
$tRoyaltyHead = GUICtrlCreateLabel("Royalty Points", 15, 10, 300, 20)
GUICtrlSetFont(-1, 8.5, 800, "", "Tahoma")
GUICtrlSetBkColor(-1, 0xfeb916)
GUICtrlSetState(-1, $GUI_HIDE)
$tRoyaltyHead2 = GUICtrlCreateLabel("Please confirm your email address to claim your Royalty Points.", 25, 30, 410, 30)
GUICtrlSetBkColor(-1, 0xfeb916)
GUICtrlSetFont(-1, 8.5, 400, "", "Tahoma")
GUICtrlSetState(-1, $GUI_HIDE)
$tRoyaltyBody1 = GUICtrlCreateLabel("Please enter your email address to continue.", 25, 75, 450, 20)
GUICtrlSetState(-1, $GUI_HIDE)
$input = GUICtrlCreateInput("Enter your email address here", 25, 90, 225, 20)
;~ $input = GUICtrlCreateInput("fran@bowens.co.za", 25, 90, 225, 20)
GUICtrlSetState(-1, $GUI_HIDE)
GUICtrlSetTip(-1, "Enter your email address (ex. joe.soap@email.com)")
FileInstall('..\_resources\royalty.txt',$AppConfigFolder & "\royalty.txt")
$tRoyaltyBody = GUICtrlCreateEdit(FileRead($AppConfigFolder & "\royalty.txt"), 25, 115, 450, 175, BitOR($ES_MULTILINE, $ES_READONLY, $WS_VSCROLL))
GUICtrlSetState(-1, $GUI_HIDE)
;~ GUICtrlSetFont(-1, 8.5, 400, "", "Lucida Console", 5)
GUICtrlSetBkColor(-1, 0xFFFFFF)
#EndRegion -> Screen 3: Royalty Points
#EndRegion -> GUI Items

#cs
#Region -> Pre GUI checks
Ping('www.google.com')
If @error Then Ping('www.google.com')
If @error Then
    MsgBox(0, '', 'You are not connected to the internet!') ;for testing
    $installdir = @ProgramFilesDir & "\RapidStudio_Updater"
    RunWait('schtasks /delete /TN "RapidStudio Updater" /F', '', @SW_HIDE)
    RunWait('schtasks /create /RU SYSTEM /SC daily /TN "RapidStudio Updater" /TR "' & $installdir & '\Updater.exe"', '', @SW_HIDE)
    Exit
EndIf
$oHTTP = ObjCreate("winhttp.winhttprequest.5.1")
$oHTTP.Open("GET", "http://www.rapidstudio.info/rsupdater/index.php?useremail=" & $useremail & "&update=1&version=" & $verl)
$oHTTP.Send()
$HTMLSource = $oHTTP.Responsetext
$aSource = StringSplit($HTMLSource, ",")
$verr = $aSource[2]
$releasedate = $aSource[3]
ConsoleWrite("Remote Version:" & @TAB & $verr & @CRLF & "Release Date:" & @TAB & $releasedate & @CRLF) ;for testing
_CheckVersion($verl, $verr)
If $vStatus = 1 Then
    If $fromsetup = 1 Then
    MsgBox(4160, "RapidStudio Updater", "RapidStudio is up to date.")
    Else
    TrayTip("RapidStudio Updater", "RapidStudio is up to date.", 5, 1)
    Sleep(5000)
    EndIf
    Exit
EndIf

If $vStatus = 3 Then
    TrayTip("RapidStudio Updater", "Your version is too old to upgrade." & @CRLF & "Please phone support on 011 225 0522", 5, 1)
    Sleep(5000)
    Exit
EndIf
#EndRegion -> Pre GUI checks
#ce
TraySetOnEvent($TRAY_EVENT_PRIMARYUP, "_On_Tray_Show")
TraySetClick(16)
TrayTip("RapidStudio Updater", "New update available for RapidStudio.", 5, 1)
TraySetToolTip("RapidStudio - Updater")
TraySetState(4)



;~  $msg = MsgBox(4 + 64 + 8192 + 262144, $instProgram, "There is a new version of RapidStudio available!" & @CRLF & @CRLF & "Would you like to upgrade now?")
;~  If $msg = 7 Then Exit

_Main()

Func _Main()

    GUISetState(@SW_HIDE)
    If $fromsetup = 1 Then
    If MsgBox(4096 + 52, "RapidStudio Updater", "New update available for RapidStudio." & @CRLF & @CRLF & "Update Now?") = 6 Then
    _On_Tray_Show()
    Else
    GUISetState(@SW_HIDE)
EndIf
EndIf
    While 1
        Switch GUIGetMsg()
            Case $GUI_EVENT_CLOSE, $but2
                If $finish = 0 Then
                    If $goto = 3 Then ;download is busy
                        _Exit()
                    Else
                        If MsgBox(52 + 4096, $instProgram, "Are you sure you want to quit " & $instProgram & "?") = 6 Then _Hide_GUI()
                        ;Hide gui, but keep showing tray icon, so if the user clicks on the tray icon, function _Main() will be called again... or something like that.
;~                      EndIf
                    EndIf
                Else
                    Exit
                EndIf

            Case $but1
                If $goto = 2 Then ;goto Stage 2: Prepare to Download Upgrade
                    GUICtrlSetState($bkg1, $GUI_HIDE)
                    GUICtrlSetState($pic1, $GUI_HIDE)
                    GUICtrlSetState($tWelcomeHead, $GUI_HIDE)
                    GUICtrlSetState($tWelcomeBody, $GUI_HIDE)
                    GUICtrlSetState($divBottom1, $GUI_HIDE)

                    GUICtrlSetData($tDownloadHead, "Download " & $App & " " & $verr & " Upgrade.")
                    GUICtrlSetData($tDownloadHead2, "Download the newest version of " & $App & ".")
                    GUICtrlSetData($tDownloadBody, "Click Download to start the download for " & $App & " " & $verr & " Upgrade.")
                    GUICtrlSetState($bkg2, $GUI_SHOW)
                    GUICtrlSetState($logo, $GUI_SHOW)
                    GUICtrlSetState($divTop, $GUI_SHOW)
                    GUICtrlSetState($divBottom2, $GUI_SHOW)
                    GUICtrlSetState($tDownloadBody, $GUI_SHOW)
                    GUICtrlSetState($tDownloadHead, $GUI_SHOW)
                    GUICtrlSetState($tDownloadHead2, $GUI_SHOW)
                    GUICtrlSetState($ProgressDownload, $GUI_SHOW)
                    GUICtrlSetData($but1, '&Download >')
                    GUICtrlSetState($but3, $GUI_SHOW)
                    $backto = 1
                    $goto = 2.5
                    $tCur = TimerInit()
                    Do
                        If TimerDiff($tCur) > 10000 Then ExitLoop
                    Until GUIGetMsg() = $but1 ;Or $but3 Or $GUI_EVENT_CLOSE Or $but2 <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
                    $backto = 0
                    GUICtrlSetState($but1, $GUI_DISABLE)
                    GUICtrlSetState($but2, $GUI_DISABLE)
                    GUICtrlSetState($but3, $GUI_DISABLE)
                    Sleep(100)
                    GUICtrlSetState($but1, $GUI_HIDE)
                    GUICtrlSetState($but2, $GUI_HIDE)
                    GUICtrlSetState($but3, $GUI_HIDE)
                    GUICtrlSetState($divBottom2, $GUI_HIDE)
                    Sleep(100)
                    GUICtrlSetData($tDownloadBody, "Downloading...")
                    DirCreate($file)
                    $StatusBar = _GUICtrlStatusBar_Create($gui)
                    _GUICtrlStatusBar_SetText($StatusBar, "Ready")
                    Start_DL($url, $file)
                    $goto = 3

                ElseIf $goto = 2.5 Then ;goto Stage 2.5: Download Upgrade
                    $backto = 0
                    GUICtrlSetState($but1, $GUI_DISABLE)
                    GUICtrlSetState($but2, $GUI_DISABLE)
                    GUICtrlSetState($but3, $GUI_DISABLE)
                    Sleep(100)
                    GUICtrlSetState($but1, $GUI_HIDE)
                    GUICtrlSetState($but2, $GUI_HIDE)
                    GUICtrlSetState($but3, $GUI_HIDE)
                    GUICtrlSetState($divBottom2, $GUI_HIDE)
                    Sleep(100)
                    GUICtrlSetData($tDownloadBody, "Downloading...")
                    DirCreate($file)
                    $StatusBar = _GUICtrlStatusBar_Create($gui)
                    _GUICtrlStatusBar_SetText($StatusBar, "Ready")
                    Start_DL($url, $file)
                    $goto = 3

                ElseIf $goto = 3 Then ;goto Stage 3: Royalty Points
                    _GUICtrlStatusBar_Destroy($StatusBar)
                    GUICtrlSetState($ProgressDownload, $GUI_HIDE)
                    GUICtrlSetState($tDownloadBody, $GUI_HIDE)
                    GUICtrlSetState($divBottom2, $GUI_SHOW)
                    GUICtrlSetState($tRoyaltyBody, $GUI_SHOW)
                    GUICtrlSetState($tRoyaltyBody1, $GUI_SHOW)
                    GUICtrlSetState($tRoyaltyHead, $GUI_SHOW)
                    GUICtrlSetState($tRoyaltyHead2, $GUI_SHOW)
                    GUICtrlSetData($but1, '&Next >')
                    GUICtrlSetState($but1, $GUI_ENABLE)
                    GUICtrlSetState($but1, $GUI_SHOW)
                    GUICtrlSetState($but2, $GUI_SHOW)
                    GUICtrlSetState($but3, $GUI_SHOW)
                    GUICtrlSetState($but2, $GUI_ENABLE)
                    GUICtrlSetData($input, $useremail)
                    GUICtrlSetState($input, $GUI_SHOW)
                    GUICtrlSetState($input, $GUI_FOCUS)
                    $goto = 4


                ElseIf $goto = 4 Then ;goto Stage 4: Launch upgrade.exe
                    GUISetState(@SW_HIDE)
                    RunWait($file & "\" & "RapidStudio Upgrade.exe")

                    $verlNEW = RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\RapidStudio_RapidStudio", "AppVersion")

                    If $verl < $verlNEW Then
                        $oHTTP = ObjCreate("winhttp.winhttprequest.5.1")
                        $oHTTP.Open("GET", "http://www.rapidstudio.info/rsupdater/index.php?useremail=" & $useremail & "&update=1&upgraded=1&version=" & $verl)
                        $oHTTP.Send()
                        $HTMLSource = $oHTTP.Responsetext
                        $aSource = StringSplit($HTMLSource, ",")
                        $verr = $aSource[2]
                        $releasedate = $aSource[3]
                        ConsoleWrite("Remote Version:" & @TAB & $verr & @CRLF & "Release Date:" & @TAB & $releasedate & @CRLF) ;for testing
                        MsgBox(0, '', 'You have been awarded ' & $numRP & ' Royalty Points for upgrading RapidStudio to version ' & $verl)
                        $finish = 1
                    ElseIf $verl = $verlNEW Then
                        $oHTTP = ObjCreate("winhttp.winhttprequest.5.1")
                        $oHTTP.Open("GET", "http://www.rapidstudio.info/rsupdater/index.php?useremail=" & $useremail & "&update=1&upgraded=0&version=" & $verl)
                        $oHTTP.Send()
                        $HTMLSource = $oHTTP.Responsetext
                        $aSource = StringSplit($HTMLSource, ",")
                        $verr = $aSource[2]
                        $releasedate = $aSource[3]
                        ConsoleWrite("Remote Version:" & @TAB & $verr & @CRLF & "Release Date:" & @TAB & $releasedate & @CRLF) ;for testing
                        MsgBox(0, '', 'You have been awarded ' & 0 & ' Royalty Points for upgrading RapidStudio to version ' & $verl)
                        $finish = 2 ;upgrade not successful

                    EndIf
                    ExitLoop

                EndIf

            Case $but3
                If $backto = 1 Then ;go backto Screen 1: Welcome
                    GUICtrlSetState($bkg2, $GUI_HIDE)
                    GUICtrlSetState($divTop, $GUI_HIDE)
                    GUICtrlSetState($logo, $GUI_HIDE)
                    GUICtrlSetState($divBottom2, $GUI_HIDE)
                    GUICtrlSetState($tDownloadBody, $GUI_HIDE)
                    GUICtrlSetState($tDownloadHead, $GUI_HIDE)
                    GUICtrlSetState($tDownloadHead2, $GUI_HIDE)
                    GUICtrlSetState($ProgressDownload, $GUI_HIDE)
                    GUICtrlSetData($but1, '&Next >')
                    GUICtrlSetState($but3, $GUI_HIDE)


                    GUICtrlSetState($bkg1, $GUI_SHOW)
                    GUICtrlSetState($pic1, $GUI_SHOW)
                    GUICtrlSetState($tWelcomeHead, $GUI_SHOW)
                    GUICtrlSetState($tWelcomeBody, $GUI_SHOW)
                    GUICtrlSetState($divBottom1, $GUI_SHOW)
                    $goto = 2

                EndIf

            Case $GUI_EVENT_MINIMIZE
                GUISetState(@SW_HIDE)
                $min = 1

        EndSwitch
    WEnd
;~  RunWait('schtasks /delete /TN "RapidStudio Updater" /F', '', @SW_HIDE)
;~  RunWait('schtasks /create /RU SYSTEM /SC weekly /TN "RapidStudio Updater" /TR "' & $AppFolderUpdater & '\Updater.exe"', '', @SW_HIDE)

    Exit
EndFunc   ;==>_Main

#Region -> Functions
Func _On_Tray_Show()
    ; Left clicking the tray icon shows the GUI
    GUISetState(@SW_SHOW)
    TraySetState(8)
EndFunc   ;==>_On_Tray_Show

Func _On_Exit()
    ; Exit the script
    Exit
EndFunc   ;==>_On_Exit
Func _Hide_GUI()
    GUICtrlSetState($bkg2, $GUI_HIDE)
    GUICtrlSetState($divTop, $GUI_HIDE)
    GUICtrlSetState($divBottom2, $GUI_HIDE)
    GUICtrlSetState($tDownloadBody, $GUI_HIDE)
    GUICtrlSetState($tDownloadHead, $GUI_HIDE)
    GUICtrlSetState($tDownloadHead2, $GUI_HIDE)
    GUICtrlSetState($ProgressDownload, $GUI_HIDE)
    GUICtrlSetData($but1, '&Next >')
    GUICtrlSetState($but3, $GUI_HIDE)
    GUICtrlSetState($tRoyaltyBody, $GUI_HIDE)
    GUICtrlSetState($tRoyaltyBody1, $GUI_HIDE)
    GUICtrlSetState($tRoyaltyHead, $GUI_HIDE)
    GUICtrlSetState($tRoyaltyHead2, $GUI_HIDE)
    GUICtrlSetState($input, $GUI_HIDE)
    _GUICtrlStatusBar_Destroy($StatusBar)

    GUICtrlSetState($bkg1, $GUI_SHOW)
    GUICtrlSetState($pic1, $GUI_SHOW)
    GUICtrlSetState($tWelcomeHead, $GUI_SHOW)
    GUICtrlSetState($tWelcomeBody, $GUI_SHOW)
    GUICtrlSetState($divBottom1, $GUI_SHOW)
    GUICtrlSetState($but1, $GUI_SHOW)
    GUICtrlSetState($but1, $GUI_ENABLE)
    GUICtrlSetState($but1, $GUI_FOCUS)
    GUICtrlSetState($but2, $GUI_SHOW)
    GUICtrlSetState($but2, $GUI_ENABLE)
    $goto = 2

    GUISetState(@SW_HIDE)
    TrayTip("RapidStudio Updater", "New update available for RapidStudio.", 5, 1)
EndFunc   ;==>_Hide_GUI
Func _RegRead()
    RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\RapidStudio_RapidStudio", "")
    If @error > 0 Then
        ;Key does not exist
        MsgBox(16, "RapidStudio Updater Message", "RapidStudio is not installed on this computer." & @CRLF & "Please call support on 011 225 0522 if you require assistance.", 5000)
        RunWait('schtasks /delete /TN "RapidStudio Updater" /F', '', @SW_HIDE)
        Exit
    Else
        ;Key does exist
        $appath = RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\RapidStudio_RapidStudio", "AppFolder")
;~      MsgBox(4096, "Success", "RapidStudio is installed in the following directory:" & @CRLF & $appath) ; for testing
    EndIf
EndFunc   ;==>_RegRead

Func _CheckVersion($verl, $verr)
    $averl = StringSplit($verl, ".")
    $averr = StringSplit($verr, ".")
    If $verl = $verr Then
        $vStatus = 1
;~      MsgBox(262144, "Message", "Your " & $App & " installation is up to date." & @LF & "Version: " & $verl)

    ElseIf ($averl[1] < $averr[1]) Then
        $vStatus = 3
;~      If MsgBox(52 + 262144, "Message", "There is a newer version of RapidStudio available, but the upgrade is not compatible with the version you are currently running. " & @LF & @LF & "Your version:" & @TAB & $verl & @LF & "New version:" & @TAB & $verr & @LF & @LF & "Would you like to download the fresh install of version " & $verr & " ?") = 6 Then
;~          MsgBox(0, "result", "Download full installation.")
;~      EndIf
    ElseIf ($verl < $verr) Then
        $vStatus = 2
;~      If MsgBox(68+ 262144, "Message", "Your " & $App & " installation is not up to date." & @LF & "Version: " & $verl & @CRLF & @CRLF &"Download the newer version? " & $verr) = 6 Then
;~      MsgBox(0, "result", "Download upgrade.")
;~      $upgraded = 1
;~      EndIf
    EndIf

EndFunc   ;==>_CheckVersion


Func Start_DL($url, $file)
    If $url <> "" And $file <> "" Then
        $file &= "\" & "RapidStudio Upgrade.exe"
        ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : $file = ' & $file & @crlf & '>Error code: ' & @error & @crlf) ;### Debug Console
        $nSize = InetGetSize($url)
        $hDownload = InetGet($url, $file, 1, 1)
        AdlibRegister("DL_Check", 50)
        $starttime = TimerInit()
    EndIf
EndFunc   ;==>Start_DL

Func DL_Check()
    If InetGetInfo($hDownload, 2) Then
        InetClose($hDownload)
        $nRead = $nSize
        $calc = Int(100 * $nRead / $nSize)
        GUICtrlSetData($ProgressDownload, $calc)
        _GUICtrlStatusBar_SetText($StatusBar, Round($nSize / 1024 / 1024, 2) & " MB" & @TAB & "100 %" & @TAB & $speed & " KBs / second")
        Sleep(2000)
        _GUICtrlStatusBar_Destroy($StatusBar)
        $goto = 3
        _GUICtrlButton_Click($but1)

    ElseIf $stop Then
        InetClose($hDownload)
;~      GUICtrlSetState($Start_DL, $GUI_ENABLE)
;~      GUICtrlSetState($Stop_DL, $GUI_DISABLE)
        GUICtrlSetData($ProgressDownload, 0)
        _GUICtrlStatusBar_SetText($StatusBar, "Ready")
        FileDelete($file)
        $stop = 0
        AdlibUnRegister("DL_Check")
    Else
        $nRead = InetGetInfo($hDownload, 0)
        $calc = Int(100 * $nRead / $nSize)
        GUICtrlSetData($ProgressDownload, $calc)
        $speed = Round(($nRead / 1024) / (_Timer_Diff($starttime) / 1000))
        _GUICtrlStatusBar_SetText($StatusBar, Round($nRead / 1024 / 1024, 2) & " / " & Round($nSize / 1024 / 1024, 2) & " MB" & @TAB & $calc & " %" & @TAB & $speed & " KBs / second")

    EndIf
EndFunc   ;==>DL_Check

Func Stop_DL()
    If MsgBox(8196, "Cancel", "Are you sure you want to cancel the download?") = 6 Then $stop = 1
EndFunc   ;==>Stop_DL

Func _Exit()
    If $nRead < $nSize Then
        If MsgBox(8196, "Exit", "The download is not complete. Are you sure you want to exit?") = 6 Then
            InetClose($hDownload)
            FileDelete($file)
            _Hide_GUI()
        EndIf
    Else
        _Hide_GUI()
    EndIf
EndFunc   ;==>_Exit

#EndRegion -> Functions

Br,

UEZ

1 person likes this

Please don't send me any personal message and ask for support! I will not reply!

Selection of finest graphical examples at Codepen.io

The own fart smells best!
Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!
¯\_(ツ)_/¯

Share this post


Link to post
Share on other sites

Fran,

But that syntax works perfectly: :(

Do

    $i = Random(1, 100, 1)

Until $i = 40 Or $i = 50 Or $i = 60

MsgBox(0, "Test", "I am here and $i = " & $i)

Why do you think it does not? :graduated:

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites

#8 ·  Posted (edited)

Why do you think it does not? :graduated:

Because I this doesn't work:

$tCur = TimerInit()
$msg = GUIGetMsg()
Do
If TimerDiff($tCur) > 10000 Then ExitLoop
Until $msg = $but1 Or $msg = $but2 Or $msg = $but3 Or $msg = $GUI_EVENT_CLOSE

I must add... I've tried to get this to work this morning... and it works sort of (just a little random)

If I have $msg = GUIGetMsg() outside the loop, it doesn't work nicely.

If I put it inside the loop:

$but3 (back) doesn't work at all

and $but2 (cancel) works sometimes on the first go and other times I have to press it a few times (same with $GUI_EVENT_CLOSE - and $but1)

1. Should it matter whether it's inside or outside the loop?

2. Does it matter wheter it's before the If TimerDiff().. or after?

Edited by Fran

Share this post


Link to post
Share on other sites

ok... I've switched the argument around and it seems to work now.

Except that I have to press any button twice before it exits the loop.

But here's what I've got now:

$tCur = TimerInit()
                    Do
                        $msg = GUIGetMsg()
                        If $msg = $but1 Or $msg = $but2 Or $msg = $but3 Or $msg = $GUI_EVENT_CLOSE Then ExitLoop
Until TimerDiff($tCur) > 10000

Share this post


Link to post
Share on other sites

#10 ·  Posted (edited)

EUREKA!!!!!! :graduated:

$tCur = _Timer_Init()
                Do
                    $msg = GUIGetMsg()
                    If $msg = $but1 Or $msg = $but2 Or $msg = $but3 Or $msg = $GUI_EVENT_CLOSE Then ExitLoop
                Until _Timer_Diff($tCur) > 10000

                If _Timer_Diff($tCur) > 10000 Then
                    _GUICtrlButton_Click($but1)
                    _Timer_KillAllTimers($gui)
                    $auto = 1
                Else
                    If $msg = $but1 Then _GUICtrlButton_Click($but1)
                    If $msg = $but2 Then _GUICtrlButton_Click($but2)
                    If $msg = $but3 Then _GUICtrlButton_Click($but3)
                    If $msg = $GUI_EVENT_CLOSE Then _GUICtrlButton_Click($GUI_EVENT_CLOSE)
                    $auto = 0
                EndIf
                _Timer_KillAllTimers($gui)

works 100%

Thanx for all your help guys! I never would've got it if it wasn't for your input!

UEZ & M23... as always... you rock! :(

Edited by Fran

Share this post


Link to post
Share on other sites

You could also use adlib:

GUICreate("Title", 120, 30)
$cIdButton = GUICtrlCreateButton("Press me", 5, 5, 110, 20)
GUISetState()

While 1
    Switch GUIGetMsg()
        Case -3
            Exit
        Case $cIdButton
            AdlibRegister("_YeahYeah", 10000)
    EndSwitch
WEnd

Func _YeahYeah()
    AdlibUnRegister("_YeahYeah")
    MsgBox(0, "See text.", "Ten seconds have gone since you pressed the button!")
EndFunc

Share this post


Link to post
Share on other sites

#12 ·  Posted (edited)

EUREKA!!!!!!

That's a convoluted control loop.

Melba pointed you to the straight forward method...

What can't you accomplish with a variation of something like this?

#include <timers.au3>

GUICreate("", 160, 140)
$button_back = GUICtrlCreateButton("BACK", 50, 40, 60, 20)
$button_next = GUICtrlCreateButton("NEXT", 50, 80, 60, 20)
GUISetState()

$tCur = _Timer_Init()
While 1
    $msg = GUIGetMsg()
    Switch $msg
        Case $button_back
            MsgBox(0,"", "Performing button1 function", 1)
        Case $button_next
            MsgBox(0,"", "Performing button2 function", 1)
        Case -3 ; $GUI_EVENT_CLOSE
            ExitLoop
    EndSwitch
    If _Timer_Diff($tCur) > 5000 Then
        MsgBox(0,"", "Performing timer function", 1)
        $tCur = _Timer_Init() ; reset timer
    EndIf
WEnd

Edit: a souped-up example

#include <StaticConstants.au3>
#include <timers.au3>
Global $state,$old_state, $timer

GUICreate("", 160, 140)
$label = GUICtrlCreateLabel("WELCOME!", 20, 40, 120, 20, $SS_CENTER)
$button_back = GUICtrlCreateButton("BACK", 15, 100, 60, 20)
$button_next = GUICtrlCreateButton("NEXT", 85, 100, 60, 20)
GUISetState()

While 1
    $msg = GUIGetMsg()
    Switch $msg
        Case $button_back
            $state = $state - 1 * ($state > 0)
        Case $button_next
            $state += 1
        Case -3 ; $GUI_EVENT_CLOSE
            ExitLoop
    EndSwitch
    If $state <> $old_state Then
        ToolTip($state) ; for testing
        $old_state = $state
        Process()
    EndIf
    If $state = 2 And _Timer_Diff($timer) > 2500 Then $state += 1
WEnd
Exit

Func Process()
    Switch $state
        Case 0
            GUICtrlSetData($label, "WELCOME!")
        Case 1
            GUICtrlSetData($label, "AGREE?")
        Case 2
            GUICtrlSetData($label, "DOWNLOAD?")
            $timer = _Timer_Init()
        Case 3
            Beep(800, 50)
            GUICtrlSetData($label, "DOWNLOADING...")
            Sleep(2500)
            Beep(800, 50)
            $state += 1
        Case 4
            GUICtrlSetData($label, "FINISHED!")
        Case 5
            Exit
    EndSwitch
Endfunc
Edited by Spiff59

Share this post


Link to post
Share on other sites

#13 ·  Posted (edited)

That's a convoluted control loop.

Melba pointed you to the straight forward method...

What can't you accomplish with a variation of something like this?

#include <timers.au3>

I can't start the timer the moment the GUI starts up because there is a welcome screen, and then a licence agreement screen and then some other screen... So, by the time they get to the Download screen, having the timer is a bit useless.

The timer can only start when the button to get to the Download screen is pushed.

And when at that screen, the user can still go back (and then the timer needs to clear). So, having the timer outside the Switch Loop is not really an option.

I will have a look at your "souped up version" - I didn't think about handling my GUI that way. Seems a bit cleaner than the way I'm doing it at the moment.

Thank you!

F

Edited by Fran

Share this post


Link to post
Share on other sites

#14 ·  Posted (edited)

Have you asked yourself why AutoIt uses NSIS to install? Probably because NSIS is designed for the task at hand. That's not to say it can't be done with AutoIt but there are a couple of GOOD (and free) install compilers already out there that are better suited to the task. Look at Inno Setup and NSIS.

Edited by GEOSoft

George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

Share this post


Link to post
Share on other sites

Have you asked yourself why AutoIt uses NSIS to install? Probably because NSIS is designed for the task at hand. That's not to say it can't be done with AutoIt but there are a couple of GOOD (and free) install compilers already out there that are better suited to the task. Look at Inno Setup and NSIS.

Thanx, I'll have a look.

F

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0