migration backup tool with autoit

View previous topic View next topic Go down

migration backup tool with autoit

Post  surreal on Mon Oct 26, 2009 1:01 am

i found this website within the autoit forums. i have started the script, however i have hit some road blocks. i would like to add a progressbar and error checking, as well as make sure im writing this code correctly or best practiced. im still somewhat of a newbie to programing but have enjoyed learning from everyones help.

if this is something that this site can help with that would be great. im mostly looking for someone that can help me finish this program, as this well help me learn as we do. im a desktop support tech, dont make much but im willing to donate some cash if possible.

im not sure if i should included this code here or just add a link to the autoit request. at this time i will add the link, if you would rather me included the info here i can do that as well, just let me know.

http://www.autoitscript.com/forum/index.php?showtopic=104509

d@ve

surreal

Posts: 11
Join date: 2009-10-26
Location: Denver, Colorado

View user profile

Back to top Go down

Re: migration backup tool with autoit

Post  P5ych0Gigabyte on Mon Oct 26, 2009 2:08 pm

Do you want to animate the progress bar you already have on the bottom of your gui?

P5ych0Gigabyte
Admin

Posts: 27
Join date: 2009-10-21
Location: New Jersey,USA

View user profile http://www.c4free.info

Back to top Go down

Re: migration backup tool with autoit

Post  P5ych0Gigabyte on Mon Oct 26, 2009 2:22 pm

Try this code out. I modified the CopyWithProgress function to update your label and progressbar and put the code into your app. Nice GUI by the way.

Download

P5ych0Gigabyte
Admin

Posts: 27
Join date: 2009-10-21
Location: New Jersey,USA

View user profile http://www.c4free.info

Back to top Go down

Re: migration backup tool with autoit

Post  surreal on Mon Oct 26, 2009 3:12 pm

damn, lol. that sucks that something that i have been trying to get to work you figured out so quickly, lol. thanks for the complement on the gui. i have a few questions:

i noticed that you are using PBAR.au3 to run the copy progress. does this work on dircopy only? i also have for the lotus notes stuff and future added stuff that just need to copy single files.

i noticed that this is a progress per folder, is is possible to also report back how much time or percent for the full copy? i played with the $TimeRemained but that is also just per folder time, not total time.

i have some other questions regarding some error checking and problems that im have with the gui. would i be able to post these here.
things like when the input is left blank the error message will pop up, then exit the gui. i tried to enter a return after the endif but then the rest of the code does not work. is it ok that im doing this all in fuctions, or should i be using cases.

wow, thank you so much for your help so far. let me know if you need some donations to keep this site going. and i will also try to help others within this site if it is within my coding skills.

d@ve

surreal

Posts: 11
Join date: 2009-10-26
Location: Denver, Colorado

View user profile

Back to top Go down

Re: migration backup tool with autoit

Post  P5ych0Gigabyte on Mon Oct 26, 2009 6:32 pm

As far as progress for the whole task it might be a good idea to add a second a progress bar. As far as the errors i'll take a look at the code and see what i can fix. Can you post a list of some of the errors?

P5ych0Gigabyte
Admin

Posts: 27
Join date: 2009-10-21
Location: New Jersey,USA

View user profile http://www.c4free.info

Back to top Go down

Re: migration backup tool with autoit

Post  surreal on Mon Oct 26, 2009 7:13 pm

im fine with the 2nd progressbar if you think it is possible to incorporate such a function. i will change the gui tonight, when i get home I will post the new code.

i have been playing with how to get progress for filecopy as well, but so far no luck. im leaving work right now but will post new code and errors as soon as im home, thank you so much for your help with this.

d@ve

surreal

Posts: 11
Join date: 2009-10-26
Location: Denver, Colorado

View user profile

Back to top Go down

Re: migration backup tool with autoit

Post  P5ych0Gigabyte on Mon Oct 26, 2009 7:19 pm

Progress for individual filemove calls would require using the fileread and filewrite functions. This would slow things down quite a bit.

P5ych0Gigabyte
Admin

