Jump to content

Application to back up


Belini
 Share

Recommended Posts

I needed to do a backup program that meets my needs and I want to share it with you.

#RequireAdmin
#region ;**** Directives created by AutoIt3Wrapper_GUI ****
#AutoIt3Wrapper_Icon=.\Bk.ico
#AutoIt3Wrapper_Compression=0
#AutoIt3Wrapper_UseUpx=n
#AutoIt3Wrapper_Res_Comment=Função: Application to backup
#AutoIt3Wrapper_Res_Description=Autoit3 3.3.9.4
#AutoIt3Wrapper_Res_Fileversion=1.1.10.18
#AutoIt3Wrapper_Res_LegalCopyright=Made by Belini
#AutoIt3Wrapper_Res_requestedExecutionLevel=asInvoker
#AutoIt3Wrapper_AU3Check_Parameters=-d -w 1 -w 2 -w 3 -w 4 -w 5 -w 6
#endregion ;**** Directives created by AutoIt3Wrapper_GUI ****

#cs -------------------------------------------------
    Title:          Backup Personal
    Objective:      Back up of the files and folders
    Author:         Belini (Brazil)
    Autoit Version: 3.3.9.4
    Version:        1.0.10.18
    Forum:          http://www.autoitbrasil.com/forum
#ce -------------------------------------------------

#include <ListViewConstants.au3>
#include <WindowsConstants.au3>
#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <EditConstants.au3>
#include "_UskinLibrary.au3"
#include <GuiListView.au3>
#include "Skin_03.au3"
#include <File.au3>

Global $iFix_Col = 1, $Dir_backup, $Input, $Listv, $Listv_Files, $Updated = 0, $Sustained = 0
Global $nMsg, $proceed = 1, $item_num, $But[8], $item_text[4], $Check, $lab[3]

_Arq_ini()
_Uskin_LoadDLL()
_USkin_Init(_Skin_03(True))
_Gui_backup()

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $But[1]
            _Add_Line()
        Case $But[2]
            _Del_line()
        Case $But[3]
            _Opt_Dir()
        Case $But[4]
            _Opt_Backup()
        Case $But[5]
            _Dir_Backup()
        Case $But[6]
            $proceed = 0
        Case $But[7]
            _Start_backup()
        Case $Check
            _Opt_Finalize()
    EndSwitch
WEnd

Func _Add_Line()
    Local $dir = FileSelectFolder("Searching for folder.", "")
    If IniRead(@ScriptDir & "\Config.ini", "Folders", $dir, "") = "" Then
        GUICtrlCreateListViewItem($dir & "|Include Subfolders" & "|Yes", $Listv)
        IniWrite(@ScriptDir & "\Config.ini", "Folders", $dir, "|Include Subfolders" & "|Yes")
    Else
        MsgBox(4096, "", "This directory has already been chosen!", 3)
    EndIf
EndFunc   ;==>_Add_Line

Func _Arq_ini()
    If Not FileExists(@ScriptDir & "\Config.ini") Then _
            FileWrite(@ScriptDir & "\Config.ini", "[BACKUP]" & @CRLF & "address= " & @CRLF & @CRLF & "[TURN OFF]" & @CRLF & "option=0" & @CRLF & @CRLF & "[FOLDERS]")
EndFunc   ;==>_Arq_ini

