#Region ;**** Directives created by AutoIt3Wrapper_GUI **** #AutoIt3Wrapper_outfile=Backup.exe #AutoIt3Wrapper_Compression=4 #EndRegion ;**** Directives created by AutoIt3Wrapper_GUI **** #Region #### AutoIt Includes #### #include #include #include #include #include #include #include #include #include #include #include #include #EndRegion #### AutoIt Includes #### #Region ### Globals #### ; set the constant values for the array elements Global Enum _ $e_MAINGUI, _ $e_BACKUPDESTINATIONLBL, _ $e_INCLUDEMORELBL, _ $e_OUTLOOKCHATCHK, _ $e_EDITBOX, _ $e_COMPRESSBACKUPCHK, _ $e_BACKUPBTN, _ $e_ARRAYMAX ; create a global array for the controls Global $aid_Controls[$e_ARRAYMAX] Global $bln_FlashBalloon = True #EndRegion ### Globals #### Draw_GUI() ; draw the gui ; check if any file transfers were interrupted If CheckPendingCopy() Then Local $i_CopyData = MsgBox($MB_YESNOCANCEL, 'Alert', _ 'A previous copy seems pending or was interupted ' & @CRLF & _ 'Select Yes to resume copying, No to restart or Cancel to skip') Switch $i_CopyData Case $IDYES ; continue copy FileCopy_ProcessPending(True) Case $IDNO ; skip copy FileCopy_ProcessPending(False) Case $IDCANCEL ; maybe delete ini sections so box not shown next time EndSwitch EndIf GUISetState() ; show the main gui While 1 Sleep(10) WEnd Func BrowseForDestination() Local $s_Destination = FileSelectFolder('Select backup destination', '', $FSF_CREATEBUTTON + $FSF_NEWDIALOG + $FSF_EDITCONTROL) If @error Then ; user cancelled ; disable the backup button if no destination is selected If GUICtrlRead($aid_Controls[$e_BACKUPDESTINATIONLBL]) = '' Then GUICtrlSetState($aid_Controls[$e_BACKUPBTN], $GUI_DISABLE) Return EndIf ; enable the backup button GUICtrlSetState($aid_Controls[$e_BACKUPBTN], $GUI_ENABLE) ; update the label GUICtrlSetData($aid_Controls[$e_BACKUPDESTINATIONLBL], $s_Destination) ; get the type of destination drive selected Local $s_DrvType = DriveGetType($s_Destination) ; set a default message for the edit box Local $s_Message = 'The Drive you selected is Local.' & @CRLF & _ 'Please make sure you have plenty of space before proceeding with Backup' ; change message based on drive selection If $s_DrvType = 'Removable' Then $s_Message = 'The Drive you selected is an External one.' & @CRLF & _ ' This is against AON policy to copy data to external drives,' & @CRLF & _ ' tool will not be held responsible for not adhering AON policies' & @CRLF ElseIf $s_DrvType = 'Network' Then $s_Message = 'The Drive you selected is on Network.' & @CRLF & _ 'Please make sure you have plenty of space before proceeding with Backup' EndIf ; update the edit control GUICtrlSetData($aid_Controls[$e_EDITBOX], ' ') GUICtrlSetData($aid_Controls[$e_EDITBOX], $s_Message, 1) EndFunc ;==>BrowseForDestination Func BrowseForMore() GUICtrlSetData($aid_Controls[$e_INCLUDEMORELBL], FileSelectFolder('Select folders to backup', '', $FSF_CREATEBUTTON + $FSF_NEWDIALOG + $FSF_EDITCONTROL)) EndFunc ;==>BrowseForMore Func CheckPendingCopy() Local $bln_IsCopyPending = False ; Check if any key exists in any section of ini File Local $as_PendingKeyList = IniReadSectionNames(INI_ReturnFilePath()) If Not @error Then ; array of section names returned For $s_CurrSection In $as_PendingKeyList If UBound(IniReadSection(INI_ReturnFilePath(), $s_CurrSection)) > 0 And $s_CurrSection <> 'Destination' Then $bln_IsCopyPending = True ExitLoop EndIf Next EndIf Return $bln_IsCopyPending EndFunc ;==>CheckPendingCopy Func Draw_GUI() Opt('GUIOnEventMode', 1) $aid_Controls[$e_MAINGUI] = GUICreate('Backup', 627, 384) GUISetOnEvent($GUI_EVENT_CLOSE, 'Program_Exit') ; set the font properties for the text Local $i_FontSize = 11 Local $i_FontWeight = 400 Local $s_FontName = 'Lucida Console' #Region #### Backup controls #### GUICtrlCreateLabel('Backup Destination:', 4, 12, 175, 19, BitOR($SS_CENTER, $SS_CENTERIMAGE)) GUICtrlSetFont(-1, $i_FontSize, $i_FontWeight, $GUI_FONTNORMAL, $s_FontName) $aid_Controls[$e_BACKUPDESTINATIONLBL] = GUICtrlCreateLabel('', 175, 11, 353, 21, BitOR($SS_SUNKEN, $DT_END_ELLIPSIS), $WS_EX_STATICEDGE) GUICtrlSetFont(-1, $i_FontSize, $i_FontWeight, $GUI_FONTNORMAL, $s_FontName) GUICtrlSetBkColor(-1, $COLOR_WHITE) GUICtrlCreateButton('Browse', 540, 10, 75, 25) GUICtrlSetFont(-1, $i_FontSize, $i_FontWeight, 0, $s_FontName) GUICtrlSetOnEvent(-1, 'BrowseForDestination') #EndRegion #### Backup controls #### #Region #### Include More controls #### GUICtrlCreateLabel('Include More :', 14, 51, 130, 19) GUICtrlSetFont(-1, $i_FontSize, $i_FontWeight, $GUI_FONTNORMAL, $s_FontName) $aid_Controls[$e_INCLUDEMORELBL] = GUICtrlCreateLabel('', 175, 48, 353, 21, BitOR($SS_SUNKEN, $DT_END_ELLIPSIS), $WS_EX_STATICEDGE) GUICtrlSetFont(-1, $i_FontSize, $i_FontWeight, $GUI_FONTNORMAL, $s_FontName) GUICtrlSetBkColor(-1, $COLOR_WHITE) GUICtrlCreateButton('Browse', 540, 48, 75, 25) GUICtrlSetFont(-1, $i_FontSize, $i_FontWeight, $GUI_FONTNORMAL, $s_FontName) GUICtrlSetOnEvent(-1, 'BrowseForMore') #EndRegion #### Include More controls #### $aid_Controls[$e_OUTLOOKCHATCHK] = GUICtrlCreateCheckbox('Include Outlook mailbox and Lync chat', 16, 128, 445, 17) GUICtrlSetFont(-1, $i_FontSize, $i_FontWeight, $GUI_FONTNORMAL, $s_FontName) $aid_Controls[$e_EDITBOX] = GUICtrlCreateEdit('', 4, 160, 613, 185) GUICtrlSetFont(-1, $i_FontSize, $i_FontWeight, $GUI_FONTNORMAL, $s_FontName) GUICtrlSetColor(-1, 0x00FF00) GUICtrlSetBkColor(-1, $COLOR_BLACK) $aid_Controls[$e_BACKUPBTN] = GUICtrlCreateButton('Backup', 454, 352, 75, 25) GUICtrlSetFont(-1, $i_FontSize, $i_FontWeight, $GUI_FONTNORMAL, $s_FontName) GUICtrlSetState(-1, $GUI_DISABLE) GUICtrlSetOnEvent(-1, 'BackupFiles') GUICtrlCreateButton('Exit', 536, 352, 75, 25) GUICtrlSetFont(-1, $i_FontSize, $i_FontWeight, $GUI_FONTNORMAL, $s_FontName) GUICtrlSetOnEvent(-1, 'Program_Exit') $aid_Controls[$e_COMPRESSBACKUPCHK] = GUICtrlCreateCheckbox('Compress Backup', 16, 356, 157, 17) GUICtrlSetFont(-1, $i_FontSize, $i_FontWeight, $GUI_FONTNORMAL, $s_FontName) GUICtrlSetTip(-1, 'Use to compress data') EndFunc ;==>Draw_GUI Func FileCopy_List($s_SectionName, $as_FileList, $s_SourceDir) Local $i_Errors = 0 ; Set an error counter for file copy errors Local $s_Destination = GUICtrlRead($aid_Controls[$e_BACKUPDESTINATIONLBL]) & '\' & $s_SectionName ; get the user selected destination and add the user folder For $i = 1 To $as_FileList[0] ; if a file is doesn't exist, then it will still be in the ini file and everytime ; the program starts it will think a copy operation is pending. So remove from the ini section If Not FileExists($as_FileList[$i]) Then IniDelete(INI_ReturnFilePath(), $s_SectionName, $as_FileList[$i]) ElseIf Not FileCopy($as_FileList[$i], StringReplace($as_FileList[$i], $s_SourceDir, $s_Destination), $FC_OVERWRITE + $FC_CREATEPATH) Then $i_Errors += 1 Else ; if you only delete the files successfully copied, you then have a record of those that weren't ; and could do something with that IniDelete(INI_ReturnFilePath(), $s_SectionName, $as_FileList[$i]) EndIf Next ; when the function returns you can check for @error it will tell you how many files failed to copy Return SetError($i_Errors) EndFunc ;==>FileCopy_List Func FileCopy_Desktop($bln_CopyPending) Local $s_FolderPath = @DesktopDir Local $as_FileList = 0 _FileWriteLog('.\Backup.log', $s_FolderPath & ' ..............Started ') ; only scan for files if $bln_CopyPending = false. ; ProcessCurrentFolderCopy ignores the passed list and creates one from ; the ini if $bln_CopyPending = True. Pointless scanning If Not $bln_CopyPending Then ; return files and their full path (Do you want to copy empty folders?) $as_FileList = _FileListToArrayRec($s_FolderPath, '*', $FLTAR_FILES, $FLTAR_RECUR, $FLTAR_SORT, $FLTAR_FULLPATH) ; check for errors, an array won't be returned so further processing will fail If @error Then Return SetError(@error, @extended, 0) EndIf ; update the edit control GUICtrlSetData($aid_Controls[$e_EDITBOX], '', ' ') GUICtrlSetData($aid_Controls[$e_EDITBOX], @CRLF & 'Backing Up Current Users Desktop' & @CRLF, ' ') ProcessCurrentFolderCopy($bln_CopyPending, $as_FileList, 'Desktop', $s_FolderPath) ; check for errors with the copy process If @error Then Return SetError(1) _FileWriteLog('.\Backup.log', $s_FolderPath & ' ..............Completed ') GUICtrlSetData($aid_Controls[$e_EDITBOX], '', ' ') GUICtrlSetData($aid_Controls[$e_EDITBOX], '---> Desktop backup Complete' & @CRLF, ' ') EndFunc ;==>FileCopy_Desktop Func FileCopy_Favorites($bln_CopyPending) Local $s_FolderPath = @UserProfileDir & '\Favorites' Local $as_FileList = 0 _FileWriteLog('.\Backup.log', $s_FolderPath & ' ..............Started ') ; only scan for files if $bln_CopyPending = false. ; ProcessCurrentFolderCopy ignores the passed list and creates one from ; the ini if $bln_CopyPending = True. Pointless scanning If Not $bln_CopyPending Then ; return files and their full path (Do you want to copy empty folders?) $as_FileList = _FileListToArrayRec($s_FolderPath, '*', $FLTAR_FILES, $FLTAR_RECUR, $FLTAR_SORT, $FLTAR_FULLPATH) ; check for errors, an array won't be returned so further processing will fail If @error Then Return SetError(@error, @extended, 0) EndIf GUICtrlSetData($aid_Controls[$e_EDITBOX], '', ' ') GUICtrlSetData($aid_Controls[$e_EDITBOX], @CRLF & 'Backing Up Current Users IE Favorites' & @CRLF, ' ') ProcessCurrentFolderCopy($bln_CopyPending, $as_FileList, 'Favorites', $s_FolderPath) ; check for errors with the copy process If @error Then Return SetError(1) _FileWriteLog('.\Backup.log', $s_FolderPath & ' ..............Completed ') GUICtrlSetData($aid_Controls[$e_EDITBOX], '', ' ') GUICtrlSetData($aid_Controls[$e_EDITBOX], '---> Favorites backup Complete' & @CRLF, ' ') EndFunc ;==>FileCopy_Favorites Func FileCopy_Firefox($bln_CopyPending) Local $s_FolderPath = @AppDataDir & '\Mozilla' Local $as_FileList = 0 _FileWriteLog('.\Backup.log', $s_FolderPath & ' ..............Started ') If FileExists($s_FolderPath) = 1 Then ; this seems to work but may need to put a loop to run until all processes are closed If ProcessExists('firefox.exe') Then ProcessClose('firefox.exe') EndIf ; only scan for files if $bln_CopyPending = false. ; ProcessCurrentFolderCopy ignores the passed list and creates one from ; the ini if $bln_CopyPending = True. Pointless scanning If Not $bln_CopyPending Then ; return files and their full path (Do you want to copy empty folders?) $as_FileList = _FileListToArrayRec($s_FolderPath, '*', $FLTAR_FILES, $FLTAR_RECUR, $FLTAR_SORT, $FLTAR_FULLPATH) ; check for errors, an array won't be returned so further processing will fail If @error Then Return SetError(@error, @extended, 0) EndIf GUICtrlSetData($aid_Controls[$e_EDITBOX], '') GUICtrlSetData($aid_Controls[$e_EDITBOX], @CRLF & 'Backing Up Firefox Profile' & @CRLF, ' ') ProcessCurrentFolderCopy($bln_CopyPending, $as_FileList, 'Firefox', $s_FolderPath) ; check for errors with the copy process If @error Then Return SetError(1) _FileWriteLog('.\Backup.log', $s_FolderPath & ' ..............Completed ') GUICtrlSetData($aid_Controls[$e_EDITBOX], '', ' ') GUICtrlSetData($aid_Controls[$e_EDITBOX], '---> Firefox backup Complete' & @CRLF, ' ') EndIf $bln_FlashBalloon = True EndFunc ;==>FileCopy_Firefox Func FileCopy_ProcessPending($bln_IfContinuePendingCopy) ; read the last backup path from the ini Local $s_Destination = IniRead(INI_ReturnFilePath(), 'Destination', 'Path', '') ; no path in the ini #### could set @error so something to check for on return #### If $s_Destination = '' Then Return ; update the control if the gui has been created If $aid_Controls[$e_BACKUPDESTINATIONLBL] Then GUICtrlSetData($aid_Controls[$e_BACKUPDESTINATIONLBL], $s_Destination) FileCopy_Desktop($bln_IfContinuePendingCopy) FileCopy_Favorites($bln_IfContinuePendingCopy) FileCopy_Firefox($bln_IfContinuePendingCopy) ;~ MyDocuments($bln_IfContinuePendingCopy) EndFunc ;==>FileCopy_ProcessPending Func INI_ReturnFilePath() ; return the ini path Return @ScriptDir & '\CurrentDir.ini' EndFunc ;==>INI_ReturnFilePath Func INI_UpdateSection($s_SectionName, $as_FileList) IniDelete(INI_ReturnFilePath(), $s_SectionName) ; loop through the file list adding to the correct section For $i_FileCount = 1 To $as_FileList[0] IniWrite(INI_ReturnFilePath(), $s_SectionName, $as_FileList[$i_FileCount], $i_FileCount) Next ;~ FileClose(INI_ReturnFilePath()) EndFunc ;==>INI_UpdateSection Func ProcessCurrentFolderCopy($bln_IfCopyPending, $as_FileList, $s_CurrentFolderName, $s_SourceDir) ; check for pending file copy If $bln_IfCopyPending Then ; get a list of files that await copying (Returns a 2D array $as_FileList = IniReadSection(INI_ReturnFilePath(), $s_CurrentFolderName) ; check an array was returned If Not IsArray($as_FileList) Then Return SetError(1) ; convert to a 1D array by deleting the column that has the values _ArrayColDelete($as_FileList, 1, True) Else INI_UpdateSection($s_CurrentFolderName, $as_FileList) EndIf ; copy the file listed in the array FileCopy_List($s_CurrentFolderName, $as_FileList, $s_SourceDir) If @error Then MsgBox(0, 'error', @error) EndFunc ;==>ProcessCurrentFolderCopy Func Program_Exit() GUIDelete() Exit EndFunc ;==>Program_Exit Func BackupFiles() ; write the user selection to the ini IniWrite(INI_ReturnFilePath(), 'Destination', 'Path', GUICtrlRead($aid_Controls[$e_BACKUPDESTINATIONLBL])) ;~ _MyDocuments(False) FileCopy_Firefox(False) If @error Then MsgBox($MB_ICONERROR, 'File Copy', 'Errors occured copying the users Firefox profile') FileCopy_Desktop(False) If @error Then MsgBox($MB_ICONERROR, 'File Copy', 'Errors occured copying the users Desktop files') FileCopy_Favorites(False) If @error Then MsgBox($MB_ICONERROR, 'File Copy', 'Errors occured copying the users Favorites files') ;~ _MsOutlook() ;~ _BackupSelection() ; Must Always Be Last ------------------------------------ ;~ If GUICtrlRead($aid_Controls[$e_COMPRESSBACKUPCHK]) = $GUI_CHECKED Then Compress() ;~ If GUICtrlRead($aid_Controls[$e_OUTLOOKCHATCHK]) = $GUI_CHECKED Then MsOutlook() If Not $bln_FlashBalloon Then TrayTip('Backup Completed', 'Your Backup is completed', 10) EndFunc ;==>BackupFiles