Sign in to follow this  
Followers 0
Charus

copy with gui progress bar

4 posts in this topic

hello guys... i want i little help to finish my script. i crate a script that copys games from a server machine to pc's and i want a gui progress bar to check the copy status

my script is:

If FileExists("E:\Thief - Deadly Shadows\installed.txt") Then

run("t3.exe", "E:\Thief - Deadly Shadows\System\", @SW_MAXIMIZE)

Else

If FileExists("\\GameServer\Games\Thief - Deadly Shadows\") Then

FileCopy("\\GameServer\Games\Thief - Deadly Shadows\installed.txt", "E:\Thief - Deadly Shadows\", 9)

DirCopy("\\GameServer\Games\Thief - Deadly Shadows\" , "E:\")

Else

MsgBox(16,"Error", "I cant see target folder")

EndIf

EndIf

Exit

and the gui progress bar is this:

#include<GuiConstants.au3>

GUICreate("Example", 600, 140)

$ProgressBar = GUICtrlCreateProgress( 50, 50, 500, 20)

$Label = GUICtrlCreateLabel("Click to Begin", 270, 5, 80, 20)

$Begin = GUICtrlCreateButton("Begin", 250, 80, 100, 30)

$ProgressBarLoaded = 0

GUISetState()

While 1

$msg = GUIGetMsg()

Select

Case $msg = $Begin

If $ProgressBarLoaded = 0 Then

GUICtrlSetData($Label, "Loading...")

GUICtrlSetState($Begin, $GUI_DISABLE)

GUICtrlSetData($Begin, "Loading...")

GUICtrlSetData($ProgressBar, 10)

Sleep(100)

GUICtrlSetData($ProgressBar, 20)

Sleep(100)

GUICtrlSetData($ProgressBar, 30)

Sleep(100)

GUICtrlSetData($ProgressBar, 40)

Sleep(100)

GUICtrlSetData($ProgressBar, 50)

Sleep(100)

GUICtrlSetData($ProgressBar, 60)

Sleep(100)

GUICtrlSetData($ProgressBar, 70)

Sleep(100)

GUICtrlSetData($ProgressBar, 80)

Sleep(100)

GUICtrlSetData($ProgressBar, 90)

Sleep(100)

GUICtrlSetData($ProgressBar, 100)

GUICtrlSetData($Label, "Finished!")

GUICtrlSetData($Begin, "Exit")

GUICtrlSetState($Begin, $GUI_ENABLE)

$ProgressBarLoaded = 1

Else

Exit

EndIf

Case $msg = $GUI_EVENT_CLOSE

Exit

EndSelect

WEnd

i want help to much this script to work together. pls someone help me

Share this post


Link to post
Share on other sites



erm, you might be in luck. I have done so many different approaches to automating stuff for lan parties it is ridiculous. From batch to wsh to vbs to full on vb to a little c++ to torrents to finally my favorite, AutoIt.

I developed some pretty good ideas, but the #1 thing I found to be an issue was more than one peep pushing or pulling from the server at the same time. I fixed that with tag files that my script looked for and just paused until the tag file was either present or not. I am still working out newer and better models.

Anyway, you could look for a post by ezzetabi I believe it was. I incorporated most of his into my stuff. I forget now if it was his or someone else's originally.

Regardless, here is a sample now of how I transfer things I want with copy progress. Enjoy

Sul

#cs ===============================================================================

X-CPI ver. 1.0 - 01.26.2007
Autor: MrWoo, Ezzetabi (copy progress)
Language: English
OSystem: Windows Xp
Features: simple method to install an application via copy/paste

        -simple progress bar showing % by file
        -minimal code to change

Requirements: Windows Xp/2000
Construction: Autoit 3.2.0.1, SciTE 1.70
#ce ==========>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>

#region - CHECK PREVIOUS INSTANCE AND HOT-KEY EXIT -
$appV = "X-CPI"
If WinExists($appV) Then Exit 
AutoItWinSetTitle($appV)
HotKeySet("^!x", "_exit"); exit hotkeys are Ctrl + Alt + X
#endregion ---------->>>>>>>>>>>>>>>

; Copy Battlefield 2142 into c:\Program Files\Electronic Arts\Battlefield 2142
; script resided in same directory as $StartDir

$StartDir = "Electronic Arts"; name of child directory for paste target
$TargetDir = "C:\Program Files\" & $StartDir; name of parent directory for paste target
$AppDesc = "Battlefield 2142"; description displayed in progress bar
$copy = _CopyDirWithProgress(@ScriptDir & "\" & $StartDir,$TargetDir,$AppDesc)

If @error = -1 Or @error = 1 Or @error = 2 Then; error codes for CopyDirWithProgress NOT working
    MsgBox(4096,"Error","There was an error copying files. Try it manually")
ElseIf @error = 0 Then; CopyDirWithProgress DID work
    MsgBox(4096,"Success","Files copied")
EndIf

Exit

#region - FUNCTION _CopyDirWithProgress - dump directory to array to display progress and copy -
Func _CopyDirWithProgress($sOriginalDir, $sDestDir, $AppDesc)
;$sOriginalDir and $sDestDir are quite self explanatory...
;This func returns:
; -1 in case of critical error, bad original (@error = 1) or destination (@error = 2) dir
; '' (empty string) if everything went all right
; 'list|list|list' list of uncopied files, original full paths separed by pipes '|'
;  @error is also set to 3
   If StringRight($sOriginalDir, 1) <> '\' Then $sOriginalDir = $sOriginalDir & '\'
   If StringRight($sDestDir, 1) <> '\' Then $sDestDir = $sDestDir & '\'
    ProgressOn('Copying ' & $AppDesc & '...', 'Making list of files...', '', -1, -1, 18) 
   Local $aFileList = _FileSearch($sOriginalDir)
   If $aFileList[0] = 0 Then
      ProgressOff()
      SetError(1)
      Return -1
   EndIf
   If FileExists($sDestDir) Then
      If Not StringInStr(FileGetAttrib($sDestDir), 'd') Then
         ProgressOff()
         SetError(2)
         Return -1
      EndIf
   Else
      DirCreate($sDestDir)
      If Not FileExists($sDestDir) Then
         ProgressOff()
         SetError(2)
         Return -1
      EndIf
   EndIf
   Local $iDirSize, $iCopiedSize = 0, $fProgress = 0
   Local $c, $FileName, $iOutPut = ''
   Local $Sl = StringLen($sOriginalDir)
   _Quick_Sort($aFileList, 1, $aFileList[0])
   $iDirSize = Int(DirGetSize ($sOriginalDir) / 1024)
   ProgressSet(Int($fProgress * 100), $aFileList[$c], 'Copying file:')
   For $c = 1 To $aFileList[0]
      $FileName = StringTrimLeft($aFileList[$c], $Sl)
      If StringInStr(FileGetAttrib($aFileList[$c]), 'd') Then
         DirCreate($sDestDir & $FileName)
      Else
         ProgressSet(Int($fProgress * 100), StringTrimLeft($aFileList[$c], StringInStr($aFileList[$c], '\', 0, -2)) & @lf & 'Total Kbytes: ' & $iDirSize & @lf & 'Done Kbytes: ' & $iCopiedSize)
         If Not FileCopy($aFileList[$c], $sDestDir & $FileName, 1) Then
            $iOutPut = $iOutPut & '|' & $aFileList[$c]
         EndIf
         $iCopiedSize = $iCopiedSize + Int(FileGetSize($aFileList[$c]) / 1024)
         $fProgress = $iCopiedSize / $iDirSize
      EndIf
   Next
   ProgressOff()
   If $iOutPut <> '' Then SetError(3)
   Return $iOutPut
EndFunc;==>_CopyDirWithProgress
#endregion

#region - FUNCTION  _FileSearch - parse array -
Func _FileSearch($sIstr, $bSF = 1)
; $bSF = 1 means looking in subfolders
; $sSF = 0 means looking only in the current folder.
; An array is returned with the full path of all files found. The pos [0] keeps the number of elements.
Local $sCriteria, $sBuffer, $iH, $iH2, $sCS, $sCF, $sCF2, $sCP, $sFP, $sOutPut = '', $aNull[1];$sIstr, $bSF, 
   $sCP = StringLeft($sIstr, StringInStr($sIstr, '\', 0, -1))
   If $sCP = '' Then $sCP = @WorkingDir & '\'
   $sCriteria = StringTrimLeft($sIstr, StringInStr($sIstr, '\', 0, -1))
   If $sCriteria = '' Then $sCriteria = '*.*'
;To begin we seek in the starting path.
   $sCS = FileFindFirstFile($sCP & $sCriteria)
   While $sCS <> - 1
      $sCF = FileFindNextFile($sCS)
      If @error Then
         FileClose($sCS)
         ExitLoop
      EndIf
      If $sCF = '.' Or $sCF = '..' Then ContinueLoop
      $sOutPut = $sOutPut & $sCP & $sCF & @LF
   Wend
;And after, if needed, in the rest of the folders.
   If $bSF = 1 Then
      $sBuffer = @CR & $sCP & '*' & @LF;The buffer is set for keeping the given path plus a *.
      Do
         $sCS = StringTrimLeft(StringLeft($sBuffer, StringInStr($sBuffer, @LF, 0, 1) - 1), 1);current search.
         $sCP = StringLeft($sCS, StringInStr($sCS, '\', 0, -1));Current search path.
         $iH = FileFindFirstFile($sCS)
         While $iH <> - 1
            $sCF = FileFindNextFile($iH)
            If @error Then
               FileClose($iH)
               ExitLoop
            EndIf
            If $sCF = '.' Or $sCF = '..' Then ContinueLoop
            If StringInStr(FileGetAttrib($sCP & $sCF), 'd') Then
               $sBuffer = @CR & $sCP & $sCF & '\*' & @LF & $sBuffer;Every folder found is added in the begin of buffer
               $sFP = $sCP & $sCF & '\';                            for future searches
               $iH2 = FileFindFirstFile($sFP & $sCriteria);      and checked with the criteria.
               While $iH2 <> - 1
                  $sCF2 = FileFindNextFile($iH2)
                  If @error Then
                     FileClose($iH2)
                     ExitLoop
                  EndIf
                  If $sCF2 = '.' Or $sCF2 = '..' Then ContinueLoop
                  $sOutPut = $sOutPut & $sFP & $sCF2 & @LF;Found items are put in the Output.
               Wend
            EndIf
         Wend
         $sBuffer = StringReplace($sBuffer, @CR & $sCS & @LF, '')
      Until $sBuffer = ''
   EndIf
   If $sOutPut = '' Then
      $aNull[0] = 0
      Return $aNull
   Else
      Return StringSplit(StringTrimRight($sOutPut, 1), @LF)
   EndIf
EndFunc;==>_FileSearch
#endregion

#region - FUNCTION  _QuickSort - sort array -
Func _Quick_Sort(ByRef $SortArray, $First, $Last);Larry code
   Dim $Low, $High
   Dim $Temp, $List_Separator
   $Low = $First
   $High = $Last
   $List_Separator = StringLen($SortArray[ ($First + $Last) / 2])
   Do
      While (StringLen($SortArray[$Low]) < $List_Separator)
         $Low = $Low + 1
      Wend
      While (StringLen($SortArray[$High]) > $List_Separator)
         $High = $High - 1
      Wend
      If ($Low <= $High) Then
         $Temp = $SortArray[$Low]
         $SortArray[$Low] = $SortArray[$High]
         $SortArray[$High] = $Temp
         $Low = $Low + 1
         $High = $High - 1
      EndIf
   Until $Low > $High
   If ($First < $High) Then _Quick_Sort($SortArray, $First, $High)
   If ($Low < $Last) Then _Quick_Sort($SortArray, $Low, $Last)
   EndFunc;==>_Quick_Sort
#endregion

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

i have something like this. this isnt a gui progress bar :/ its not helps me thx btw

Edited by Charus

Share this post


Link to post
Share on other sites

hello guys... i want i little help to finish my script. i crate a script that copys games from a server machine to pc's and i want a gui progress bar to check the copy status

umm, the script I put up does not do exactly what you request, no. But, if you have a progress bar you can certainly trade in the progress bar that is built with this script and instead reference the one on your gui. Pretty much any progress bar can be updated with that routine with some slight modifications. I should know, I use it in every gui app that I build where it requires some semblance of "how much longer" questions.

Sul

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