Func _Backup_Files($path = "")
    Local $searh_files, $i
    $searh_files = _FileListToArray($path, "*.*", 1)
    If Not @error Then
        For $i = 1 To $searh_files[0]
            If GUIGetMsg() = $But[6] Then $proceed = 0
            If $proceed = 0 Then ExitLoop
            _Compare_files($path & "\" & $searh_files[$i])
        Next
    EndIf
EndFunc   ;==>_Backup_Files

Func _Backup_Full($path = "", $counter = 0)
    $counter = 0
    $path &= '\'
    Local $file, $searh_files
    $searh_files = FileFindFirstFile($path & '*')
    If $searh_files = -1 Then Return ''
    While 1
        If GUIGetMsg() = $But[6] Then $proceed = 0
        $file = FileFindNextFile($searh_files)
        If @error Or $proceed = 0 Then ExitLoop
        If @extended Then
            If $counter >= 10 Then ContinueLoop
            _Backup_Full($path & $file, $counter + 1)
        Else
            _Compare_files($path & $file)
        EndIf
    WEnd
    FileClose($searh_files)
EndFunc   ;==>_Backup_Full

Func _Compare_files($file = "")
    Local $File_backup, $item, $folder
    $item = StringTrimLeft($file, StringInStr($file, "\", 1, -1))
    $folder = StringTrimLeft($file, StringInStr($file, "\", 1, -2))
    $folder = StringMid($folder, 1, StringInStr($folder, "\", 1, -1) -1 )
    $File_backup = StringReplace($file, StringMid($file, 1, 2), $Dir_backup, 0, 2)
    $file = FileGetShortName($file)
    $File_backup = FileGetShortName($File_backup)
    _GUICtrlListView_SetItemText($Listv, 0, $folder, 2)
    _GUICtrlListView_SetItemText($Listv, 0, $item, 1)
    If FileGetTime($file, 0, 1) > FileGetTime($File_backup, 0, 1) Then
        $Updated += 1
        FileCopy($file, $File_backup, 9)
        GUICtrlSetData($lab[2], "Updated: " & $Updated)
    Else
        $Sustained += 1
        GUICtrlSetData($lab[1], "Sustained: " & $Sustained)
    EndIf
EndFunc   ;==>_Compare_files

Func _Del_line()
    $item_num = _GUICtrlListView_GetSelectedIndices(GUICtrlGetHandle($Listv))
    $item_text[1] = _GUICtrlListView_GetItemText(GUICtrlGetHandle($Listv), Number($item_num))
    _GUICtrlListView_DeleteItemsSelected(GUICtrlGetHandle($Listv))
    IniDelete(@ScriptDir & "\Config.ini", "Folders", $item_text[1])
EndFunc   ;==>_Del_line

Func _Dir_Backup()
    $Dir_backup = FileSelectFolder("Searching for folder.", "", 1)
    ;GUICtrlSetState($Input, $GUI_FOCUS)
    GUICtrlSetData($Input, $Dir_backup)
    IniWrite(@ScriptDir & "\Config.ini", "BACKUP", "address", $Dir_backup)
EndFunc   ;==>_Dir_Backup

Func _Gui_backup()
    GUICreate("Backup  Personal    -    Made  by  Belini", 660, 679, -1, -1)
    GUICtrlCreateGroup("Directory for backup ", 352, 11, 290, 69)
    $But[1] = GUICtrlCreateButton("Include address", 15, 16, 140, 25)
    GUICtrlSetFont(-1, 12, 400, 0, "MS Sans Serif")
    $But[2] = GUICtrlCreateButton("Delete address", 15, 56, 140, 25)
    GUICtrlSetFont(-1, 12, 400, 0, "MS Sans Serif")
    $But[3] = GUICtrlCreateButton("Archives / Subfolders", 170, 16, 170, 25)
    GUICtrlSetFont(-1, 12, 400, 0, "MS Sans Serif")
    $But[4] = GUICtrlCreateButton("Mark / Unmark", 170, 56, 170, 25)
    GUICtrlSetFont(-1, 12, 400, 0, "MS Sans Serif")
    $But[5] = GUICtrlCreateButton("Search", 553, 36, 75, 25)
    GUICtrlSetFont(-1, 10, 400, 0, "MS Sans Serif")
    $But[6] = GUICtrlCreateButton("Cancel", 514, 631, 130, 33)
    GUICtrlSetFont(-1, 18, 400, 0, "MS Sans Serif")
    $But[7] = GUICtrlCreateButton("Start", 390, 631, 110, 33)
    GUICtrlSetFont(-1, 18, 400, 0, "MS Sans Serif")
    $Input = GUICtrlCreateInput(IniRead(@ScriptDir & "\Config.ini", "BACKUP", "address", ""), 368, 38, 183, 21)
    GUICtrlSetFont(-1, 10, 400, 0, "MS Sans Serif")
    $Check = GUICtrlCreateCheckbox("Turn off the computer when the task is finished.", 15, 647, 352, 25)
    GUICtrlSetFont(-1, 12, 400, 0, "MS Sans Serif")
    $lab[1] = GUICtrlCreateLabel("Sustained: 0", 32, 623, 175, 25)
    GUICtrlSetFont(-1, 12, 400, 0, "MS Sans Serif")
    $lab[2] = GUICtrlCreateLabel("Updated: 0", 210, 623, 175, 25)
    GUICtrlSetFont(-1, 12, 400, 0, "MS Sans Serif")
    $Listv = GUICtrlCreateListView("Folder Address|List  Files|Make  Backup", 16, 96, 627, 520, _
            BitOR($LVS_SHOWSELALWAYS, $LVS_SINGLESEL), BitOR($LVS_EX_GRIDLINES, $LVS_EX_FULLROWSELECT))
    GUICtrlSetFont(-1, 10, 400, 0, "MS Sans Serif")
    GUICtrlSetColor(-1, 0x000000)
    _GUICtrlListView_SetColumnWidth($Listv, 0, 395)
    _GUICtrlListView_SetColumnWidth($Listv, 1, 120)
    _GUICtrlListView_SetColumnWidth($Listv, 2, 105)
    _GUICtrlListView_JustifyColumn($Listv, 1, 2)
    _GUICtrlListView_JustifyColumn($Listv, 2, 2)
    GUISetState(@SW_SHOW)
    Local $aArray = IniReadSection(@ScriptDir & "\Config.ini", "Folders")
    _ArraySort($aArray)
    If Not @error Then
        For $i = 1 To $aArray[0][0]
            If FileExists($aArray[$i][0]) Then
                GUICtrlCreateListViewItem(StringReplace($aArray[$i][0] & $aArray[$i][1], "=|", "|"), $Listv)
            Else
                GUICtrlCreateListViewItem($aArray[$i][0] & "|Inexistent Folder|Not", $Listv)
            EndIf
        Next
    EndIf
    If IniRead(@ScriptDir & "\Config.ini", "TURN OFF", "option", "1") = "1" Then GUICtrlSetState($Check, $GUI_CHECKED)
EndFunc   ;==>_Gui_backup

Func _Opt_Dir()
    $item_num = _GUICtrlListView_GetSelectedIndices(GUICtrlGetHandle($Listv))
    $item_text[1] = _GUICtrlListView_GetItemText(GUICtrlGetHandle($Listv), Number($item_num), 1)
    $item_text[2] = _GUICtrlListView_GetItemText(GUICtrlGetHandle($Listv), Number($item_num), 2)
    Switch $item_text[1]
        Case "Directory Only"
            _GUICtrlListView_SetItemText($Listv, $item_num, "Include Subfolders", 1)
            IniWrite(@ScriptDir & "\Config.ini", "Folders", _GUICtrlListView_GetItemText(GUICtrlGetHandle($Listv), Number($item_num)), "|Include Subfolders|" & $item_text[2])
        Case "Include Subfolders"
            _GUICtrlListView_SetItemText($Listv, $item_num, "Directory Only", 1)
            IniWrite(@ScriptDir & "\Config.ini", "Folders", _GUICtrlListView_GetItemText(GUICtrlGetHandle($Listv), Number($item_num)), "|Directory Only|" & $item_text[2])
        Case "Inexistent Folder"
            MsgBox(4096, "", "Directory does not exist!", 3)
    EndSwitch
EndFunc   ;==>_Opt_Dir

Func _Opt_Backup()
    $item_num = _GUICtrlListView_GetSelectedIndices(GUICtrlGetHandle($Listv))
    $item_text[1] = _GUICtrlListView_GetItemText(GUICtrlGetHandle($Listv), Number($item_num), 1)
    $item_text[2] = _GUICtrlListView_GetItemText(GUICtrlGetHandle($Listv), Number($item_num), 2)
    If $item_text[1] <> "Inexistent Folder" Then
        Switch $item_text[2]
            Case "Yes"
                _GUICtrlListView_SetItemText($Listv, $item_num, "Not", 2)
                IniWrite(@ScriptDir & "\Config.ini", "Folders", _GUICtrlListView_GetItemText(GUICtrlGetHandle($Listv), Number($item_num)), "|" & $item_text[1] & "|Not")
            Case "Not"
                _GUICtrlListView_SetItemText($Listv, $item_num, "Yes", 2)
                IniWrite(@ScriptDir & "\Config.ini", "Folders", _GUICtrlListView_GetItemText(GUICtrlGetHandle($Listv), Number($item_num)), "|" & $item_text[1] & "|Yes")
        EndSwitch
    Else
        MsgBox(4096, "", "Directory does not exist!", 3)
    EndIf
EndFunc   ;==>_Opt_Backup

Func _Opt_Finalize()
    If GUICtrlRead($Check) = 1 Then
        IniWrite(@ScriptDir & "\Config.ini", "TURN OFF", "option", "1")
    Else
        IniWrite(@ScriptDir & "\Config.ini", "TURN OFF", "option", "0")
    EndIf
EndFunc   ;==>_Opt_Finalize

Func _Start_backup()
    Local $itens = _GUICtrlListView_GetItemCount($Listv)
    If $itens > 0 Then
        $Dir_backup = GUICtrlRead($Input)
        If FileExists($Dir_backup) Then
            For $i = 1 To $itens
                If $proceed = 0 Then ExitLoop
                $item_text[1] = _GUICtrlListView_GetItemText(GUICtrlGetHandle($Listv), 0, 0)
                $item_text[2] = _GUICtrlListView_GetItemText(GUICtrlGetHandle($Listv), 0, 1)
                $item_text[3] = _GUICtrlListView_GetItemText(GUICtrlGetHandle($Listv), 0, 2)
                If $item_text[2] <> "Inexistent Folder" And $item_text[3] = "Yes" Then
                    If $item_text[2] = "Include Subfolders" Then
                        _Backup_Full($item_text[1], 0)
                    Else
                        _Backup_Files($item_text[1])
                    EndIf
                EndIf
                If $proceed = 1 Then _GUICtrlListView_DeleteItem($Listv, 0)
            Next
            If $proceed = 1 Then
                If GUICtrlRead($Check) = 1 Then
                    Shutdown(1)
                Else
                    GUICtrlSetState($Listv_Files, $GUI_HIDE)
                    MsgBox(4096, "", "Task Completed!")
                    Exit
                EndIf
            Else
                $proceed = 1
                _GUICtrlListView_SetItemText($Listv, 0, $item_text[2], 1)
                _GUICtrlListView_SetItemText($Listv, 0, $item_text[3], 2)
            EndIf
        Else
            MsgBox(4096, "", "Backup directory does not exist!", 3)
        EndIf
    EndIf
EndFunc   ;==>_Start_backup
Spoiler

Bk_personal.png

Download full:  https://mega.nz/#!5JEylSoB!AvebLVC9bFq_8a33MA2LzaRra6ZEgbYKH5MGcDS8khE

Edited by Belini
Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...