Posts: 27
Join date: 2009-10-21
Location: New Jersey,USA

View user profile http://www.c4free.info

Back to top Go down

Re: migration backup tool with autoit

Post  surreal on Mon Oct 26, 2009 10:08 pm

i have uploaded the new gui to:

Download

how slow are we talking, i guess it does not matter do to the fact that this program is going to need to copy some single files.

i will work on the list of issues but before i post i wanna try and see if i can fix some of them tonight myself. had a few ideas on the way home.

i have added a full progress bar in the new gui and keep the details bar. im thinking best case solution would be:

top bar full process including single files and folders
bottom bar would be per file process instead of per folder, and within the details the file name only not full path and filename.

thanks so much again.
d@ve

surreal

Posts: 11
Join date: 2009-10-26
Location: Denver, Colorado

View user profile

Back to top Go down

Re: migration backup tool with autoit

Post  surreal on Mon Oct 26, 2009 11:06 pm

this of course is not as important as the progress bar. below is a problem im having to make the program more friendly.

i thought i may be able to get this to work if i tried a different way but i seemed to be just making things worse, so the situation is:

Within Computer To Tranfer From, and i click on connect:

if input is left blank, update GUICtrlCreateLabel("Enter Computer Name or IP Address", 248, 64, 174, 15) text to target machine must be entered.

if the ping is unsuccessful then update same GUICtrlCreateLabel text to something like could not connect to $cnTarget.

if the ping is successful i would like the exciting popup with remote system info then update same GUICtrlCreateLabel text to something like connected to $cnTarget.

now the part im not sure is possible:

if the ping is successful and after the popup i would like the profile dropdown updated at the sametime. that way it would be one less click, would no longer need to use the load button. the part im not sure is possible but can the last used profile pulled with wmi be visible without having to click on the dropdown? that way if the dropdown is used another profile can be selected if needed.

right now i have popups for errors that i dont want do to extra clicks and they are not working correctly, on vista they exit the gui, in xp just wired stuff, lol. thats why i though updating GUICtrlCreateLabel text may be a better way.

hopefully that made some sense, lol. if not let me know, its some what of a puzzle, but has been driving me nuts.

d@ve

surreal

Posts: 11
Join date: 2009-10-26
Location: Denver, Colorado

View user profile

Back to top Go down

Re: migration backup tool with autoit

Post  P5ych0Gigabyte on Mon Oct 26, 2009 11:17 pm

I have added the changes you requested and fixed the error if the box is empty.

Download

P5ych0Gigabyte
Admin

Posts: 27
Join date: 2009-10-21
Location: New Jersey,USA

View user profile http://www.c4free.info

Back to top Go down

Re: migration backup tool with autoit

Post  surreal on Mon Oct 26, 2009 11:44 pm

thanks again P5ych0Gigabyte!!!

i have been looking over your changes trying to learn from it, i like what you have done, maybe later i will try and attempt per file instead of per folder progress.

i tried the return tag thing, lol, but i put it after the endif, lol. would the above be possible instead. it would be so much cleaner, and less clicks.

wow, thanks again for all your help. i have been working on this for a couple of months, you have helped me get so far in such a short amount of time. i may be able to actually start using it pretty soon, sooner then i thought.

d@ve

surreal

Posts: 11
Join date: 2009-10-26
Location: Denver, Colorado

View user profile

Back to top Go down

Re: migration backup tool with autoit

Post  P5ych0Gigabyte on Wed Oct 28, 2009 3:41 am

I have changed the program so it loads the profile box automatically after connecting. I'm not sure how the get the last profile used automatically though.Download

P5ych0Gigabyte
Admin

Posts: 27
Join date: 2009-10-21
Location: New Jersey,USA

View user profile http://www.c4free.info

Back to top Go down

Re: migration backup tool with autoit

Post  surreal on Wed Oct 28, 2009 7:23 pm

i have made changes to the code after much reading, hopefully for the better. by trying to implement the above changes "text changing instead of pop ups" the code now does not return again or exits. it will exit after blank field, and will no longer continue after incorrect name error.

