Jump to content

Problem with Progress


RiZon
 Share

Recommended Posts

#include <GUIConstants.au3>

GUICreate("AutoIt Downloader", 395, 170)

$ConfirmID = GUICtrlCreateRadio("Confirm",20,110,90)
$DoNotOverWriteID = GUICtrlCreateRadio("Don't overwrite",116,110,130)
$OverWrite = GUICtrlCreateRadio("Overwrite",260,110,100)
$Label = GUICtrlCreateLabel("Made by RiZon", 10, 145)
$StartID   = GUICtrlCreateButton("Start", 225, 140, 70, 23)
$CloseID = GUICtrlCreateButton("Close", 313, 140, 70, 23)
$ProgressID = GUICtrlCreateProgress("10",75,370,20)
$ChooseDirectory = GUICtrlCreateInput("C:\SciTE4AutoIt3.exe",10,40,290,20)
$FileBrowse = GUICtrlCreateButton("Browse...",310,40,70,20)
$File="http://www.autoitscript.com/cgi-bin/getfile.pl?../autoit3/scite/download/SciTE4AutoIt3.exe"
;GUISetOnEvent($CloseID,"_StopDownloading")
HotKeySet("{Esc}","_StopDownloading")
GUICtrlSetState ($ConfirmID, $GUI_CHECKED)
GUISetState()  ; display the GUI
$Path_to = GUICtrlRead($ChooseDirectory)

$MyDocsFolder = "::{450D8FBA-AD25-11D0-98A8-0800361B1103}"



While 1
    $case = GUIGetMsg()
   
    Select
        Case $case= $FileBrowse
        $Input_to_tmp = FileSaveDialog( "Save As",$MyDocsFolder , "All files (*.*)", 16,"SciTE4AutoIt3.exe")
; option 2 = dialog remains until valid path/file selected
If @error Then ContinueLoop
            GUICtrlSetData($ChooseDirectory, $Input_to_tmp) ;put path into input field
        $Path_to = GUICtrlRead($ChooseDirectory)
        If $Path_to = "" Then
            MsgBox (16, "Please specify a local path", "No local path specified!")
            ContinueLoop
        EndIf
    Case $case= $StartID
        if $ConfirmID And BitAND(GUICtrlRead($ConfirmID), $GUI_CHECKED) = $GUI_CHECKED Then
                   
                   $size = InetGetSize($File)
                   
                   ProgressOn ( "Downloading " & $File, "0% downloaded" , $size & " bytes remaining")
                   InetGet($File,$Path_to,0,1)
                   While @InetGetActive
                       $Percent=Int((@InetGetBytesRead*100)/$size)
                       $Remain=$size-@InetGetBytesRead
                       ProgressSet( $Percent,$Remain & " bytes remaining", $Percent & "% downloaded")
                       Sleep(100)
                   WEnd
                   
                   ProgressOff()
                   
                   MsgBox(64,"Download complete",$Path_to)
                   EndIf
                   
                   if $DoNotOverWriteID And BitAND(GUICtrlRead($DoNotOverWriteID), $GUI_CHECKED) = $GUI_CHECKED Then
                
                   
                   $size = InetGetSize($File)
                   
                   ProgressOn ( "Downloading " & $File, "0% downloaded" , $size & " bytes remaining")
                   
                   InetGet($File,$Path_to,0,1)
                   
                   While @InetGetActive
                       $Percent=Int((@InetGetBytesRead*100)/$size)
                       $Remain=$size-@InetGetBytesRead
                       ProgressSet( $Percent,$Remain & " bytes remaining", $Percent & "% downloaded")
                       Sleep(100)
                   WEnd
                   
                   ProgressOff()
                   
                   MsgBox(64,"Download complete",$Path_to)
               EndIf
               
                               if $OverWrite And BitAND(GUICtrlRead($OverWrite), $GUI_CHECKED) = $GUI_CHECKED Then
                
                   
                   $size = InetGetSize($File)
                   
                   ProgressOn ( "Downloading " & $File, "0% downloaded" , $size & " bytes remaining")
                   
                   InetGet($File,$Path_to,0,1)
                   
                   While @InetGetActive
                       $Percent=Int((@InetGetBytesRead*100)/$size)
                       $Remain=$size-@InetGetBytesRead
                       ProgressSet( $Percent,$Remain & " bytes remaining", $Percent & "% downloaded")
                       Sleep(100)
                   WEnd
                   
                   ProgressOff()
                   
                   MsgBox(64,"Download complete",$Path_to)
               EndIf
               
        Case $case= $CloseID
            ExitLoop ;exit program
        Case $case= $GUI_EVENT_CLOSE
            ExitLoop ;exit program
        EndSelect
        WEnd
