#Region ;**** Directives created by AutoIt3Wrapper_GUI **** #AutoIt3Wrapper_icon=C:\windows\TinyBackupBox.ico #AutoIt3Wrapper_outfile=TinyBackupBox.exe #AutoIt3Wrapper_Compression=4 #AutoIt3Wrapper_Res_Comment=Tested on Xp sp3 32 bit #AutoIt3Wrapper_Res_Description=Do a backup of a folders list. #AutoIt3Wrapper_Res_Fileversion=1.0.3.2 #AutoIt3Wrapper_Res_Fileversion_AutoIncrement=P #AutoIt3Wrapper_Res_LegalCopyright=Copyright © wakillon 2010 - 2011 #AutoIt3Wrapper_Res_Language=1036 #AutoIt3Wrapper_Res_Field=AutoIt Version|%AutoItVer% #AutoIt3Wrapper_Res_Field=Compile date|%longdate% %time% #EndRegion ;**** Directives created by AutoIt3Wrapper_GUI **** #Region ;************ Includes ************ #include #Include #Include ;~ #Include ;~~~ #Include #include #include #include #Include #EndRegion ;************ Includes ************ If Not _Singleton ( @ScriptName, 1 ) Then Exit OnAutoItExitRegister ( '_OnAutoItExit' ) Opt ( 'TrayMenuMode', 1 ) Opt ( 'TrayOnEventMode', 1 ) Opt ( 'GUICloseOnESC', 0 ) Global Const $STM_SETIMAGE = 0x0172 Global $_Version = _GetScriptVersion (), $_TempDir = @TempDir & '\TBB' Global $_RegKeySettings = 'HKEY_CURRENT_USER\Software\TinyBackupBox' Global $_Pid, $_SrcDirSize, $_DestDirPath2, $TV1, $TV2, $_Item, $_Path, $_Select1, $_Select2 Global $_PidArray[1], $_SelectedTv1ItemsArray[1], $_CheckedTv1ItemsArray[1], $_CheckedTv1PathsArray[1] Global $_Backup, $_Paused, $_Cancel, $_Finish=1, $_ProcessExisted, $_Msg, $_MsgArray, $_IdleMode, $_ShowFlag Global $_BitmapHandle1, $_BitmapHandle2, $_BitmapHandle3, $_RoboCopyWinHandle Global $_Gui, $_StartButton, $_RefreshButton, $_ProgressBar1, $_Label1, $_Label2 Global $_ProgressBar2, $_ProgressLabel1, $_ProgressLabel2, $_ProgressLabel1Handle Global $_Dummy, $_Context, $_Menu, $_ButtonMenu, $_Invert, $_Step, $_StepOld, $_Ubound, $_LogFilePath Global $_AboutGui, $_AboutGuiWidth = 450, $_AboutGuiHeight = 370, $_AboutLabel1, $_AboutLabel2 Global $_Pic, $_FontSize, $_BassModDll, $_VolumeStep, $_Volume, $_VolumeOld Global $_TitleItem, $_MinimizeItem, $_BackupDirItem, $_OverWriteItem, $_AboutItem Global $_PreservAttribsItem, $_ShowConsoleItem, $_MuteSoundsItem, $_IdleTimeItem, $_PurgeItem, $_ExitItem Global $_OverWrite, $_ShowConsole, $_IdleTimeDelay, $_Purge, $_PreservAttribs, $_MuteSounds, $_MuteSoundsOld Global $_Timer1 = _NowCalc (), $_Timer2 = _NowCalc (), $_Timer3 = _NowCalc () _FileInstall () _TrayMenu () _Gui () While 1 #Region Gui Management. Switch _GUICtrlTVExplorer_GetMsg () Case $GUI_EVENT_CLOSE _Exit () Case $GUI_EVENT_MINIMIZE TrayItemSetText ( $_MinimizeItem, 'Restore Window' ) Case $GUI_EVENT_RESTORE TrayItemSetText ( $_MinimizeItem, 'Minimize' ) Case $_ButtonMenu $_InputBox = InputBox ( 'Create a New Sub Folder', 'Enter a folder Name', 'Backup ' & _ @YEAR & '-' & @MON & '-' & @MDAY & ' ' & @HOUR & @MIN & @SEC , Default, 300, 130 ) If $_InputBox And Not FileExists ( $_Path & '\' & $_InputBox ) Then $_DirCreate = DirCreate ( $_Path & '\' & $_InputBox ) If $_DirCreate Then $_MuteSoundsOld = $_MuteSounds $_MuteSounds = 1 $_IsExpanded = _GUICtrlTreeView_GetExpanded ( $TV2, $_Item ) If $_IsExpanded Then $_Image = _TV_AddIcon ( 0, $_Path ) $_NewItem = '0x' & Hex ( _GUICtrlTreeView_InsertItem ( $TV2, $_InputBox, $_Item, $TVI_SORT, $_Image, $_Image ) ) _GUICtrlTreeView_ClickItem ( $TV2, $_NewItem ) Else _GUICtrlTVExplorer_Expand ( $TV2, $_Path ) ; search new item by text and select it. Local $_SearchItem = 0 $_FirstItem = _GUICtrlTreeView_GetFirstChild ( $TV2, $_Item ) If _GUICtrlTreeView_GetText ( $TV2, $_FirstItem ) = $_InputBox Then $_SearchItem = $_FirstItem Else $_StartItem = $_FirstItem Do $_NextItem = _GUICtrlTreeView_GetNextChild ( $TV2, $_StartItem ) If _GUICtrlTreeView_GetText ( $TV2, $_NextItem ) = $_InputBox Then $_SearchItem = $_NextItem ExitLoop EndIf If $_NextItem Then $_StartItem = $_NextItem Until Not $_NextItem EndIf If Not $_SearchItem Then $_Image = _TV_AddIcon ( 0, $_Path ) $_NewItem = '0x' & Hex ( _GUICtrlTreeView_InsertItem ( $TV2, $_InputBox, $_Item, $TVI_SORT, $_Image, $_Image ) ) _GUICtrlTreeView_ClickItem ( $TV2, $_NewItem ) Else _GUICtrlTreeView_ClickItem ( $TV2, $_SearchItem ) EndIf EndIf $_MuteSounds = $_MuteSoundsOld Else MsgBox ( 262144+4112, 'Error', "This Folder can't be created !", 5 ) EndIf Else If $_InputBox Then MsgBox ( 262144+4112, 'Error', 'This Folder already exists !', 5 ) Else MsgBox ( 262144+4112, 'Error', "This Folder can't be created !", 5 ) EndIf EndIf Case $_StartButton If Not $_Backup Then ; startbutton backup. _SimulPressButton ( $_StartButton, 40, 20, 640, 35 ) If _IsPressed ( '10' ) Then ; 10, Hold Left SHIFT key when clicking Start button for enable Idle Mode. If $_IdleMode Then _CancelBackup () $_IdleMode = 0 WinSetTitle ( $_Gui, '', $_Version ) ContinueLoop Else $_IdleMode = 1 EndIf EndIf If Not $_Paused Then $_LogFilePath = $_TempDir & '\TinyBackupBox_' & @YEAR & '-' & @MON & '-' & @MDAY & '_' & @HOUR & @MIN & @SEC & '.log' $_Paused = 0 $_Cancel = 0 $_BackupDirpath = $_Select2 $_BackupDirName = _WinAPI_PathStripPath ( $_BackupDirPath ) ; check backup directory. If Not FileExists ( $_BackupDirPath ) Then $_IdleMode = 0 WinSetTitle ( $_Gui, '', $_Version ) MsgBox ( 262144+4160, '', 'Please Select an Existing Backup Directory', 5 ) ContinueLoop ElseIf StringInStr ( $_BackupDirPath, 'recycle' ) Or $_BackupDirName = 'windows' Or $_BackupDirName = 'System Volume Information' Then $_IdleMode = 0 WinSetTitle ( $_Gui, '', $_Version ) MsgBox ( 262144+4160, '', 'Please Select Another Backup Directory', 5 ) ContinueLoop EndIf ; get checked items. $_CheckedTv1ItemsArray = _DeleteArrayElementNotChecked ( $TV1, $_SelectedTv1ItemsArray ) _TVUnCheckAllParentItems ( $TV1, $_CheckedTv1ItemsArray ) $_CheckedTv1ItemsArray = _DeleteArrayElementNotChecked ( $TV1, $_CheckedTv1ItemsArray ) $_CheckedTv1ItemsArray = _ArrayUnique ( $_CheckedTv1ItemsArray, 1, 1, 0 ) If Not IsArray ( $_CheckedTv1ItemsArray ) Or UBound ( $_CheckedTv1ItemsArray ) -1 = 0 Then $_IdleMode = 0 WinSetTitle ( $_Gui, '', $_Version ) MsgBox ( 262144+4160, '', 'All CheckBoxes are Unchecked !' & @CRLF & @CRLF & 'Please Select Folders to be Saved', 5 ) ContinueLoop EndIf ; get paths of checked items. For $_I = 1 To UBound ( $_CheckedTv1ItemsArray ) -1 $_PathFromItem = _GUICtrlTVExplorer_GetPathFromItem ( $TV1, $_CheckedTv1ItemsArray[$_I] ) If Not _AlreadyInArray ( $_CheckedTv1PathsArray, $_PathFromItem ) Then _ArrayAdd ( $_CheckedTv1PathsArray, $_PathFromItem ) Next Sleep ( 50 ) GUICtrlSendMsg ( $_StartButton, $STM_SETIMAGE, 0, $_BitmapHandle2 ) If $_IdleMode Then GUICtrlSetTip ( $_StartButton, 'Hold Shift + Click for Cancel Backup in Idle Mode', 'Stop Button', 1, 1 ) Else GUICtrlSetTip ( $_StartButton, 'Click for Pause Backup or' & @CRLF & 'Hold Shift + Click for Cancel Backup', 'Stop Button', 1, 1 ) EndIf ; check drive free space. GUICtrlSetData ( $_ProgressLabel1, 'Please wait while checking drive free space.' ) $_DriveSpaceFree = DriveSpaceFree ( StringLeft ( $_BackupDirPath, 2 ) ) * 10^6 ; bytes ; get needed space. Local $_NeededSpace = 0 For $_Element In $_CheckedTv1PathsArray If FileExists ( $_Element ) Then $_NeededSpace += DirGetSize ( $_Element ) - DirGetSize ( $_BackupDirpath & '\' & _WinAPI_PathStripPath ( $_Element ) ) Next GUICtrlSetData ( $_ProgressLabel1, 'BackupDir Selected : ' & $_Select2 ) If $_DriveSpaceFree < $_NeededSpace Then MsgBox ( 262144+4112, 'Error', 'There is not enough free space on Backup Dir Drive', 0 ) _StopBackup () $_Finish = 1 $_Cancel = 1 ContinueLoop EndIf ; initialize backup If Not $_IdleMode Then $_Backup = 1 $_Step = 0 Else ; StopButton backup _SimulPressButton ( $_StartButton, 40, 20, 640, 35 ) _CloseProcess ( $_Pid ) If _IsPressed ( '10' ) Then ; Cancel backup, 10 , Hold Left SHIFT key when clicking Stop button for totaly Cancel current backup instead of pause. _CancelBackup () Else ; Paused Backup. $_Paused = 1 $_Finish = 0 GUICtrlSetData ( $_ProgressBar1, 100 ) GUICtrlSetTip ( $_StartButton, 'Resume Current Backup', 'Go !', 1, 1 ) EndIf If $_Backup Then _StopBackup () EndIf Case $_RefreshButton ; cancel current backup in any mode. _SimulPressButton ( $_RefreshButton, 40, 545, 640, 35 ) If $_IdleMode Then _StopBackup () GUICtrlSetState ( $_ProgressLabel1, $GUI_HIDE ) $_Finish = 1 $_Cancel = 0 $_Paused = 0 $_IdleMode = 0 $_Msg='' If IsArray ( $_CheckedTv1ItemsArray ) Then ReDim $_CheckedTv1ItemsArray[1] If IsArray ( $_CheckedTv1PathsArray ) Then ReDim $_CheckedTv1PathsArray[1] If IsArray ( $_SelectedTv1ItemsArray ) Then ReDim $_SelectedTv1ItemsArray[1] Local $_Expand = 1 If _IsPressed ( '10' ) Then ; 10, hold Left SHIFT key when clicking Refresh button for expand treeviews to the root instead of last selections. $_Expand = 0 $_Select1 ='' $_Select2 ='' GUICtrlSetData ( $_ProgressLabel1, '' ) EndIf Local $_Select2Old = $_Select2 ; recreate treeviews. _CreateTreeviews () _TVRemoveDrivesCheckboxes ( $TV1 ) $_MuteSoundsOld = $_MuteSounds ; expand to previous selections. If $_Expand Then $_MuteSounds = 1 _GUICtrlTVExplorer_Expand ( $TV1, $_Select1, False ) _GUICtrlTVExplorer_Expand ( $TV2, $_Select2Old, False ) $_MuteSounds = $_MuteSoundsOld EndIf GUICtrlSetState ( $_ProgressLabel1, $GUI_SHOW ) EndSwitch $_NowCalc2 = _NowCalc () If _DateDiff ( "s", $_Timer2, $_NowCalc2 ) >= 1 Then ; 1 sec $_Timer2 = $_NowCalc2 If _IsMinimized ( $_Gui ) Then If TrayItemGetText ( $_MinimizeItem ) <> 'Restore Window' Then TrayItemSetText ( $_MinimizeItem, 'Restore Window' ) Else If TrayItemGetText ( $_MinimizeItem ) <> 'Minimize' Then TrayItemSetText ( $_MinimizeItem, 'Minimize' ) EndIf EndIf #EndRegion Gui Management. #Region Backup Management. If $_Backup Then If Not $_ProcessExisted Then $_Step = $_Step + 1 If $_Step <= UBound ( $_CheckedTv1ItemsArray ) -1 Then $_ItemPath = _GUICtrlTVExplorer_GetPathFromItem ( $TV1, $_CheckedTv1ItemsArray[$_Step] ) $_Msg &= $_ItemPath & @CRLF If $_ItemPath = $_BackupDirPath Then MsgBox ( 262144+4112, 'Error', 'Selected Folder and Backup Dir are Same', 5 ) $_Finish = 1 $_Cancel = 1 _StopBackup () ContinueLoop EndIf GUICtrlSetState ( $_RefreshButton, $GUI_HIDE ) $_Finish = 0 _DirCopyWithProgress ( $_ItemPath, $_BackupDirPath, $_OverWrite ) ; If overwrite checked, then no deletion of previous existing dir. Else GUICtrlSetData ( $_ProgressBar1, 100 ) If Not $_MuteSounds Then SoundPlay ( @WindowsDir & '\Media\done.wav' ) _StopBackup () $_MsgArray = _ArrayUnique ( StringSplit ( $_Msg, @CRLF, 3 ) ) $_Msg = _ArrayToString ( $_MsgArray, @CRLF, 1 ) $_Diff = 0 For $_I = 1 To UBound ( $_CheckedTv1PathsArray ) -1 $_Size1 = DirGetSize ( $_CheckedTv1PathsArray[$_I] ) $_Size2 = DirGetSize ( $_BackupDirPath & '\' & _WinAPI_PathStripPath ( $_CheckedTv1PathsArray[$_I] ) ) If $_Size2 < $_Size1 Then $_Diff = 1 ExitLoop EndIf Next If Not $_Diff Then MsgBox ( 262144+4160, 'Backup Successfull', $_Msg & @CRLF & 'have been saved in :' & @CRLF & @CRLF & $_BackupDirPath, 0 ) Else If $_IdleMode Then ContinueLoop If MsgBox ( 262144+4160+4, 'Backup with errors', $_Msg & @CRLF & 'have been saved in :' & @CRLF & @CRLF & $_BackupDirPath & @CRLF & _ @CRLF & 'Some files were not copied...' & @CRLF & @CRLF & 'Do you want to open Log file ?', 0 ) = 6 Then Run ( 'notepad ' & $_LogFilePath ) EndIf $_Msg='' $_IdleMode = 0 $_Finish = 1 $_StepOld = 0 If IsArray ( $_CheckedTv1ItemsArray ) Then ReDim $_CheckedTv1ItemsArray[1] If IsArray ( $_CheckedTv1PathsArray ) Then ReDim $_CheckedTv1PathsArray[1] WinSetTitle ( $_Gui, '', $_Version ) EndIf EndIf Else Sleep ( 10 ) EndIf #EndRegion Backup Management. #Region Idle Backup Management. If $_IdleMode Then $_NowCalc = _NowCalc () If _DateDiff ( 's', $_Timer1, $_NowCalc ) >= 1 Then ; 1 sec $_Timer1 = $_NowCalc $_Invert = Not $_Invert If $_Invert Then If $_Backup Then WinSetTitle ( $_Gui, '', $_Version & ' - Idle Mode - Copying' ) Else WinSetTitle ( $_Gui, '', $_Version & ' - Idle Mode - Waiting' ) EndIf Else WinSetTitle ( $_Gui, '', $_Version ) EndIf EndIf $_TimerIdleDiff = Int ( _WinAPI_GetIdleTime ()/60000 ) ; min If $_TimerIdleDiff > $_IdleTimeDelay Then $_Backup = 1 $_Paused = 0 $_Cancel = 0 If $_Step Then $_StepOld = $_Step -1 Else $_Backup = 0 _CloseProcess ( $_Pid ) $_Paused = 1 $_Finish = 0 If $_Step Then $_Step = $_StepOld EndIf EndIf #EndRegion Idle Backup Management. #Region Progress Management. If ProcessExists ( $_Pid ) Then $_NowCalc3 = _NowCalc () If _DateDiff ( 's', $_Timer3, $_NowCalc3 ) >= 1 Then ; 1 sec $_Timer3 = $_NowCalc3 Local $_DestDirSize = DirGetSize ( $_DestDirPath2, 1 ) GUICtrlSetData ( $_ProgressBar1, $_Step / $_Ubound *100 ) If $_DestDirSize[0] Then GUICtrlSetData ( $_ProgressBar2, Round ( $_DestDirSize[0] / ( $_SrcDirSize[0]/100 ) ) ) GUICtrlSetData ( $_ProgressLabel2, Round ( $_DestDirSize[0] / ( $_SrcDirSize[0]/100 ) ) & '% - ' & _ Round ( $_DestDirSize[0] / ( 1024 * 1024 ) ) & ' / ' & Round ( $_SrcDirSize[0] / ( 1024 * 1024 ) ) & ' MB copied' & @CRLF & _ $_DestDirSize[1] & ' / ' & $_SrcDirSize[1] & ' Files copied' & ' - ' & _ $_DestDirSize[2] & ' / ' & $_SrcDirSize[2] & ' Folders copied' ) EndIf EndIf $_ProcessExisted = 1 Else If $_ProcessExisted Then GUICtrlSetData ( $_ProgressLabel2, '' ) GUICtrlSetData ( $_ProgressBar2, 0 ) $_ProcessExisted = 0 If Not $_Cancel And Not $_Paused Then _GUICtrlTreeView_SetChecked ( $TV1, $_CheckedTv1ItemsArray[$_Step], False ) ; Uncheck folders already saved. EndIf EndIf #EndRegion Progress Management. WEnd Func _About () _AboutGui () GUISetState ( @SW_HIDE, $_Gui ) Opt ( 'TrayIconHide', 1 ) _Play () GUISetState ( @SW_SHOW, $_AboutGui ) Local $_AboutLabel1YCoord = $_AboutGuiHeight, $_Step2 = 1, $_FontSize=11 While 1 If _IsPressed ( '1B' ) Then ExitLoop ; 1B = ESC key Local $_CursorInfoArray = GUIGetCursorInfo ( $_AboutGui ) If Not @error And $_CursorInfoArray[4] = $_AboutLabel2 And $_CursorInfoArray[2] Then If FileExists ( _GetDefaultBrowser () ) Then ShellExecute ( 'http://www.autoitscript.com/site/donate/' ) Else ShellExecute ( 'iexplore.exe', 'http://www.autoitscript.com/site/donate/' ) EndIf EndIf $_Count = 0 $_AboutLabel1YCoord -= $_Step2 $_AboutLabel1Pos = ControlGetPos ($_AboutGui, '', $_AboutLabel1 ) If $_AboutLabel1Pos[1] > - ( $_AboutGuiHeight-120 ) Then ControlMove ( $_AboutGui, '', $_AboutLabel1, 0, $_AboutLabel1YCoord ) $_AboutLabel2State = GUICtrlGetState ( $_AboutLabel2 ) If $_AboutLabel2State = $GUI_SHOW + $GUI_ENABLE Then $_AboutLabel2Pos = ControlGetPos ( $_AboutGui, '', $_AboutLabel2 ) If $_AboutLabel2Pos[1] > 80 Then ControlMove ( $_AboutGui, '', $_AboutLabel2, 0, $_AboutLabel2Pos[1]-1 ) Else If $_AboutLabel1Pos[1] <= - ( $_AboutGuiHeight-120 ) Then $_FontSize+= 0.5 If $_FontSize > 70 Then $_Volume -= $_VolumeStep If $_Volume >= 0 Then DllCall ( $_BassModDll, 'int', 'BASSMOD_SetVolume', 'int', $_Volume ) $_TransLevel = 255 - ( $_FontSize - 70 ) * 8 If $_TransLevel >= 0 Then WinSetTrans ( $_AboutGui, '', $_TransLevel ) Else ExitLoop EndIf EndIf If $_FontSize < 18 Then If IsInt ( $_FontSize ) Then GUICtrlSetFont ( $_AboutLabel2, $_FontSize ) Else If GUICtrlGetState ( $_Pic ) <> $GUI_SHOW + $GUI_ENABLE Then GUICtrlSetState ( $_Pic, $GUI_SHOW ) EndIf EndIf EndIf EndIf Sleep ( 50 ) If $_AboutLabel1YCoord = 10 Then GUICtrlSetState ( $_AboutLabel2, $GUI_SHOW ) While 1 $_Count+= 1 Sleep ( 40 ) If $_Count = 200 Then ExitLoop WEnd $_AboutLabel1YCoord = 9 EndIf If $_AboutLabel1YCoord = - $_AboutGuiHeight - 10 Then $_AboutLabel1YCoord = $_AboutGuiHeight WEnd GUISetState ( @SW_HIDE, $_AboutGui ) _CloseBassMod () GUIDelete ( $_AboutGui ) GUISetState ( @SW_SHOW, $_Gui ) TrayItemSetState ( $_AboutItem, $TRAY_UNCHECKED ) WinWait ( $_Gui, '', 2 ) WinActivate ( $_Gui ) Opt ( 'TrayIconHide', 0 ) EndFunc ;==> _About () Func _AboutGui () $_AboutGui = GUICreate ( '', $_AboutGuiWidth, $_AboutGuiHeight, -1, -1, $WS_POPUP, $WS_EX_TOPMOST, WinGetHandle ( AutoItWinGetTitle () ) ) GUISetBkColor ( 0x000000 ) $_Pic = GUICtrlCreatePic ( @TempDir & '\About\WakiBlack2.jpg', 185, 270, 80, 80 ) GUICtrlSetState ( -1, $GUI_HIDE ) $_AboutLabel1Txt = $_Version & @CRLF & @CRLF & @CRLF & _ 'Thanks To the Authors of AutoIt ' & @CRLF & _ 'For their free wonderfull scripting language !' & @CRLF & @CRLF & _ 'I would like to thank the following Members for their help : ' & @CRLF & @CRLF & _ 'UEZ - - Melba23 - - Funkey' & @CRLF & _ 'Prog@ndy - - trancexx - - Yashield' & @CRLF & _ 'Siao - - Taietel - - Waithru - - Ward - - BrettF - - wolf9228' & @CRLF & _ 'Jon - - KaFu - - Eukalyptus - - Beege - - Guinness - - rasim' & @CRLF & _ 'Zedna - - enaiman - - Rover - - martin - - Malkey' & @CRLF & _ 'and all others...' & @CRLF & @CRLF $_AboutLabel1 = GUICtrlCreateLabel ( $_AboutLabel1Txt, 0, $_AboutGuiHeight, $_AboutGuiWidth, $_AboutGuiHeight-130, 0x1 ) GUICtrlSetFont ( -1, 11, 900, 1, 'GlobalMonospace' ) GUICtrlSetColor ( -1, 0xD2F630 ) GUICtrlSetBkColor ( -1, $GUI_BKCOLOR_TRANSPARENT ) $_AboutLabel2Txt = 'If you like AutoIt' & @CRLF & _ 'Donate To the AutoIt Team ! ' & @CRLF & @CRLF & _ 'http://www.autoitscript.com/donate.php' & @CRLF & @CRLF & _ 'Copyright © wakillon 2010 - 2011' & @CRLF & @CRLF $_AboutLabel2 = GUICtrlCreateLabel ( $_AboutLabel2Txt, 0, 250, $_AboutGuiWidth, $_AboutGuiHeight-190, 0x1 ) GUICtrlSetFont ( -1, $_FontSize ) GUICtrlSetColor ( -1, 0xFF0000 ) GUICtrlSetCursor ( -1, 0 ) GUICtrlSetState ( -1, $GUI_HIDE ) EndFunc ;==> _AboutGui () Func _Activate () WinActivate ( $_Gui ) EndFunc ;==> _Activate () Func _AlreadyInArray ( $_SearchArray, $Item, $_Start=0, $_Partial=0 ) $_Index = _ArraySearch ( $_SearchArray, $Item, $_Start, 0, 0, $_Partial ) If Not @error Then Return 1 EndFunc ;==> _AlreadyInArray () Func _CancelBackup () ; get folders list copied. $_MsgArray = _ArrayUnique ( StringSplit ( $_Msg, @CRLF, 3 ) ) _ArrayPop ( $_MsgArray ) _ArrayPop ( $_MsgArray ) _ArraySort ( $_MsgArray, 0, 1 ) $_Msg = _ArrayToString ( $_MsgArray, @CRLF, 1 ) If IsArray ( $_CheckedTv1ItemsArray ) Then For $_Element In $_CheckedTv1ItemsArray _GUICtrlTreeView_SetChecked ( $TV1, $_Element, False ) Next EndIf If Not DirRemove ( $_DestDirPath2, 1 ) Then Run ( @ComSpec & ' /C RD /S /Q "' & $_DestDirPath2 & '"', @SystemDir, @SW_HIDE ) If IsArray ( $_CheckedTv1ItemsArray ) Then ReDim $_CheckedTv1ItemsArray[1] If IsArray ( $_CheckedTv1PathsArray ) Then ReDim $_CheckedTv1PathsArray[1] _StopBackup () WinSetTitle ( $_Gui, '', $_Version ) GUICtrlSetData ( $_ProgressBar1, 0 ) If $_Msg = '' Then MsgBox ( 262144+4160, 'Backup Canceled', 'No Folders' & @CRLF & 'have been saved in :' & @CRLF & @CRLF & $_BackupDirPath & @CRLF, 0 ) Else MsgBox ( 262144+4160, 'Backup Canceled', 'Only' & @CRLF & @CRLF & $_Msg & @CRLF & @CRLF & 'have been saved in :' & @CRLF & @CRLF & $_BackupDirPath & @CRLF, 0 ) EndIf $_Msg='' $_Finish = 1 $_Cancel = 1 $_ProcessExisted = 0 EndFunc ;==> _CancelBackup () Func _CloseBassMod () If FileExists ( @TempDir & '\About\BASSMOD.dll' ) And $_BassModDll Then DllCall ( $_BassModDll, 'int', 'BASSMOD_MusicStop' ) DllCall ( $_BassModDll, 'int', 'BASSMOD_SetVolume', 'int', $_VolumeOld ) DllCall ( $_BassModDll, 'int:cdecl', 'BASSMOD_MusicFree' ) DllCall ( $_BassModDll, 'int', 'BASSMOD_Free' ) DllClose ( $_BassModDll ) EndIf EndFunc ;==> _CloseBassMod () Func _CloseProcess ( $_Process ) Do ProcessClose ( $_Process ) Until Not ProcessExists ( $_Process ) EndFunc ;==> _CloseProcess () Func _CreateTreeviews () If $TV1 Then _GUICtrlTVExplorer_Destroy ( $TV1 ) $TV1 = _GUICtrlTVExplorer_Create ( '', 20, 85, 330, 365, BitOR ( $TVS_EDITLABELS, $TVS_CHECKBOXES, $TVS_DISABLEDRAGDROP, $TVS_HASLINES, $TVS_HASBUTTONS, $TVS_SHOWSELALWAYS ), _ $WS_EX_CLIENTEDGE, BitOR ( $TV_FLAG_SHOWLIKEEXPLORER, $TV_FLAG_SHOWSYSTEM, $TV_FLAG_SHOWFOLDERICON ), '_TVEvent' ) _TVSet ( $TV1 ) If $TV2 Then _GUICtrlTVExplorer_Destroy ( $TV2 ) $TV2 = _GUICtrlTVExplorer_Create ( '', 370, 85, 330, 365, BitOR ( $TVS_HASLINES, $TVS_HASBUTTONS, $TVS_DISABLEDRAGDROP, $TVS_SHOWSELALWAYS ), _ $WS_EX_CLIENTEDGE, BitOR ( $TV_FLAG_SHOWLIKEEXPLORER, $TV_FLAG_SHOWSYSTEM, $TV_FLAG_SHOWFOLDERICON ), '_TVEvent' ) _TVSet ( $TV2 ) EndFunc ;==> _CreateTreeviews () Func _DeleteArrayElementNotChecked ( $_TreeView, $_Array ) If Not IsArray ( $_Array ) Then Return Local $_Start=0 For $_Element In $_Array If Not _GUICtrlTreeView_GetChecked ( $_TreeView, $_Element ) Then _ArrayDelete ( $_Array, $_Start ) Else $_Start+=1 EndIf Next If Not IsArray ( $_Array ) Then Return If $_Array[0] <> UBound ( $_Array )-1 Then _ArrayInsert ( $_Array, 0, UBound ( $_Array ) ) Return $_Array EndFunc ;==> _DeleteArrayElementNotChecked () Func _DirCopyWithProgress ( $_SrcDirPath, $_DestDirPath, $_OverWritePrevDir=False ) $_SrcDirPath = _WinAPI_PathRemoveBackslash ( $_SrcDirPath ) $_DestDirPath = _WinAPI_PathRemoveBackslash ( $_DestDirPath ) Local $_SrcDirName = _WinAPI_PathStripPath ( $_SrcDirPath ) $_DestDirPath2 = $_DestDirPath & '\' & $_SrcDirName GUICtrlSetState ( $_ProgressLabel1, $GUI_SHOW ) If Not $_OverWritePrevDir And FileExists ( $_DestDirPath2 ) Then GUICtrlSetData ( $_ProgressLabel1, 'Please Wait While Deleting ' & $_DestDirPath2 ) If Not DirRemove ( $_DestDirPath2, 1 ) Then RunWait ( @ComSpec & ' /C RD /S /Q "' & $_DestDirPath2 & '"', @SystemDir, @SW_HIDE ) ; usefull with big dirs. EndIf If Not FileExists ( $_DestDirPath2 ) Then DirCreate ( $_DestDirPath2 ) $_SrcDirSize = DirGetSize ( $_SrcDirPath, 1 ) $_Ubound = UBound ( $_CheckedTv1ItemsArray ) -1 $_Data = 'Remaining Steps : ' & StringFormat ( '%02i/%02i', $_Step, $_Ubound ) & ' - Copying ' & $_SrcDirName & @crlf & ' To : ' & _WinAPI_PathCompactPath ( $_ProgressLabel1Handle, $_BackupDirpath, 0 ) If GUICtrlRead ( $_ProgressLabel1 ) <> $_Data Then GUICtrlSetData ( $_ProgressLabel1, $_Data ) $_Switches = '/R:10 /W:10 /E /B /V /NP /TEE' ; By default Robocopy will only copy a file if the source and destination have different time stamps or different file sizes. If $_PreservAttribs = 'True' Then $_Switches = $_Switches & ' /COPYALL' Else $_Switches = $_Switches & ' /COPY:DT' EndIf If $_Purge = 'True' Then $_Switches = $_Switches & ' /PURGE' ; Delete dest files/dirs that no longer exist in source $_ShowFlag = @SW_HIDE If $_ShowConsole Then $_ShowFlag = @SW_SHOW $_Pid = Run ( @SystemDir & '\robocopy.exe "' & $_SrcDirPath & '" "' & $_DestDirPath2 & '" *.* ' & $_Switches & ' /LOG+:"' & $_LogFilePath & '"', @SystemDir, $_ShowFlag ) ProcessWait ( $_Pid, 2 ) ProcessSetPriority ( $_Pid, 0 ) $_ProcessExisted = 1 $_RoboCopyWinHandle = _GetWinHwndByPid ( $_Pid ) TrayItemSetState ( $_AboutItem, $TRAY_DISABLE ) TrayItemSetState ( $_IdleTimeItem, $TRAY_DISABLE ) _ArrayAdd ( $_PidArray, $_Pid ) GUICtrlSetState ( $_ProgressBar1, $GUI_SHOW ) GUICtrlSetState ( $_ProgressBar2, $GUI_SHOW ) GUICtrlSetState ( $_ProgressLabel2, $GUI_SHOW ) EndFunc ;==> _DirCopyWithProgress () Func _Exit () GUISetState ( @SW_HIDE, $_Gui ) If $TV1 Then _GUICtrlTVExplorer_Destroy ( $TV1 ) If $TV2 Then _GUICtrlTVExplorer_Destroy ( $TV2 ) _CloseBassMod () If WinExists ( $_AboutGui ) Then GUIDelete ( $_AboutGui ) For $_I = 1 To UBound ( $_PidArray ) -1 _CloseProcess ( $_PidArray[$_I] ) Next _GDIPlus_ShutDown () GUIDelete ( $_Gui ) Exit EndFunc ;==> _Exit () Func _FileInstall () If Not FileExists ( $_TempDir ) Then If Not _IsConnected () Then Exit MsgBox ( 262144+4112, "Error", 'You are Not Connected !' & @CRLF & @CRLF & _ 'Sorry but' & @CRLF & 'Some externals files need to be downloaded at first execution !', 5 ) DirCreate ( $_TempDir ) EndIf ; robocopy If Not FileExists ( @SystemDir & '\robocopy.exe' ) Then InetGet ( 'http://tinyurl.com/d6up8vv', @SystemDir & '\robocopy.exe', 27, 1 ) ; Icon If Not FileExists ( 'C:\windows\TinyBackupBox.ico' ) Then InetGet ( 'http://tinyurl.com/5wmy88j/TinyBackupBox.ico', 'C:\windows\TinyBackupBox.ico', 27, 1 ) ; Pics Buttons If Not FileExists ( $_TempDir & '\StartButton001.png' ) Then InetGet ( 'http://tinyurl.com/5wmy88j/StartButton001.png', $_TempDir & '\StartButton001.png', 27, 0 ) If Not FileExists ( $_TempDir & '\StopButton001.png' ) Then InetGet ( 'http://tinyurl.com/5wmy88j/StopButton001.png', $_TempDir & '\StopButton001.png', 27, 0 ) If Not FileExists ( $_TempDir & '\RefreshButton001.png' ) Then InetGet ( 'http://tinyurl.com/5wmy88j/RefreshButton001.png', $_TempDir & '\RefreshButton001.png', 27, 0 ) ; Wave sounds If Not FileExists ( @WindowsDir & '\media\done.wav' ) Then InetGet ( 'http://tinyurl.com/5wmy88j/done.wav', @WindowsDir & '\media\done.wav', 27, 1 ) If Not FileExists ( @WindowsDir & '\media\bip8.wav' ) Then InetGet ( 'http://tinyurl.com/5wmy88j/bip8.wav', @WindowsDir & '\media\bip8.wav', 27, 1 ) If Not FileExists ( @WindowsDir & '\media\bip3.wav' ) Then InetGet ( 'http://tinyurl.com/5wmy88j/bip3.wav', @WindowsDir & '\media\bip3.wav', 27, 1 ) ; About files If Not FileExists ( @TempDir & '\About' ) Then DirCreate ( @TempDir & '\About' ) If Not FileExists ( @TempDir & '\About\BASSMOD.dll' ) Then InetGet ( 'http://tinyurl.com/3mac25y/BASSMOD.dll', @TempDir & '\About\BASSMOD.dll', 27, 1 ) If Not FileExists ( @TempDir & '\About\Alcatraz.xm' ) Then InetGet ( 'http://tinyurl.com/3mac25y/Alcatraz.xm', @TempDir & '\About\Alcatraz.xm', 27, 1 ) If Not FileExists ( @TempDir & '\About\WakiBlack2.jpg' ) Then InetGet ( 'http://tinyurl.com/3mac25y/WakiBlack2.jpg', @TempDir & '\About\WakiBlack2.jpg', 27, 1 ) EndFunc ;==> _FileInstall () Func _GetCtrlIdByHandle ( $_Hwnd ) If IsHWnd ( $_Hwnd ) Then Return _WinAPI_GetDlgCtrlID ( $_Hwnd ) EndFunc ;==> _GetCtrlIdByHandle () Func _GetDefaultBrowser () $_DefautBrowser = _WinAPI_AssocQueryString ( '.html', $ASSOCSTR_EXECUTABLE ) If Not @error Then Return $_DefautBrowser EndFunc ;==> _GetDefaultBrowser () Func _GetScriptVersion () If Not @Compiled Then Return StringTrimRight ( @ScriptName, 4 ) & ' © wakillon 2010 - 2011' Else Return StringTrimRight ( @ScriptName, 4 ) & ' v' & FileGetVersion ( @ScriptFullPath ) & ' © wakillon 2010 - 2011' EndIf EndFunc ;==> _GetScriptVersion () Func _GetWinHwndByPid ( $PID ) Local $_WinList While ProcessExists ( $PID ) $_WinList = WinList () For $_I = 1 To $_WinList[0][0] If $_WinList[$_I][0] <> "" And $PID = WinGetProcess ( $_WinList[$_I][1] ) Then Return $_WinList[$_I][1] Next Wend EndFunc ;==> _GetWinHwndByPid () Func _Gui () $_Gui = GUICreate ( $_Version, 720, 600 ) GUISetBkColor ( 0xEBBC2E ) GUISetIcon ( 'C:\windows\TinyBackupBox.ico' ) $_Label3 = GUICtrlCreateLabel ( 'Select Folders to be Saved', 20, 70, 330, 15, 0x01 ) GUICtrlSetFont ( -1, 11, 800 ) GUICtrlSetColor ( -1, 0x000000 ) $_Label4 = GUICtrlCreateLabel ( 'Select Backup Directory', 370, 70, 330, 15, 0x01 ) GUICtrlSetFont ( -1, 11, 800 ) GUICtrlSetColor ( -1, 0x000000 ) $_Dummy = GUICtrlCreateDummy () $_Context = GUICtrlCreateContextMenu ( $_Dummy ) $_Menu = GUICtrlGetHandle ( $_Context ) $_ButtonMenu = GUICtrlCreateMenuItem ( 'Create a New Sub Folder', $_Context ) $_Label1 = GUICtrlCreateLabel ( '', 21, 450, 328, 15 ) GUICtrlSetBkColor ( -1, 0x000000 ) GUICtrlSetColor ( -1, 0xEBBC2E ) GUICtrlSetFont ( -1, 8 ) $_Label2 = GUICtrlCreateLabel ( '', 371, 450, 328, 15 ) GUICtrlSetBkColor ( -1, 0x000000 ) GUICtrlSetColor ( -1, 0xEBBC2E ) GUICtrlSetFont ( -1, 8 ) _CreateTreeviews () _TVRemoveDrivesCheckboxes ( $TV1 ) _GDIPlus_Startup () $_StartButton = GUICtrlCreatePic ( '', 40, 20, 640, 35 ) $_StartButtonHandle = GUICtrlGetHandle ( $_StartButton ) GUICtrlSetTip ( $_StartButton, 'Click for Start a new Backup or' & @CRLF & 'Hold Shift + Click for Backup in Idle Mode', 'Start Button', 1, 1 ) $hPngImage1 = _GDIPlus_ImageLoadFromFile ( $_TempDir & '\StartButton001.png' ) $_BitmapHandle1 = _GDIPlus_BitmapCreateHBITMAPFromBitmap ( $hPngImage1, 0xFF000000 ) GUICtrlSendMsg ( $_StartButton, $STM_SETIMAGE, 0, $_BitmapHandle1 ) $hPngImage2 = _GDIPlus_ImageLoadFromFile ( $_TempDir & '\StopButton001.png' ) $_BitmapHandle2 = _GDIPlus_BitmapCreateHBITMAPFromBitmap ( $hPngImage2, 0xFF000000 ) $_RefreshButton = GUICtrlCreatePic ( '', 40, 545, 640, 35 ) GUICtrlSetTip ( -1, 'Click for Refresh TreeViews to previous Selection or' & @CRLF & 'Hold Shift + Click for Refresh TreeViews to the Root', 'Refresh Button', 1, 1 ) $hPngImage3 = _GDIPlus_ImageLoadFromFile ( $_TempDir & '\RefreshButton001.png' ) $_BitmapHandle3 = _GDIPlus_BitmapCreateHBITMAPFromBitmap ( $hPngImage3, 0xFF000000 ) GUICtrlSendMsg ( $_RefreshButton, $STM_SETIMAGE, 0, $_BitmapHandle3 ) $_ProgressBar1 = GUICtrlCreateProgress ( 20, 485, 680, 20 ) GUICtrlSetColor ( -1, 0xF88917 ) GUICtrlSetState ( -1, $GUI_HIDE ) $_ProgressLabel1 = GUICtrlCreateLabel ( '', 20, 505, 680, 40, 0x01 ) GUICtrlSetFont ( -1, 11, 800 ) GUICtrlSetColor ( -1, 0x000000 ) $_ProgressLabel1Handle = GUICtrlGetHandle ( -1 ) $_ProgressBar2 = GUICtrlCreateProgress ( 20, 545, 680, 20 ) GUICtrlSetColor ( -1, 0xF88917 ) GUICtrlSetState ( -1, $GUI_HIDE ) $_ProgressLabel2 = GUICtrlCreateLabel ( '', 20, 565, 680, 40, 0x01 ) GUICtrlSetFont ( -1, 11, 800 ) GUICtrlSetColor ( -1, 0x000000 ) GUICtrlSetState ( -1, $GUI_HIDE ) WinSetTrans ( $_Gui, '', 230 ) GUISetState ( @SW_SHOW ) EndFunc ;==> _Gui () Func _IsConnected () If Ping ( 'www.bing.com', 1 ) _ Or InetRead ( 'http://www.google.com/humans.txt', 19 ) Then Return True EndFunc ;==> _IsConnected () Func _IsMinimized ( $_Hwnd ) If BitAnd ( WinGetState ( $_Hwnd ), 16 ) Then Return 1 EndFunc ;==> _IsMinimized () Func _IsVisible ( $_Hwnd ) If BitAnd ( WinGetState ( $_Hwnd ), 2 ) Then Return 1 EndFunc ;==> _IsVisible () Func _Minimize () TrayItemSetState ( $_MinimizeItem, $TRAY_UNCHECKED ) If Not _IsMinimized ( $_Gui ) Then TrayItemSetText ( $_MinimizeItem, 'Restore Window' ) _SendMessage ( $_Gui, $WM_SYSCOMMAND, $SC_MINIMIZE, 0 ) Else TrayItemSetText ( $_MinimizeItem, 'Minimize' ) _SendMessage ( $_Gui, $WM_SYSCOMMAND, $SC_RESTORE, 0 ) EndIf EndFunc ;==> _Minimize () Func _MuteSounds () $_MuteSounds = Not $_MuteSounds If $_MuteSounds = 'True' Then TrayItemSetState ( $_MuteSoundsItem, $TRAY_CHECKED ) Else TrayItemSetState ( $_MuteSoundsItem, $TRAY_UNCHECKED ) EndIf RegWrite ( $_RegKeySettings, 'MuteSounds', 'REG_SZ', $_MuteSounds ) EndFunc ;==> _MuteSounds () Func _OnAutoItExit () Opt ( 'TrayIconHide', 0 ) TrayTip ( ' ', $_Version, 1, 1 ) FileDelete ( $_TempDir & '\*.log' ) Sleep ( 2000 ) TrayTip ( '', '', 1, 1 ) EndFunc ;==> _OnAutoItExit () Func _OpenBackupDirectory () TrayItemSetState ( $_BackupDirItem, $TRAY_UNCHECKED ) If FileExists ( $_Select2 ) Then ShellExecute ( $_Select2 ) Else MsgBox ( 262144+4160, '', 'No Backup Directory Selected !', 5 ) EndIf EndFunc ;==> _OpenBackupDirectory () Func _OpenTopic () TrayItemSetState ( $_TitleItem, $TRAY_UNCHECKED ) If FileExists ( _GetDefaultBrowser () ) Then ShellExecute ( 'http://www.autoitscript.com/forum/topic/135287-tinybackupbox-v1030-2011-12-02/' ) Else ShellExecute ( 'iexplore.exe', 'http://www.autoitscript.com/forum/topic/135287-tinybackupbox-v1030-2011-12-02/' ) EndIf EndFunc ;==> _OpenTopic () Func _OverWrite () $_OverWrite = Not $_OverWrite If $_OverWrite = 'True' Then TrayItemSetState ( $_OverWriteItem, $TRAY_CHECKED ) Else TrayItemSetState ( $_OverWriteItem, $TRAY_UNCHECKED ) EndIf RegWrite ( $_RegKeySettings, 'OverWrite', 'REG_SZ', $_OverWrite ) EndFunc ;==> _OverWrite () Func _Play () If FileExists ( @TempDir & '\About\BASSMOD.dll' ) Then $_BassModDll = DllOpen ( @TempDir & '\About\BASSMOD.dll' ) DllCall ( $_BassModDll, 'int', 'BASSMOD_Init', 'int', -1, 'int', 44100, 'int', 0 ) $_String = DllStructCreate ( 'char[255]' ) DllStructSetData ( $_String, 1, @TempDir & '\About\Alcatraz.xm' ) Local $aRet = DllCall ( $_BassModDll, 'int', 'BASSMOD_GetVolume') If Not @error Then $_VolumeOld = $aRet[0] If $aRet[0] < 30 Then DllCall ( $_BassModDll, 'int', 'BASSMOD_SetVolume', 'int', 30 ) $_Volume = 30 Else $_Volume = $_VolumeOld EndIf EndIf If $_VolumeOld > 30 Then $_VolumeStep = 1 DllCall ( $_BassModDll, 'int', 'BASSMOD_MusicLoad', 'int', 0, 'ptr', DllStructGetPtr ( $_String ), 'int', 0, 'int', 0, 'int', 4 + 1024 ) DllCall ( $_BassModDll, 'int', 'BASSMOD_MusicPlay' ) EndIf EndFunc ;==> _Play () Func _PreservAttribs () $_PreservAttribs = Not $_PreservAttribs If $_PreservAttribs = 'True' Then TrayItemSetState ( $_PreservAttribsItem, $TRAY_CHECKED ) Else TrayItemSetState ( $_PreservAttribsItem, $TRAY_UNCHECKED ) EndIf RegWrite ( $_RegKeySettings, 'PreservAttribs', 'REG_SZ', $_PreservAttribs ) EndFunc ;==> _PreservAttribs () Func _Purge () $_Purge = Not $_Purge If $_Purge = 'True' Then TrayItemSetState ( $_PurgeItem, $TRAY_CHECKED ) Else TrayItemSetState ( $_PurgeItem, $TRAY_UNCHECKED ) EndIf RegWrite ( $_RegKeySettings, 'Purge', 'REG_SZ', $_Purge ) EndFunc ;==> _OverWrite () Func _SetIdleTimeDelay () TrayItemSetState ( $_IdleTimeItem, $TRAY_UNCHECKED ) Local $_NewIdleTimeDelay = Int ( InputBox ( 'Set Idle Time Delay', "In Idle Mode, Backup will only start when you are not active and will pause if you're." & @crlf & _ 'You can set duration for the period of inactivity ( default is 5 Min ) before the backup starts or resumes.' & @crlf & @crlf & _ 'Enter number of Minutes desired.', $_IdleTimeDelay, ' M', 250, 200 ) ) If $_NewIdleTimeDelay > 0 Then $_IdleTimeDelay = $_NewIdleTimeDelay TrayItemSetText ( $_IdleTimeItem, 'Set Idle Time Delay ( Is currently set to ' & $_IdleTimeDelay & ' Min )' ) RegWrite ( $_RegKeySettings, 'IdleTimeDelay', 'REG_SZ', $_IdleTimeDelay ) EndFunc ;==> _SetIdleTimeDelay () Func _ShowConsole () If $_ShowConsole Then If $_RoboCopyWinHandle And _IsVisible ( $_RoboCopyWinHandle ) Then WinSetState ( $_RoboCopyWinHandle, '', @SW_HIDE ) $_ShowConsole = 0 TrayItemSetState ( $_ShowConsoleItem, $TRAY_UNCHECKED ) Else If $_RoboCopyWinHandle And Not _IsVisible ( $_RoboCopyWinHandle ) Then WinSetState ( $_RoboCopyWinHandle, '', @SW_SHOW ) $_ShowConsole = 1 TrayItemSetState ( $_ShowConsoleItem, $TRAY_CHECKED ) EndIf EndFunc ;==> _ShowConsole () Func _SimulPressButton ( $_ButtonId, $_ButtonLeft, $_ButtonTop, $_ButtonWidth, $_ButtonHeight, $_Delay=50 ) GUICtrlSetPos ( $_ButtonId, $_ButtonLeft +3, $_ButtonTop +1, $_ButtonWidth -3*2, $_ButtonHeight -1*2 ) Sleep ( $_Delay ) GUICtrlSetPos ( $_ButtonId, $_ButtonLeft, $_ButtonTop, $_ButtonWidth, $_ButtonHeight ) EndFunc ;==> _SimulPressButton () Func _StopBackup () $_Backup = 0 $_Pid = 0 $_RoboCopyWinHandle=0 GUICtrlSetState ( $_RefreshButton, $GUI_SHOW ) GUICtrlSendMsg ( $_StartButton, $STM_SETIMAGE, 0, $_BitmapHandle1 ) GUICtrlSetTip ( $_StartButton, 'Click for Start a new Backup or' & @CRLF & 'Hold Shift + Click for Backup in Idle Mode', 'Start Button', 1, 1 ) GUICtrlSetState ( $_ProgressBar1, $GUI_HIDE ) GUICtrlSetState ( $_ProgressBar2, $GUI_HIDE ) GUICtrlSetState ( $_ProgressLabel2, $GUI_HIDE ) GUICtrlSetData ( $_ProgressLabel1, 'BackupDir Selected : ' & $_Select2 ) TrayItemSetState ( $_AboutItem, $TRAY_ENABLE ) TrayItemSetState ( $_IdleTimeItem, $TRAY_ENABLE ) EndFunc ;==> _StopBackup () Func _TrayMenu () TraySetIcon ( 'C:\windows\TinyBackupBox.ico' ) $_TitleItem = TrayCreateItem ( $_Version ) TrayItemSetOnEvent ( -1, '_OpenTopic' ) TrayCreateItem ( '-------------------------- Settings -------------------------' ) $_OverWriteItem = TrayCreateItem ( 'Copy only new files ( Instead of Delete previous Dir )' ) TrayItemSetOnEvent ( -1, '_OverWrite' ) $_RegRead = RegRead ( $_RegKeySettings, 'OverWrite' ) If @error Or $_RegRead = 'True' Then $_OverWrite = True TrayItemSetState ( $_OverWriteItem, $TRAY_CHECKED ) Else $_OverWrite = False TrayItemSetState ( $_OverWriteItem, $TRAY_UNCHECKED ) EndIf TrayCreateItem ( '' ) $_PurgeItem = TrayCreateItem ( 'Delete dest files/dirs that no longer exist in source' ) TrayItemSetOnEvent ( -1, '_Purge' ) $_RegRead = RegRead ( $_RegKeySettings, 'Purge' ) If @error Or $_RegRead = 'True' Then $_Purge = True TrayItemSetState ( $_PurgeItem, $TRAY_CHECKED ) Else $_Purge = False TrayItemSetState ( $_PurgeItem, $TRAY_UNCHECKED ) EndIf TrayCreateItem ( '' ) $_PreservAttribsItem = TrayCreateItem ( 'Preserve Attributes' ) TrayItemSetOnEvent ( -1, '_PreservAttribs' ) $_RegRead = RegRead ( $_RegKeySettings, 'PreservAttribs' ) If @error Or $_RegRead = 'True' Then $_PreservAttribs = True TrayItemSetState ( $_PreservAttribsItem, $TRAY_CHECKED ) Else $_PreservAttribs = False TrayItemSetState ( $_PreservAttribsItem, $TRAY_UNCHECKED ) EndIf TrayCreateItem ( '' ) $_ShowConsoleItem = TrayCreateItem ( 'Show Robocopy Console Window when running' ) TrayItemSetOnEvent ( -1, '_ShowConsole' ) TrayCreateItem ( '' ) $_MuteSoundsItem = TrayCreateItem ( 'Mute Sounds' ) TrayItemSetOnEvent ( -1, '_MuteSounds' ) $_RegRead = RegRead ( $_RegKeySettings, 'MuteSounds' ) If @error Or $_RegRead = 'False' Then $_MuteSounds = False TrayItemSetState ( $_MuteSoundsItem, $TRAY_UNCHECKED ) Else $_MuteSounds = True TrayItemSetState ( $_MuteSoundsItem, $TRAY_CHECKED ) EndIf TrayCreateItem ( '-------------------------- Actions -------------------------' ) $_IdleTimeItem = TrayCreateItem ( 'Set Idle Time Delay' ) TrayItemSetState ( $_IdleTimeItem, $TRAY_UNCHECKED ) TrayItemSetOnEvent ( -1, '_SetIdleTimeDelay' ) $_RegRead = RegRead ( $_RegKeySettings, 'IdleTimeDelay' ) If @error Or $_RegRead = '' Then $_IdleTimeDelay = 5 Else $_IdleTimeDelay = $_RegRead EndIf TrayItemSetText ( $_IdleTimeItem, 'Set Idle Time Delay ( Is currently set to ' & $_IdleTimeDelay & ' Min )' ) TrayCreateItem ( '' ) $_BackupDirItem= TrayCreateItem ( 'Open Selected Backup Directory' ) TrayItemSetOnEvent ( -1, '_OpenBackupDirectory' ) TrayItemSetState ( $_BackupDirItem, $TRAY_UNCHECKED ) TrayCreateItem ( '' ) $_AboutItem = TrayCreateItem ( 'About ( ESC for Quit )' ) TrayItemSetOnEvent ( -1, '_About' ) TrayCreateItem ( '' ) $_MinimizeItem = TrayCreateItem ( 'Minimize' ) TrayItemSetOnEvent ( -1, '_Minimize' ) TrayCreateItem ( '' ) $_ExitItem = TrayCreateItem ( 'Exit' ) TrayItemSetOnEvent ( -1, '_Exit' ) TraySetClick ( 16 ) TraySetState ( 4 ) TraySetOnEvent ( $TRAY_EVENT_PRIMARYDOUBLE, '_Minimize' ) TraySetOnEvent ( $TRAY_EVENT_PRIMARYDOWN, '_Activate' ) TraySetToolTip ( $_Version & @CRLF & 'Left click Restore/Activate' & @CRLF & 'Double click Minimize' & @CRLF & 'Right click Tray Menu' ) EndFunc ;==> _TrayMenu () Func _TVEvent ( $hTV, $iMsg, $sPath, $hItem ) Switch $iMsg Case $TV_NOTIFY_SELCHANGED _TVSetPath () $_Path = $sPath $_Item = $hItem $_ItemText = _GUICtrlTreeView_GetText ( $TV1, $_Item ) If $hTV = $TV1 Then If _IsPressed ( '10' ) Then ; 10 : Hold Left SHIFT key when clicking a first item chekbox will check all next items. $_FirstChild = _GUICtrlTreeView_GetFirstChild ( $hTV, _GUICtrlTreeView_GetParentHandle ( $hTV, $_Item ) ) $_LastChild = _GUICtrlTreeView_GetLastChild ( $hTV, _GUICtrlTreeView_GetParentHandle ( $hTV, $_Item ) ) If $_FirstChild = $_Item Then _GUICtrlTreeView_SetChecked ( $hTV, $_FirstChild, True ) If Not _AlreadyInArray ( $_CheckedTv1ItemsArray, $_FirstChild, 1, 1 ) Then _ArrayAdd ( $_SelectedTv1ItemsArray, $_FirstChild ) $_StartItem = $_FirstChild Do $_NextItem = _GUICtrlTreeView_GetNextChild ( $hTV, $_StartItem ) If $_NextItem Then _GUICtrlTreeView_SetChecked ( $hTV, $_NextItem, True ) If Not _AlreadyInArray ( $_CheckedTv1ItemsArray, $_NextItem, 1, 1 ) Then _ArrayAdd ( $_SelectedTv1ItemsArray, $_NextItem ) $_StartItem = $_NextItem EndIf Until Not $_NextItem EndIf EndIf If Not _AlreadyInArray ( $_CheckedTv1ItemsArray, $_Item, 1, 1 ) Then _ArrayAdd ( $_SelectedTv1ItemsArray, $_Item ) If Not $_MuteSounds Then SoundPlay ( @WindowsDir & '\Media\bip3.wav' ) Else If Not $_MuteSounds Then SoundPlay ( @WindowsDir & '\Media\bip8.wav' ) EndIf Case $TV_NOTIFY_RCLICK If $hTV = $TV2 Then _GUICtrlMenu_TrackPopupMenu ( $_Menu, $_Gui ) ; Tv2 : Display a Context Menu for create a new sub folder of the clicked Item. Else If Not _AlreadyInArray ( $_CheckedTv1ItemsArray, $hItem, 1, 1 ) Then _ArrayAdd ( $_SelectedTv1ItemsArray, $hItem ) $_FirstChild = _GUICtrlTreeView_GetFirstChild ( $hTV, $hItem ) ; Tv1 : a right click for uncheck childs checkboxes Items of an Item. _GUICtrlTreeView_SetChecked ( $hTV, $_FirstChild, False ) $_StartItem = $_FirstChild Do $_NextItem = _GUICtrlTreeView_GetNextChild ( $hTV, $_StartItem ) If $_NextItem Then _GUICtrlTreeView_SetChecked ( $hTV, $_NextItem, False ) $_StartItem = $_NextItem EndIf Until Not $_NextItem EndIf EndSwitch EndFunc ;==> _TVEvent () Func _TVItemHasCheckbox ( $_TreeView, $_Item ) Return BitAND ( _GUICtrlTreeView_GetState ( $_TreeView, $_Item ), BitOR ( $TVIS_CHECKED, $TVIS_UNCHECKED ) ) <> 0 EndFunc ;==> _TVItemHasCheckbox () Func _TVRemoveDrivesCheckboxes ( $_TreeView ) $_FirstChild = _GUICtrlTreeView_GetFirstItem ( $_TreeView ) If _TVItemHasCheckbox ( $_TreeView, $_FirstChild ) Then _TVSetNoCheckboxToItem ( $_TreeView, $_FirstChild ) Do $_NextChild = _GUICtrlTreeView_GetNext ( $_TreeView, $_FirstChild ) If _TVItemHasCheckbox ( $_TreeView, $_NextChild ) Then _TVSetNoCheckboxToItem ( $_TreeView, $_NextChild ) $_FirstChild = $_NextChild Until Not $_NextChild EndFunc ;==> _TVRemoveDrivesCheckboxes () Func _TVSet ( $_TreeView ) If IsHWnd ( $_TreeView ) Then $_TreeView = _WinAPI_GetDlgCtrlID ( $_TreeView ) ; get ctrlid GUICtrlSetBkColor ( $_TreeView, 0x000000 ) GUICtrlSetFont ( $_TreeView, 8, 800 ) GUICtrlSetColor ( $_TreeView, 0xEBBC2E ) _GUICtrlTreeView_SetLineColor ( $_TreeView, 0xEBBC2E ) EndFunc ;==> _TVSet () Func _TVSetItemUnSelectable ( $_TreeView, $_Item ) _GUICtrlTreeView_SetSelected ( $_TreeView, $_Item, True ) _GUICtrlTreeView_SetState ( $_TreeView, $_Item, $TVIS_SELECTED, False ) EndFunc ;==> _TVSetItemUnSelectable () Func _TVSetNoCheckboxToItem ( $_TreeView, $_Item ) _GUICtrlTreeView_SetChecked ( $_TreeView, $_Item, True ) _GUICtrlTreeView_SetState ( $_TreeView, $_Item, $TVIS_CHECKED, False ) EndFunc ;==> _TVSetNoCheckboxToItem () Func _TVSetPath () Local $hInput1 = GUICtrlGetHandle ( $_Label1 ) $_Select1 = _GUICtrlTVExplorer_GetSelected ( $TV1 ) GUICtrlSetData ( $_Label1, _WinAPI_PathCompactPath ( $hInput1, $_Select1, -2 ) ) GUICtrlSetTip ( $_Label1, $_Select1, "Left TreeView Selected path : ", 1, 1 ) Local $hInput2 = GUICtrlGetHandle ( $_Label2 ) If $_Finish Then $_Select2 = _GUICtrlTVExplorer_GetSelected ( $TV2 ) If Not $_Backup Then GUICtrlSetData ( $_ProgressLabel1, 'BackupDir Selected : ' & $_Select2 ) GUICtrlSetData ( $_Label2, _WinAPI_PathCompactPath ( $hInput2, $_Select2, -2 ) ) GUICtrlSetTip ( $_Label2, $_Select2, "Right TreeView Selected path : ", 1, 1 ) EndFunc ;==> _TVSetPath () Func _TVUnCheckAllParentItems ( $_TreeView, $_Array ) If Not IsArray ( $_Array ) Then Return Local $_ChildItem For $_Element In $_Array $_ChildItem = $_Element Do $_ParentItem = _GUICtrlTreeView_GetParentHandle ( $_TreeView, $_ChildItem ) If _TVItemHasCheckbox ( $_TreeView, $_ParentItem ) Then _GUICtrlTreeView_SetChecked ( $_TreeView, $_ParentItem, False ) $_ChildItem = $_ParentItem Until Not $_ParentItem Next EndFunc ;==> _TVUnCheckAllParentItems ()