RichE Posted January 20, 2009 Share Posted January 20, 2009 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 expandcollapse popup#cs ---------------------------------------------------------------------------- AutoIt Version: 3.2.12.1 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) $SourceFiles = GUICtrlCreatelistview("", 16, 72, 289, 329, BitOR($LVS_LIST,$LVS_SHOWSELALWAYS,$LVS_SORTASCENDING,$LVS_AUTOARRANGE,$WS_HSCROLL,$WS_VSCROLL), $WS_EX_CLIENTEDGE) ; 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) EndIf WEnd ; Close the search handle FileClose($search) ;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") $DestinationFiles = GUICtrlCreateListview("", 384, 72, 289, 329, BitOR($LVS_LIST,$LVS_SHOWSELALWAYS,$LVS_SORTASCENDING,$LVS_AUTOARRANGE,$WS_HSCROLL,$WS_VSCROLL), $WS_EX_CLIENTEDGE) $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. GUISetState(@SW_SHOW) While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit 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) Else $iI = 1 ;check for select source if @error or $s[0] = 0 Then msgbox(48, "NDS Roms", "No NDS Roms slected", 3) Else 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) #cs Do $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 & "%") next until $dsize = $ssize #ce _GUICtrlListView_CopyItems($SourceFiles, $destinationfiles, True) ;update sourcefiles rom count guictrlsetdata($romcount, _GUICtrlListView_GetItemCount($sourcefiles), "") ;update destination rom count guictrlsetdata($dromcount, _GUICtrlListView_GetItemCount($destinationfiles), "") Next EndIf EndIf case $sourceselect ;description: select source for source files. ;clear entries _GUICtrlListView_DeleteAllItems($Sourcefiles) 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) Else guictrlsetdata($sourcedrive, $sourcepath & "\", "") EndIf ;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 EndIf WEnd ; Close the search handle FileClose($search) ;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) else DirCreate($destpath & "Games") Msgbox(4160, "Games Folder", "Games folder created on Drive " & $destpath, 3) GUICtrlSetData($destinationdrive, $destpath & "Games\", "") GUICtrlSetState($creategames, $GUI_DISABLE) EndIf case $selectdest ;clear entries if guictrlread($sourcedrive) <> "" Then _GUICtrlListView_DeleteAllItems($destinationfiles) 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) Else guictrlsetdata($destinationdrive, $Destpath & "\", "") if not StringInStr($destpath, "Games") then GUICtrlSetState($creategames, $GUI_ENABLE) EndIf EndIf ;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 EndIf WEnd ; Close the search handle FileClose($search) Else Msgbox(48, "No Source", "Please select a source drive and folder first", 5) EndIf EndSwitch WEnd Thx in advance RichE [font="'Arial Narrow';"]Current projects[/font] [font="'Arial Narrow';"]are on my site [/font]Sellostring Link to comment Share on other sites More sharing options...
monoceres Posted January 20, 2009 Share Posted January 20, 2009 (edited) 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 resultsb ) 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 January 20, 2009 by monoceres Broken link? PM me and I'll send you the file! Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now