here is the new code Download

i found some other progressbar code that seems to do folder and file copy. if this is true if implemented i would get a more realistic progress, at this time the details bar does not move for single file copy and the program looks as if frozen. I think this code also has true full progress code in it that would move per file instead of per checkbox. i tried to implement the below code as you did with the last but with no success.

Code:

;===Needed======================================================================
#include<String.au3>
#include<Misc.au3>
Global $strFiles = '', $strSize = 0
;===============================================================================


;===Example 1 (create the file "!copydata.mfc" in the source directory)=========
Global $sSourcePath = 'C:\Programme\AutoIt3\Examples\'

Global $aReturn = _MultiFileCopy($sSourcePath)

MsgBox(0, 'MFC', '"!copydata.mfc" has been created!')
;===============================================================================


;===Example 2 (complete list copy )=============================================
; Are all files and subdirectories (recursively) copy
; Directory structure of the source is assumed
Global $sSourcePath = 'C:\Programme\AutoIt3\Examples\'
Global $sDestinationPath = @ScriptDir & '\Tmp1'; Target path (may be created)

Global $aReturn = _MultiFileCopy($sSourcePath, $sDestinationPath, False)
;===============================================================================


;===Example 3 (copy multiple files )============================================
; All files from the array are copied into the target directory
; Array[0], the number of files to copy contained
Global $aSource[4] = [3, @SystemDir & '\shell32.dll', @SystemDir & '\mspaint.exe', @SystemDir & '\eula.txt']
Global $sDestinationPath = @ScriptDir & '\Tmp2'; Target path (may be created)

Global $aReturn = _MultiFileCopy($aSource, $sDestinationPath, False)
;===============================================================================



