Jump to content
Sign in to follow this  

Help with progress bar

Recommended Posts


Hi folks,

I need some help with the progress bar part of this gui i'm writing, I would like to show the file copy and know the theory of comparing file sizes but my head has turn to mush and can't think sraight atm, so any help would be greatly recieved :)

as you can see i've had a bash at the progress bar part, but it's commented out atm

#cs ----------------------------------------------------------------------------
        AutoIt Version:
        Author:      Rich Easton
        www:             http://thesauce.webs.com
        Script Function:
           NDS Rom Explorer.
       #ce ----------------------------------------------------------------------------
       #include <GUIConstants.au3>
       #include <GUIConstantsEx.au3>
       #include <WindowsConstants.au3>
       #include <ListviewConstants.au3>
       #include <TreeViewConstants.au3>
       #Include <GuiListView.au3>
       #Include <GuiListBox.au3>
       #Include <GuiTreeView.au3>
       #Include <File.au3>          
       #include <ButtonConstants.au3>
       #include <ComboConstants.au3>
       #include <Array.au3>
       $NDSForm = GUICreate("NDS Explorer.", 690, 497, -1, -1)
      ;Source section start
       $SourceGrp = GUICtrlCreateGroup(" Source ", 8, 32, 305, 409)
       $SourceDrive = GUICtrlCreateInput("", 16, 48, 200, 20)
       $sourceselect = GUICtrlCreateButton("Source", 220, 48, 80, 20)
       GUICtrlSetTip(-1, "Select the source of the DS Rom", "Select Source Button")
       GUICtrlCreateLabel("Number of Roms: ", 16,413, 250, 25)
       $romcount = GUICtrlCreateLabel("0", 110,413, 150, 25)
      ; Shows the filenames of .nds files in the current directory.
       $search = FileFindFirstFile(Guictrlread($sourcedrive) & "\*.nds"  )
       While 1
           $file = FileFindNextFile($search) 
           If @error Then ExitLoop
           if stringinstr($file, ".") Then
           GUICtrlCreatelistViewItem($file, $SourceFiles)
      ; Close the search handle
      ;source section end
      ;destination section start
       $DestinationGrp = GUICtrlCreateGroup(" Destination ", 376, 32, 305, 409)
       $DestinationDrive = GUICtrlCreateInput("", 384, 48, 200, 20)
       $selectdest = GUICtrlCreateButton("Destination", 590, 48, 80, 20)
       GUICtrlSetTip($selectdest, "Select the Destination for the DS Roms", "Destination Button")
       $CBX_createfolders = GUICtrlCreatebutton("Create Folders", 384, 408, 89, 25)
       GUICtrlSetTip($CBX_createfolders, "If you Click this, NDS Explorer will create a folder for each games in your destination", "Create Folders")
       guictrlcreatelabel("Number of Roms: ", 480, 413, 100,25) 
       $dromcount = guictrlcreatelabel("0", 575, 413, 50, 25)
      ;destination section end
      ;controls section start.
       GUICtrlCreateGroup(" Controls ", 8, 445, 673, 50)
       $creategames = guictrlcreatebutton("Create Games", 16, 460, 100, 25)
       GUICtrlSetTip($creategames, "Setup the Initial Games folder to copy the ROM's into.", "Create Games Button")
       GUICtrlSetState($creategames, $GUI_DISABLE)
       $copygame = guictrlcreatebutton("Copy Games", 120, 460, 100, 25)
       GUICtrlSetTip($copygame, "Will copy the selected games from the source to destination.", "Copy Games Button")
      ;controls section end.
       While 1
           $nMsg = GUIGetMsg()
           Switch $nMsg
               Case $GUI_EVENT_CLOSE
               Case $copygame
                  ;description: copies files from source to destination
                   Local $sItems, $aitems, $s, $sic, $da
                   $da = _GUICtrlListView_GetSelectedIndices($sourcefiles, False)
                   $s = stringsplit($da, "|", 0)
                   if Guictrlread($destinationdrive) = "" or @Error Then
                       msgbox(48, "Warning!", "No Destination Selected", 3)
                       $iI = 1
                          ;check for select source
                       if @error or $s[0] = 0 Then
                           msgbox(48, "NDS Roms", "No NDS Roms slected", 3)
                           For $iI = 0 To $s[0]
                              ;check for selected file in destination.
                               _GUICtrlListView_GetItemSelected($SourceFiles, $iI)
                              ;get text of selected item(s)
                               $aitems = _GUICtrlListView_GetItemText($SourceFiles, $iI)
                              ;progresson("File Copy Operation", $aitems & ".nds", "")
                               filecopy(guictrlread($sourcedrive) & $aitems & ".nds", guictrlread($destinationdrive) & "\" ,  0)
                                   $ssize = FileGetsize(guictrlread($sourcedrive) & $aitems & ".nds")
                                   $dsize = FileGetsize(guictrlread($destinationdrive) & $aitems & ".nds")
                                   $p = $dsize/$ssize*100 
                                   ProgressSet(0, "", "")
                                   for  $v = 1 to 100 step 1
                                       ProgressSet($p, $Aitems, $p & "%")
                           until $dsize = $ssize
                               _GUICtrlListView_CopyItems($SourceFiles, $destinationfiles, True)
                              ;update sourcefiles rom count
                               guictrlsetdata($romcount, _GUICtrlListView_GetItemCount($sourcefiles), "")
                              ;update destination rom count
                               guictrlsetdata($dromcount, _GUICtrlListView_GetItemCount($destinationfiles), "")
               case $sourceselect
                  ;description: select source for source files.
                  ;clear entries
                   guictrlsetdata($sourcedrive, "", "")
                   guictrlsetdata($romcount, "Number of Roms: ", "")
                  ;select folder dialog
                   $sourcepath = Fileselectfolder("Please Select Source Location..", "")
                   if $sourcepath = "" or @error Then
                       Msgbox(48, "Warning!", "No Source Folder selected!", 3)
                       guictrlsetdata($sourcedrive, $sourcepath & "\", "")
                  ;read the path to the source folder and enumerate the files
                   $search = FileFindFirstFile(Guictrlread($sourcedrive) & "*.nds")
                   $n = 1
                   While 1
                       $file = FileFindNextFile($search) 
                       If @error Then ExitLoop
                       if stringinstr($file, ".") Then
                          ;take the etxn off the end
                           $FileName = stringsplit($file, ".")
                           GUICtrlCreateListViewItem($filename[1], $SourceFiles)
                           guictrlsetdata($romcount, $n, "")
                           $n = $n +1
                  ; Close the search handle
                  ;update the rom count
               case $creategames
                  ;description: creates games folder on destination target
                   $destpath = guictrlread($DestinationDrive)
                   $destpathg = $destpath & "Games"
                   if $destpath = "" or @error Then
                       Msgbox(48, "Warning!", "No Destination path select, please select a destination.!", 3)
                       DirCreate($destpath & "Games")
                       Msgbox(4160, "Games Folder", "Games folder created on Drive " & $destpath, 3)
                       GUICtrlSetData($destinationdrive, $destpath & "Games\", "")
                       GUICtrlSetState($creategames, $GUI_DISABLE)
               case $selectdest
                  ;clear entries
                   if guictrlread($sourcedrive) <> "" Then
                       guictrlsetdata($DestinationDrive, "", "")
                      ;open file open dialog
                           $destpath = FileSelectFolder("Please Select Destination Location..", "")
                           if $destpath = "" or @error Then
                               Msgbox(48, "Warning!", "No Destination Folder selected!", 3)
                               guictrlsetdata($destinationdrive, $Destpath & "\", "")
                               if not StringInStr($destpath, "Games") then
                                   GUICtrlSetState($creategames, $GUI_ENABLE)
                              ;read the path to the source folder and enumerate the files
                               $search = FileFindFirstFile(Guictrlread($DestinationDrive) & "\*.nds")
                               $n = 0
                               While 1
                                   $file = FileFindNextFile($search) 
                                   If @error Then ExitLoop
                                   if stringinstr($file, ".") Then
                                      ;take the etxn off the end
                                       $FileName = stringsplit($file, ".")
                                       GUICtrlCreateListViewItem($filename[1], $DestinationFiles)
                                       $listitem = _GUICtrlListView_FindParam($sourcefiles, $filename[1], -1)
                                       _GUICtrlListView_DeleteItem($sourcefiles, $filename[1])
                                      ;update the rom counts
                                       guictrlsetdata($romcount, _GUICtrlListView_GetItemCount($sourcefiles), "")
                                       guictrlsetdata($dromcount, _GUICtrlListView_GetItemCount($destinationfiles), "")
                                       $n = +1
                              ; Close the search handle
                       Msgbox(48, "No Source", "Please select a source drive and folder first", 5)

Thx in advance :lmao:


[font="'Arial Narrow';"]Current projects[/font]

[font="'Arial Narrow';"]are on my site [/font]Sellostring

Share this post

Link to post
Share on other sites

The problem is the FileCopy function. It doesn't return until the copying is done so when it's time to update the progress bar the progress is already complete.

To solve it you can either:

a ) Check out these search results

b ) Read and write the file manually one part at time with the FileRead()/FileWrite functions and update the progress bar between the loop iterations.


Edited by monoceres

Broken link? PM me and I'll send you the file!

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