Exit
        
        Func _StopDownloading()
    InetGet("abort")
EndFunc

post-30975-1200062247_thumb.jpg

i don't want this picture

post-30975-1200062236_thumb.jpg

i want this picture

plz, help me.

Link to comment
Share on other sites

#include <GUIConstants.au3>

GUICreate("AutoIt Downloader", 395, 170)

$ConfirmID = GUICtrlCreateRadio("Confirm", 20, 110, 90)
$DoNotOverWriteID = GUICtrlCreateRadio("Don't overwrite", 116, 110, 130)
$OverWrite = GUICtrlCreateRadio("Overwrite", 260, 110, 100)
$Label = GUICtrlCreateLabel("Made by RiZon", 10, 145)
$StartID = GUICtrlCreateButton("Start", 225, 140, 70, 23)
$CloseID = GUICtrlCreateButton("Close", 313, 140, 70, 23)
$ProgressID = GUICtrlCreateProgress("10", 75, 370, 20)
$ChooseDirectory = GUICtrlCreateInput("C:\SciTE4AutoIt3.exe", 10, 40, 290, 20)
$FileBrowse = GUICtrlCreateButton("Browse...", 310, 40, 70, 20)
$File = "http://www.autoitscript.com/cgi-bin/getfile.pl?../autoit3/scite/download/SciTE4AutoIt3.exe"
;GUISetOnEvent($CloseID,"_StopDownloading")
HotKeySet("{Esc}", "_StopDownloading")
GUICtrlSetState($ConfirmID, $GUI_CHECKED)
GUISetState()  ; display the GUI
$Path_to = GUICtrlRead($ChooseDirectory)

$MyDocsFolder = "::{450D8FBA-AD25-11D0-98A8-0800361B1103}"



While 1
    $case = GUIGetMsg()

    Select
        Case $case = $FileBrowse
            $Input_to_tmp = FileSaveDialog("Save As", $MyDocsFolder, "All files (*.*)", 16, "SciTE4AutoIt3.exe")
            ; option 2 = dialog remains until valid path/file selected
            If @error Then ContinueLoop
            GUICtrlSetData($ChooseDirectory, $Input_to_tmp) ;put path into input field
            $Path_to = GUICtrlRead($ChooseDirectory)
            If $Path_to = "" Then
                MsgBox(16, "Please specify a local path", "No local path specified!")
                ContinueLoop
            EndIf
        Case $case = $StartID
            If $ConfirmID And BitAND(GUICtrlRead($ConfirmID), $GUI_CHECKED) = $GUI_CHECKED Then

                $size = InetGetSize($File)

;~                    ProgressOn ( "Downloading " & $File, "0% downloaded" , $size & " bytes remaining")
                InetGet($File, $Path_to, 0, 1)
                While @InetGetActive
                    $Percent = Int((@InetGetBytesRead * 100) / $size)
                    $Remain = $size - @InetGetBytesRead
;~                        ProgressSet( $Percent,$Remain & " bytes remaining", $Percent & "% downloaded")
                    GUICtrlSetData($ProgressID, $Percent)
                    Sleep(100)
                WEnd
                                GUICtrlSetData($ProgressID, 100)
;~              ProgressOff()

                MsgBox(64, "Download complete", $Path_to)
            EndIf

            If $DoNotOverWriteID And BitAND(GUICtrlRead($DoNotOverWriteID), $GUI_CHECKED) = $GUI_CHECKED Then


                $size = InetGetSize($File)

;~              ProgressOn("Downloading " & $File, "0% downloaded", $size & " bytes remaining")

                InetGet($File, $Path_to, 0, 1)

                While @InetGetActive
                    $Percent = Int((@InetGetBytesRead * 100) / $size)
                    $Remain = $size - @InetGetBytesRead
