-
-
Notifications
You must be signed in to change notification settings - Fork 4
/
BackupsForm.pas
237 lines (204 loc) · 7.12 KB
/
BackupsForm.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
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
unit BackupsForm;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, ComCtrls, StdCtrls, ExtCtrls, Menus,
InflatablesList_Manager;
type
TfBackupsForm = class(TForm)
lvBackups: TListView;
leBackupFolder: TLabeledEdit;
btnOpenBckFolder: TButton;
pmnBackups: TPopupMenu;
mniBU_Delete: TMenuItem;
N1: TMenuItem;
mniBU_Backup: TMenuItem;
mniBU_Restore: TMenuItem;
procedure FormCreate(Sender: TObject);
procedure btnOpenBckFolderClick(Sender: TObject);
procedure pmnBackupsPopup(Sender: TObject);
procedure mniBU_DeleteClick(Sender: TObject);
procedure mniBU_RestoreClick(Sender: TObject);
procedure mniBU_BackupClick(Sender: TObject);
private
{ Private declarations }
fILManager: TILManager;
protected
procedure FillBackupList;
procedure UpdateTitle;
public
{ Public declarations }
OnRestartRequired: TNotifyEvent;
procedure Initialize(ILManager: TILManager);
procedure Finalize;
procedure ShowBackups;
end;
var
fBackupsForm: TfBackupsForm;
implementation
uses
AuxTypes, WinFileInfo, BitOps,
InflatablesList_Types,
InflatablesList_Utils;
{$R *.dfm}
procedure TfBackupsForm.FillBackupList;
var
i: Integer;
Function FlagsToStr(Flags: UInt32): String;
procedure AddToResult(const S: String);
begin
If Length(Result) > 0 then
Result := IL_Format('%s, %s',[Result,S])
else
Result := S;
end;
begin
Result := '';
If GetFlagState(Flags,IL_LIST_FLAG_BITMASK_ENCRYPTED) then
AddToResult('encrypted');
If GetFlagState(Flags,IL_LIST_FLAG_BITMASK_COMPRESSED) then
AddToResult('compressed');
end;
begin
leBackupFolder.Text := fILManager.BackupManager.StaticSettings.BackupPath;
lvBackups.Items.BeginUpdate;
try
// adjust count
If lvBackups.Items.Count > fILManager.BackupManager.BackupCount then
begin
For i := Pred(lvBackups.Items.Count) downto fILManager.BackupManager.BackupCount do
lvBackups.Items.Delete(i);
end
else If lvBackups.Items.Count < fILManager.BackupManager.BackupCount then
begin
For i := Succ(lvBackups.Items.Count) to fILManager.BackupManager.BackupCount do
with lvBackups.Items.Add do
begin
Caption := '';
SubItems.Add('');
SubItems.Add('');
SubItems.Add('');
SubItems.Add('');
SubItems.Add('');
end;
end;
// fill the list
For i := 0 to Pred(fILManager.BackupManager.BackupCount) do
with lvBackups.Items[i] do
begin
Caption := fILManager.BackupManager[i].FileName;
SubItems[0] := IL_Format('%s (%d bytes)',[
WinFileInfo.SizeToStr(fILManager.BackupManager[i].Size),
fILManager.BackupManager[i].Size]);
If fILManager.BackupManager[i].SaveVersion <> 0 then
SubItems[1] := IL_Format('%d.%d.%d (build #%d)',[
TILPreloadInfoVersion(fILManager.BackupManager[i].SaveVersion).Major,
TILPreloadInfoVersion(fILManager.BackupManager[i].SaveVersion).Minor,
TILPreloadInfoVersion(fILManager.BackupManager[i].SaveVersion).Release,
TILPreloadInfoVersion(fILManager.BackupManager[i].SaveVersion).Build])
else
SubItems[1] := 'unknown';
If fILManager.BackupManager[i].SaveTime <> 0.0 then
SubItems[2] := IL_FormatDateTime('yyyy-mm-dd hh:nn:ss',fILManager.BackupManager[i].SaveTime)
else
SubItems[2] := 'unknown';
SubItems[3] := IL_FormatDateTime('yyyy-mm-dd hh:nn:ss',fILManager.BackupManager[i].BackupTime);
SubItems[4] := FlagsToStr(fILManager.BackupManager[i].Flags);
end;
finally
lvBackups.Items.EndUpdate;
end;
end;
//------------------------------------------------------------------------------
procedure TfBackupsForm.UpdateTitle;
begin
If fILManager.BackupManager.BackupCount > 0 then
Caption := IL_Format('Backups (%d)',[fILManager.BackupManager.BackupCount])
else
Caption := 'Backups';
end;
//==============================================================================
procedure TfBackupsForm.Initialize(ILManager: TILManager);
begin
fILManager := ILManager;
end;
//------------------------------------------------------------------------------
procedure TfBackupsForm.Finalize;
begin
// nothing to do
end;
//------------------------------------------------------------------------------
procedure TfBackupsForm.ShowBackups;
begin
FillBackupList;
UpdateTitle;
ShowModal;
end;
//==============================================================================
procedure TfBackupsForm.FormCreate(Sender: TObject);
begin
lvBackups.DoubleBuffered := True;
end;
//------------------------------------------------------------------------------
procedure TfBackupsForm.btnOpenBckFolderClick(Sender: TObject);
begin
IL_ShellOpen(Handle,fILManager.BackupManager.StaticSettings.BackupPath);
end;
//------------------------------------------------------------------------------
procedure TfBackupsForm.pmnBackupsPopup(Sender: TObject);
begin
mniBU_Delete.Enabled := lvBackups.ItemIndex >= 0;
mniBU_Restore.Enabled := lvBackups.ItemIndex >= 0;
mniBU_Backup.Enabled := IL_FileExists(fILManager.BackupManager.StaticSettings.ListFile);
end;
//------------------------------------------------------------------------------
procedure TfBackupsForm.mniBU_DeleteClick(Sender: TObject);
begin
If lvBackups.ItemIndex >= 0 then
If MessageDlg(IL_Format('Are you sure you want to delete backup file "%s"?',
[fILManager.BackupManager[lvBackups.ItemIndex].FileName]),
mtConfirmation,[mbOk,mbCancel],0) = mrOK then
begin
fILManager.BackupManager.Delete(lvBackups.ItemIndex);
fILManager.BackupManager.SaveBackups;
FillBackupList;
UpdateTitle;
end;
end;
//------------------------------------------------------------------------------
procedure TfBackupsForm.mniBU_RestoreClick(Sender: TObject);
var
DoBackup: Boolean;
begin
If lvBackups.ItemIndex >= 0 then
begin
If MessageDlg(IL_Format('Are you sure you want to restore file "%s"?' + sLineBreak +
'This will replace current list file with the restored one and restarts this program.',
[fILManager.BackupManager[lvBackups.ItemIndex].FileName]),
mtConfirmation,[mbOk,mbCancel],0) = mrOK then
begin
If IL_FileExists(fILManager.BackupManager.StaticSettings.ListFile) then
DoBackup := MessageDlg('Backup current list before restoring?',mtConfirmation,[mbYes,mbNo],0) = mrYes
else
DoBackup := False;
fILManager.BackupManager.Restore(lvBackups.ItemIndex,DoBackup);
FillBackupList;
UpdateTitle;
Close;
If Assigned(OnRestartRequired) then
OnRestartRequired(Self);
end;
end;
end;
//------------------------------------------------------------------------------
procedure TfBackupsForm.mniBU_BackupClick(Sender: TObject);
begin
If IL_FileExists(fILManager.BackupManager.StaticSettings.ListFile) then
If MessageDlg('Are you sure you want to perform backup right now?',mtConfirmation,[mbOk,mbCancel],0) = mrOK then
begin
fILManager.BackupManager.Backup;
FillBackupList;
UpdateTitle;
end;
end;
end.