#cs Programm: Profiler Sprache : AutoIt 3.x Autor : M.R.Delhalle Datum : 2017-11-15 Backups the profile-directories of Firefox and Thunderbird in RAR-Archives. These archives will be created in the directory containing the script and will get a time-stamp in their filenames. these archives can be selected and restored in the profile-dir using the restore-button. #ce #include #include #include #include #include #include #include Global $file Global $handle ; check for Winrar on the system If FileExists("c:\Program Files\WinRar\WinRar.exe") Then $winrar = "c:\Program Files\WinRar\WinRar.exe" ; ElseIf FileExists("c:\Program Files (x86)\Winrar\WinRar.exe") Then $winrar = "c:\Program Files (x86)\Winrar\WinRar.exe" ; Else MsgBox(16, "Missing Winrar", "Sorry, no installed Winrar could be found on this system.") EndIf $backup_to_dir = "c:\temp\" #Region ### START Koda GUI section ### Form= $Form1 = GUICreate("Profiler - creates backups of profiles from Firefox and Thunderbird", 615, 215, -1, -1) ; this block is just for the background color $backupcolor = 0x669966 GUICtrlCreateLabel("", 0, 0, 615, 108) GUICtrlSetBkColor(-1, $backupcolor) GUICtrlSetState(-1, $GUI_DISABLE) $Group1 = GUICtrlCreateGroup("Backup", 8, 8, 601, 89) GUICtrlSetBkColor(-1, $backupcolor) $Label1 = GUICtrlCreateLabel("Firefox", 16, 32, 35, 17) GUICtrlSetBkColor(-1, $backupcolor) $lbl_firefox = GUICtrlCreateLabel("", 88, 32, 425, 21) GUICtrlSetBkColor(-1, $backupcolor) $save = GUICtrlCreateButton("Backup", 520, 32, 75, 50) $Label2 = GUICtrlCreateLabel("Thunderbird", 16, 64, 61, 17) GUICtrlSetBkColor(-1, $backupcolor) $lbl_thunderbird = GUICtrlCreateLabel("", 88, 64, 425, 21) GUICtrlSetBkColor(-1, $backupcolor) GUICtrlCreateGroup("", -99, -99, 1, 1) ; this block is just for the background color $restorecolor = 0xff8800 GUICtrlCreateLabel("", 0, 104, 615, 175) GUICtrlSetBkColor(-1, $restorecolor) GUICtrlSetState(-1, $GUI_DISABLE) $Group2 = GUICtrlCreateGroup("Restore", 8, 104, 601, 101) GUICtrlSetBkColor(-1, $restorecolor) $Label3 = GUICtrlCreateLabel("Archivename", 16, 130, 70, 17) GUICtrlSetBkColor(-1, $restorecolor) $ff_archiv = GUICtrlCreateCombo("", 104, 128, 409, 125, BitOR($CBS_DROPDOWN, $CBS_AUTOHSCROLL)) $ff_restore = GUICtrlCreateButton("Restore", 520, 128, 75, 20) $Label5 = GUICtrlCreateLabel("Archivename", 16, 172, 70, 17) GUICtrlSetBkColor(-1, $restorecolor) $tb_archiv = GUICtrlCreateCombo("", 104, 170, 409, 25, BitOR($CBS_DROPDOWN, $CBS_AUTOHSCROLL)) $tb_restore = GUICtrlCreateButton("Restore", 520, 170, 75, 20) GUICtrlCreateGroup("", -99, -99, 1, 1) GUISetState(@SW_SHOW) #EndRegion ### END Koda GUI section ### ; read out the profiles.ini to ge the profile path for firefox $last_profile_path = IniRead(@AppDataDir & "\Mozilla\Firefox\profiles.ini", "Profile0", "Path", "-") If $last_profile_path <> "-" Then $ff_profil = @AppDataDir & "\Mozilla\FireFox\" & StringReplace($last_profile_path, "/", "\") & "\" Else $ff_profil = "" EndIf GUICtrlSetData($lbl_firefox, $ff_profil) ; read out the profiles.ini to ge the profile path for thunderbird $last_profile_path = IniRead(@AppDataDir & "\Thunderbird\profiles.ini", "Profile0", "Path", "-") If $last_profile_path <> "-" Then $tb_profil = @AppDataDir & "\Thunderbird\" & StringReplace($last_profile_path, "/", "\") & "\" Else $tb_profil = "" EndIf GUICtrlSetData($lbl_thunderbird, $tb_profil) listarchives() ; find all backups and put them in the combobox While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $save $ziel = "Firefox_" & @YEAR & "-" & @MON & "-" & @MDAY & "_" & @HOUR & "-" & @MIN & "-" & @SEC & ".rar" $cmd = $winrar & ' a -r -ep1 -ma -tl "' & $ziel & '" "' & $ff_profil & '"' If $ff_profil <> "" Then RunWait($cmd, @ScriptDir) $ziel = "Thunderbird_" & @YEAR & "-" & @MON & "-" & @MDAY & "_" & @HOUR & "-" & @MIN & "-" & @SEC & ".rar" $cmd = $winrar & ' a -r -ep1 -ma -tl "' & $ziel & '" "' & $tb_profil & '"' ConsoleWrite($cmd) If $tb_profil <> "" Then RunWait($cmd, @ScriptDir) listarchives() ; find all backups and put them in the combobox Case $ff_restore If ProcessExists("firefox.exe") Then MsgBox(16, "Firefox läuft noch", "Firefox ist noch aktiv. Das Profil kann nur wiederhergestellt werden, wenn Firefox geschlossen ist.") ContinueLoop EndIf If $ff_profil <> "" Then ; only if a profile has been found ClearFolder($ff_profil) ; delete the content of the folder $archiv = GUICtrlRead($ff_archiv) ; get selected archive $cmd = $winrar & ' x "' & $archiv & '" "' & $ff_profil & '"' RunWait($cmd, @ScriptDir) ; extract the content of the archive into the profile-dir EndIf Case $tb_restore If ProcessExists("thunderbird.exe") Then MsgBox(16, "Thunderbird läuft noch", "Thunderbird ist noch aktiv. Das Profil kann nur wiederhergestellt werden, wenn Thunderbird geschlossen ist.") ContinueLoop EndIf If $tb_profil <> "" Then ; only if a profile has been found ClearFolder($tb_profil) ; delete the content of the folder $archiv = GUICtrlRead($tb_archiv) ; get selected archive $cmd = $winrar & ' x "' & $archiv & '" "' & $tb_profil & '"' RunWait($cmd, @ScriptDir) ; extract the content of the archive into the profile-dir EndIf Case $GUI_EVENT_CLOSE Exit EndSwitch WEnd Func listarchives() GUICtrlSetData($ff_archiv, "") ; delete content of Combobox $handle = FileFindFirstFile("Firefox_*.rar") While 1 $file = FileFindNextFile($handle) If @error Then ExitLoop GUICtrlSetData($ff_archiv, $file) ; add found archives GUICtrlSetData($ff_archiv, $file) ; the very last found archive is set as default (since it is the latest) WEnd FileClose($handle) GUICtrlSetData($tb_archiv, "") ; hinzufügen des Archives $handle = FileFindFirstFile("Thunderbird_*.rar") While 1 $file = FileFindNextFile($handle) ; delete content of Combobox If @error Then ExitLoop GUICtrlSetData($tb_archiv, $file) ; add found archives GUICtrlSetData($tb_archiv, $file) ; the very last found archive is set as default (since it is the latest) WEnd FileClose($handle) EndFunc ;==>listarchives Func ClearFolder($dir) If StringRight($dir, 1) <> "\" Then $dir = $dir & "\" Local $pattern = $dir & "*.*" Local $file Local $handle RunWait(@ComSpec & " /c " & 'del /Q /s "' & $pattern & '"', "", @SW_HIDE) $handle = FileFindFirstFile($pattern) While 1 $file = FileFindNextFile($handle) If @error Then ExitLoop If $file <> "." And $file <> ".." Then If StringInStr(FileGetAttrib($dir & $file), "D") Then DirRemove($dir & $file, 1) EndIf EndIf WEnd FileClose($handle) EndFunc ;==>ClearFolder