;~                  ProgressSet($Percent, $Remain & " bytes remaining", $Percent & "% downloaded")
                    GUICtrlSetData($ProgressID, $Percent)
                    Sleep(100)
                WEnd

                GUICtrlSetData($ProgressID, 100)
;~              ProgressOff()

                MsgBox(64, "Download complete", $Path_to)
            EndIf

            If $OverWrite And BitAND(GUICtrlRead($OverWrite), $GUI_CHECKED) = $GUI_CHECKED Then


                $size = InetGetSize($File)

;~              ProgressOn("Downloading " & $File, "0% downloaded", $size & " bytes remaining")

                InetGet($File, $Path_to, 0, 1)

                While @InetGetActive
                    $Percent = Int((@InetGetBytesRead * 100) / $size)
                    $Remain = $size - @InetGetBytesRead
;~                  ProgressSet($Percent, $Remain & " bytes remaining", $Percent & "% downloaded")
                    GUICtrlSetData($ProgressID, $Percent)
                    Sleep(100)
                WEnd

                GUICtrlSetData($ProgressID, 100)
;~              ProgressOff()

                MsgBox(64, "Download complete", $Path_to)
            EndIf

        Case $case = $CloseID
            ExitLoop ;exit program
        Case $case = $GUI_EVENT_CLOSE
            ExitLoop ;exit program
    EndSelect
WEnd
Exit

Func _StopDownloading()
    InetGet("abort")
EndFunc   ;==>_StopDownloading

Link to comment
Share on other sites

Optimized version --> eliminated repeating the same code by using function _DownloadOneFile()

#include <GUIConstants.au3>

GUICreate("AutoIt Downloader", 395, 170)

$ConfirmID = GUICtrlCreateRadio("Confirm", 20, 110, 90)
$DoNotOverWriteID = GUICtrlCreateRadio("Don't overwrite", 116, 110, 130)
$OverWrite = GUICtrlCreateRadio("Overwrite", 260, 110, 100)
$Label = GUICtrlCreateLabel("Made by RiZon", 10, 145)
$StartID = GUICtrlCreateButton("Start", 225, 140, 70, 23)
$CloseID = GUICtrlCreateButton("Close", 313, 140, 70, 23)
$ProgressID = GUICtrlCreateProgress("10", 75, 370, 20)
$ChooseDirectory = GUICtrlCreateInput("C:\SciTE4AutoIt3.exe", 10, 40, 290, 20)
$FileBrowse = GUICtrlCreateButton("Browse...", 310, 40, 70, 20)
$File = "http://www.autoitscript.com/cgi-bin/getfile.pl?../autoit3/scite/download/SciTE4AutoIt3.exe"
;GUISetOnEvent($CloseID,"_StopDownloading")
HotKeySet("{Esc}", "_StopDownloading")
GUICtrlSetState($ConfirmID, $GUI_CHECKED)
GUISetState()  ; display the GUI
$Path_to = GUICtrlRead($ChooseDirectory)

$MyDocsFolder = "::{450D8FBA-AD25-11D0-98A8-0800361B1103}"

While 1
    $case = GUIGetMsg()

    Select
        Case $case = $FileBrowse
            $Input_to_tmp = FileSaveDialog("Save As", $MyDocsFolder, "All files (*.*)", 16, "SciTE4AutoIt3.exe")
            ; option 2 = dialog remains until valid path/file selected
            If @error Then ContinueLoop
            GUICtrlSetData($ChooseDirectory, $Input_to_tmp) ;put path into input field
            $Path_to = GUICtrlRead($ChooseDirectory)
            If $Path_to = "" Then
                MsgBox(16, "Please specify a local path", "No local path specified!")
                ContinueLoop
            EndIf
        Case $case = $StartID
            If BitAND(GUICtrlRead($ConfirmID), $GUI_CHECKED) = $GUI_CHECKED Then
                _DownloadOneFile($File, 1)
            EndIf

            If BitAND(GUICtrlRead($DoNotOverWriteID), $GUI_CHECKED) = $GUI_CHECKED Then
                _DownloadOneFile($File, 2)
            EndIf

            If BitAND(GUICtrlRead($OverWrite), $GUI_CHECKED) = $GUI_CHECKED Then
                _DownloadOneFile($File, 3)
            EndIf

        Case $case = $CloseID
            ExitLoop ;exit program
        Case $case = $GUI_EVENT_CLOSE
            ExitLoop ;exit program
    EndSelect