;===============================================================================
; Function Name:  _MultiFileCopy
; Description::    Copies multiple files with progressbar
; Parameter(s):    Array of files to copy or source path,
;                  Target path,
;                  overwrite? [True/False],
;                  If overwrite = True, prefix to overwrite
; Return Value(s): Array containing the copied files
; Requirement(s):  Global $strFiles = '', $strSize = 0
;                  #include<String.au3>
;                  #include<Misc.au3>
; Author(s):      Tom99, progandy, eukalyptus and Oscar (www.autoit.de)
;===============================================================================
Func _MultiFileCopy($aSource, $sDestPath = '', $bOverWrite = True, $sPreFix = '!Copy')
    Local $oldGUICloseOnESC = Opt('GUICloseOnESC', 0)
    Local $ret, $sShowSource, $sShowDest, $sSourcePath = '', $sNewFolder = '', $k
    Local $aMFC[12] = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, False, DllOpen('user32.dll')]
    If IsArray($aSource) Then
        If Not IsNumber($aSource[0]) Then Return SetError(1, 0, 0)
        For $i = 1 To $aSource[0]
            $aMFC[7] += FileGetSize($aSource[$i])
        Next
    Else
        $sSourcePath = $aSource
        If StringRight($sSourcePath, 1) <> '\' Then $sSourcePath &= '\'
        $strSize = 0
        ToolTip('Please wait! Directory will be read!', @DesktopWidth / 2 - 100, 10)
        If FileExists($sSourcePath & '!copydata.mfc') And $sDestPath <> '' Then
            Local $sFile = StringTrimRight(FileRead($sSourcePath & '!copydata.mfc'), 2)
            $strSize = StringLeft($sFile, StringInStr($sFile, @CRLF) - 1)
            $aSource = StringSplit(StringTrimLeft($sFile, StringInStr($sFile, @CRLF) + 1), @CRLF, 1)
        Else
            If FileExists($sSourcePath & '!copydata.mfc') Then FileDelete($sSourcePath & '!copydata.mfc')
            $aSource = _GetFilesFolder_Rekursiv($sSourcePath)
            Local $hFile = FileOpen($sSourcePath & '!copydata.mfc', 2)
            If $hFile <> -1 Then
                FileWriteLine($hFile, $strSize)
                For $i = 1 To $aSource[0]
                    FileWriteLine($hFile, $aSource[$i])
                Next
                FileClose($hFile)
            EndIf
        EndIf
        $aMFC[7] = $strSize
        ToolTip('')
        If $sDestPath = '' Then Return SetError(0, 0, 1)
    EndIf
    If StringRight($sDestPath, 1) <> '\' Then $sDestPath &= '\'
    If Not FileExists($sDestPath) Then
        If Not DirCreate($sDestPath) Then Return SetError(2, 0, 0)
    EndIf
    $sShowDest = StringRegExpReplace($sDestPath, '(.{15})(.*)(.{35})', '$1' & '[...]' & '$3')
    Local $aReturn = $aSource
    Local $callback = DllCallbackRegister('__Progress', 'int', 'uint64;uint64;uint64;uint64;dword;dword;ptr;ptr;str')
    Local $ptr = DllCallbackGetPtr($callback)
    Local $DllKernel32 = DllOpen('kernel32.dll')
    __ProgressCreate($aMFC)
    $aMFC[9] = TimerInit()
    For $i = 1 To $aSource[0]
        $sArray = ''
        For $j = 0 To 11
            $sArray &= $aMFC[$j] & ';'
        Next
        $sFile = StringMid($aSource[$i], StringInStr($aSource[$i], '\', 0, -1) + 1)
        If $sSourcePath <> '' Then
            $sNewFolder = StringTrimLeft(StringLeft($aSource[$i], StringInStr($aSource[$i], '\', 0, -1)), StringLen($sSourcePath))
            If Not FileExists($sDestPath & $sNewFolder) Then
                If Not DirCreate($sDestPath & $sNewFolder) Then Return SetError(3, 0, 0)
            EndIf
        EndIf
        If $sFile = '' Then ContinueLoop
        $k = 0
        While $bOverWrite = False And FileExists($sDestPath & $sNewFolder & $sFile)
            $k += 1
            $sFile = $sPreFix & $k & "_" & StringMid($aSource[$i], StringInStr($aSource[$i], '\', 0, -1) + 1)
        WEnd
        $aReturn[$i] = $sDestPath & $sNewFolder & $sFile
        $sShowSource = StringRegExpReplace($aSource[$i], '(.{15})(.*)(.{35})', '$1' & '[...]' & '$3')
        GUICtrlSetData($aMFC[1], 'Kopiere Datei ' & @CRLF & '"' & $sShowSource & '"' & @CRLF & 'nach: "' & $sShowDest & '"')
        $ret = DllCall($DllKernel32, 'int', 'CopyFileExA', 'str', $aSource[$i], 'str', $aReturn[$i], 'ptr', $ptr, 'str', $sArray, 'int', 0, 'int', 0)
;~      ConsoleWrite('Return: ' & $ret[0] & @LF)
        If $ret[0] = 0 Then $aMFC[10] = True
        $aMFC[8] += FileGetSize($aSource[$i])
    Next
    DllClose($DllKernel32)
    DllCallbackFree($callback)
    GUIDelete($aMFC[0])
    DllClose($aMFC[11])
    Opt('GUICloseOnESC', $oldGUICloseOnESC)
    Return $aReturn
EndFunc  ;==>_MultiFileCopy

Func __Progress($FileSize, $BytesTransferred, $StreamSize, $StreamBytesTransferred, $dwStreamNumber, $dwCallbackReason, $hSourceFile, $hDestinationFile, $lpData)
    Local $aSplit = StringSplit(StringTrimRight($lpData, 1), ";")
    If $aSplit[11] = 'True' Then Return 1
    Local $pos = GUIGetCursorInfo($aSplit[1])
    If _IsPressed('1B', Int($aSplit[12])) Then Return 1
    If _IsPressed('01', Int($aSplit[12])) And ($pos[4] = Int($aSplit[7])) Then Return 1
    Local $sPercent = Round($BytesTransferred / $FileSize * 100, 0), $iTime, $iTotalTime, $iTransferRate
    Local $sPercentAll = Round(($aSplit[9] + $BytesTransferred) / $aSplit[8] * 100, 0)
    $iTime = TimerDiff($aSplit[10])
    $iTotalTime = Ceiling($iTime / 1000 / ($sPercentAll + 0.1) * 100)
    $iTransferRate = _StringAddThousandsSep(Int($aSplit[8] / $iTotalTime / 1000), '.', ',')
    GUICtrlSetData($aSplit[3], $sPercent & ' %')
    GUICtrlSetData($aSplit[5], $sPercent)
    GUICtrlSetData($aSplit[4], $sPercentAll & ' %    Time: ' & Int($iTime / 1000) & '/' & $iTotalTime & ' s    (' & $iTransferRate & ' KB/s)')
    GUICtrlSetData($aSplit[6], $sPercentAll)
EndFunc  ;==>__Progress

Func __ProgressCreate(ByRef $aMFC)
    If Not IsDeclared('WS_POPUPWINDOW') Then Local Const $WS_POPUPWINDOW = 0x80880000
    If Not IsDeclared('WS_EX_TOPMOST') Then Local Const $WS_EX_TOPMOST = 0x00000008
    If Not IsDeclared('WS_EX_TOOLWINDOW') Then Local Const $WS_EX_TOOLWINDOW = 0x00000080
    If Not IsDeclared('WS_EX_COMPOSITED') Then Local Const $WS_EX_COMPOSITED = 0x02000000
    $aMFC[0] = GUICreate('MultiFileCopy', 480, 220, -1, -1, $WS_POPUPWINDOW, BitOR($WS_EX_TOPMOST, $WS_EX_TOOLWINDOW, $WS_EX_COMPOSITED))
    $aMFC[1] = GUICtrlCreateLabel('', 10, 10, 460, 65)
    GUICtrlSetFont(-1, 10, 400, 0, 'Courier New')
    GUICtrlCreateLabel('File:', 10, 83, 60, 16)
    GUICtrlSetFont(-1, 11, 600, 0, 'Courier New')
    $aMFC[2] = GUICtrlCreateLabel('0 %', 80, 83, 390, 16)
    GUICtrlSetFont(-1, 11, 600, 0, 'Courier New')
    $aMFC[4] = GUICtrlCreateProgress(10, 100, 460, 20)
    GUICtrlCreateLabel('Total:', 10, 133, 60, 16)
    GUICtrlSetFont(-1, 11, 600, 0, 'Courier New')
    $aMFC[3] = GUICtrlCreateLabel('0 %', 80, 133, 390, 16)
    GUICtrlSetFont(-1, 11, 600, 0, 'Courier New')
    $aMFC[5] = GUICtrlCreateProgress(10, 150, 460, 20)
    $aMFC[6] = GUICtrlCreateButton('Cancel', 200, 185, 75, 25)
    GUICtrlSetFont(-1, 9, 400, 0, 'Arial')
    GUISetState()
EndFunc  ;==>__ProgressCreate

;==================================================================================================
; Function Name:  _GetFilesFolder_Rekursiv($sPath [, $sExt='*' [, $iDir=-1 [, $iRetType=0 ,[$sDelim='0']]]])
; Description:    Recursive list of files and / or folders
;                  Adaptation: directory size determined for _MultiFileCopy ($strSize)
; Parameter(s):    $sPath    the base path for the listing ('.' -current path, '..' -Parent path)
;                  $sExt      Extension to file selector '*' or -1 for all (default)
;                  $iDir      -1 Files folder (default), 0 only files, 1 folders only
;      optional:  $iRetType  0 returns Array, 1 returns String
;      optional:  $sDelim    specifies the separator for String Return
;                            0 -@CRLF (Default)  1 -@CR  2 -@LF  3 -';'  4 -'|'
; Return Value(s): Array (Default) od string with the found paths of files and / or folders
;                  Array[0] contains the number of files / folders
; Author(s):      BugFix (bugfix@autoit.de)
;==================================================================================================
Func _GetFilesFolder_Rekursiv($sPath, $sExt='*', $iDir=-1, $iRetType=0, $sDelim='0')
    Global $oFSO = ObjCreate('Scripting.FileSystemObject')
    Global $strFiles = ''
    Switch $sDelim
        Case '1'
            $sDelim = @CR
        Case '2'
            $sDelim = @LF
        Case '3'
            $sDelim = ';'
        Case '4'
            $sDelim = '|'
        Case Else
            $sDelim = @CRLF
    EndSwitch
    If ($iRetType < 0) Or ($iRetType > 1) Then $iRetType = 0
    If $sExt = -1 Then $sExt = '*'
    If ($iDir < -1) Or ($iDir > 1) Then $iDir = -1
    _ShowSubFolders($oFSO.GetFolder($sPath),$sExt,$iDir,$sDelim)
    If $iRetType = 0 Then
        Local $aOut
        $aOut = StringSplit(StringTrimRight($strFiles, StringLen($sDelim)), $sDelim, 1)
        If $aOut[1] = '' Then
            ReDim $aOut[1]
            $aOut[0] = 0
        EndIf
        Return $aOut
    Else
        Return StringTrimRight($strFiles, StringLen($sDelim))
    EndIf
EndFunc

Func _ShowSubFolders($Folder, $Ext='*', $Dir=-1, $Delim=@CRLF)
    If Not IsDeclared("strFiles") Then Global $strFiles = ''
    If ($Dir = -1) Or ($Dir = 0) Then
        For $file In $Folder.Files
            If $Ext <> '*' Then
                If StringRight($file.Name, StringLen($Ext)) = $Ext Then
                    $strSize += $file.size
                    $strFiles &= $file.Path & $Delim
                EndIf
            Else
                $strSize += $file.size
                $strFiles &= $file.Path & $Delim
            EndIf
        Next
    EndIf
    For $Subfolder In $Folder.SubFolders
        If ($Dir = -1) Or ($Dir = 1) Then $strFiles &= $Subfolder.Path & '\' & $Delim
        _ShowSubFolders($Subfolder, $Ext, $Dir, $Delim)
    Next
EndFunc


thanks again for everything P5ych0Gigabyte
d@ve

surreal

Posts: 11
Join date: 2009-10-26
Location: Denver, Colorado

View user profile

Back to top Go down

Re: migration backup tool with autoit

Post  P5ych0Gigabyte on Thu Oct 29, 2009 4:07 pm

I'm not sure about implmenting the progress function you provided but I'll take a detailed look at it a litle later. I however have fixed some bugs in your code and made it so the label is only create once and then updated. Download

P5ych0Gigabyte
Admin

Posts: 27
Join date: 2009-10-21
Location: New Jersey,USA

View user profile http://www.c4free.info

Back to top Go down

Re: migration backup tool with autoit

Post  surreal on Thu Oct 29, 2009 4:16 pm

thanks again, i am going to look over your updates right now.

[UPDATE] 10-29-09 5:45 mnt
for some reason the updated code you provided did not work. it no longer exiting (good thing), but the success ping would not work. i added your changes within my code and now it is working thanks to you pointing me in the right direction. the only thing is that if you connect and the green message displays then it will not return. (incase you want to connect to a different machine name)

example: enter local computername, it connects popup displays and the message shows up in green. then if you connect with a blank or incorrect name nothing happens.

new code ((( Download ))) i added a splash screen, i think i did it right, lol.
i added the splash cause: (sometime it takes a bit to find the system over the network) didnt want someone to think the program was just hanging.

thanks for also looking into the above progressbar code, if it can do what it states this would be a great, great, great, great addition.

the new code creates a log file, c:\program files\emigrate. i just wanted to let you know so that you can delete the file or folder on your system after testing.

i know i have said this time and time again but thank you so much for your help.
d@ve

surreal

Posts: 11
Join date: 2009-10-26
Location: Denver, Colorado

View user profile

Back to top Go down

View previous topic View next topic Back to top


Permissions of this forum:
You cannot reply to topics in this forum