-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathESoft.Launcher.UI.BackupRestore.pas
126 lines (108 loc) · 3.56 KB
/
ESoft.Launcher.UI.BackupRestore.pas
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
Unit ESoft.Launcher.UI.BackupRestore;
Interface
Uses
Winapi.Windows,
Winapi.Messages,
System.SysUtils,
System.Variants,
System.Classes,
Vcl.Graphics,
Vcl.Controls,
Vcl.Forms,
Vcl.Dialogs,
Vcl.StdCtrls,
Vcl.ActnList,
System.Zip,
ESoft.Utils,
System.Actions;
Type
TFormBackupRestore = Class(TForm)
GroupBox1: TGroupBox;
Label1: TLabel;
cbRestore: TComboBox;
btnCancel: TButton;
btnRestore: TButton;
ActionList: TActionList;
alClose: TAction;
Procedure alCloseExecute(Sender: TObject);
Procedure FormCreate(Sender: TObject);
Procedure btnRestoreClick(Sender: TObject);
Procedure cbRestoreChange(Sender: TObject);
Strict Private
{Private declarations}
Function FileNamePrifix(Const aIncludeFolder: Boolean = True): String;
Public
{Public declarations}
End;
Var
FormBackupRestore: TFormBackupRestore;
Implementation
{$R *.dfm}
Uses
UnitMDIMain;
Procedure TFormBackupRestore.alCloseExecute(Sender: TObject);
Begin
ModalResult := mrClose;
End;
Procedure TFormBackupRestore.btnRestoreClick(Sender: TObject);
Procedure _ClearOldFiles;
Begin
DeleteFile(FormMDIMain.ParentFolder + 'Old_' + cConfig_INI);
DeleteFile(FormMDIMain.ParentFolder + 'Old_' + cGroup_INI);
DeleteFile(FormMDIMain.ParentFolder + 'Old_' + cParam_INI);
DeleteFile(FormMDIMain.ParentFolder + 'Old_' + cClipbord_Data);
DeleteFile(FormMDIMain.ParentFolder + 'Old_' + cDatabaseFileName);
RenameFile(FormMDIMain.ParentFolder + cConfig_INI, FormMDIMain.ParentFolder + 'Old_' + cConfig_INI);
RenameFile(FormMDIMain.ParentFolder + cGroup_INI, FormMDIMain.ParentFolder + 'Old_' + cGroup_INI);
RenameFile(FormMDIMain.ParentFolder + cParam_INI, FormMDIMain.ParentFolder + 'Old_' + cParam_INI);
RenameFile(FormMDIMain.ParentFolder + cClipbord_Data, FormMDIMain.ParentFolder + 'Old_' + cClipbord_Data);
RenameFile(FormMDIMain.ParentFolder + cDatabaseFileName, FormMDIMain.ParentFolder + 'Old_' + cDatabaseFileName);
DeleteFile(FormMDIMain.ParentFolder + cConfig_INI);
DeleteFile(FormMDIMain.ParentFolder + cGroup_INI);
DeleteFile(FormMDIMain.ParentFolder + cParam_INI);
DeleteFile(FormMDIMain.ParentFolder + cClipbord_Data);
DeleteFile(FormMDIMain.ParentFolder + cDatabaseFileName);
End;
Var
varZipFile: TZipFile;
sZipFile: String;
Begin
If MessageDlg('Are you sure you want to restore ?', mtConfirmation, [mbYes, mbNo], 0, mbNo) = mrNo Then
Exit;
varZipFile := TZipFile.Create;
Try
sZipFile := FileNamePrifix + Trim(cbRestore.Text);
If FileExists(sZipFile) Then
Begin
_ClearOldFiles;
varZipFile.ExtractZipFile(sZipFile, FormMDIMain.ParentFolder);
FormMDIMain.ReloadFromIni;
ModalResult := mrOk;
End;
Finally
varZipFile.Free;
End;
End;
Procedure TFormBackupRestore.cbRestoreChange(Sender: TObject);
Begin
btnRestore.Enabled := Trim(cbRestore.Text) <> '';
End;
Function TFormBackupRestore.FileNamePrifix(Const aIncludeFolder: Boolean = True): String;
Begin
Result := cESoftLauncher + '_';
If aIncludeFolder Then
Result := FormMDIMain.BackupFolder + Result;
End;
Procedure TFormBackupRestore.FormCreate(Sender: TObject);
Var
varSearch: TSearchRec;
Begin
If FindFirst(FileNamePrifix + '*.zip', faArchive, varSearch) = 0 Then
Begin
Repeat
cbRestore.Items.Add(StringReplace(varSearch.Name, FileNamePrifix(False), '', []));
Until FindNext(varSearch) <> 0;
FindClose(varSearch);
End;
End;
End.