WEnd
Exit

Func _StopDownloading()
    InetGet("abort")
EndFunc   ;==>_StopDownloading

Func _DownloadOneFile($FileUrl, $Mode) ; Mode: 1-Confirm 2-Don't OverWrite 3-OverWrite
    If $Mode = 1 Then 
        ; ...
    EndIf

    GUICtrlSetData($ProgressID, 0)
        $size = InetGetSize($FileUrl)
    InetGet($FileUrl, $Path_to, 0, 1)

    While @InetGetActive
        $Percent = Int((@InetGetBytesRead * 100) / $size)
        $Remain = $size - @InetGetBytesRead
        GUICtrlSetData($ProgressID, $Percent)
        Sleep(100)
    WEnd

    GUICtrlSetData($ProgressID, 100)

    If $Mode = 2 Then ; don't overwrite
        ; ...
    EndIf
        MsgBox(64, "Download complete", $Path_to)
EndFunc
Edited by Zedna
Link to comment
Share on other sites

  • 3 weeks later...

Got same problem but modifyed my Code like that but everything is working but still the new window popups

I dont want to see this :D

#NoTrayIcon
#include <GUIConstants.au3>
#Region
$Form1_1 = GUICreate("Updater By Jewel", 230, 325, 193, 125)
$Group1 = GUICtrlCreateGroup("Downloader", 16, 16, 193, 161)
$Button3 = GUICtrlCreateButton("Beta", 48, 96, 121, 33, 0)
$Button1 = GUICtrlCreateButton("Update", 48, 40, 121, 41, 0)
$Button2 = GUICtrlCreateButton("www.something.com", 48, 144, 121, 17, 0)
GUICtrlCreateGroup("", -99, -99, 1, 1)
$Group2 = GUICtrlCreateGroup("Progress", 16, 184, 193, 97)
$Progress1 = GUICtrlCreateProgress(32, 216, 153, 33)
GUICtrlCreateGroup("", -99, -99, 1, 1)
$MenuItem1 = GUICtrlCreateMenu("&File")
$MenuItem3 = GUICtrlCreateMenuItem("Options", $MenuItem1)
$MenuItem2 = GUICtrlCreateMenuItem("Exit", $MenuItem1)
$MenuItem4 = GUICtrlCreateMenu("Help")
$MenuItem7 = GUICtrlCreateMenuItem("About", $MenuItem4)
$MenuItem6 = GUICtrlCreateMenuItem("Extra", $MenuItem4)
$MenuItem5 = GUICtrlCreateMenuItem("!Reports!", $MenuItem4)
$Update = "http://www.autoitscript.com/cgi-bin/getfile.pl?../autoit3/scite/download/SciTE4AutoIt3.exe"
$Beta = "Nothing yet!"
HotKeySet("{Esc}", "_StopDownloading")
GUISetState(@SW_SHOW)

#Endregion

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            exit
        Case $Button1
            $size = InetGetSize($Update)
        ProgressOn("Downloading " & $Update, "0% Downloaded", $size & " Bytes Remaining")
            InetGet($Update, "th.rar", 0, 1)
            While @InetGetActive
                $Percent = Int(@InetGetBytesRead * 100 / $size)
                $Remain = $size - @InetGetBytesRead
            ProgressSet( $Percent,$Remain & " bytes remaining", $Percent & "% downloaded")
            GUICtrlSetData($Progress1, $Percent)
        sleep(100)
    WEnd
            GUICtrlSetData($Progress1, 100)
            ProgressOff()
            
                MsgBox(0, "Download complete", "Thanks for Using My Updater.",0)
            
        Case $Button2
            ShellExecute("http://www.autoitscript.com")
        Case $Button3
            MsgBox(1, "Beta", "There's no Beta Available. Not really working :p. Adding Checks later.",5)
        Case $MenuItem1
            ExitLoop
        Case $MenuItem3
            ExitLoop
        Case $MenuItem2
            ExitLoop
        Case $MenuItem4
            ExitLoop
        Case $MenuItem5
            ExitLoop
        Case $MenuItem6
            ExitLoop
        Case $MenuItem7
            ExitLoop
        
    EndSwitch
WEnd

Func _StopDownloading()
    InetGet("abort")
EndFunc;==>_StopDownloading
Edited by Jewel
Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...