-
Notifications
You must be signed in to change notification settings - Fork 8
/
PrefForm.pas
175 lines (160 loc) · 6.94 KB
/
PrefForm.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
{****************************************************************************}
{ }
{ FIBS Firebird-Interbase Backup Scheduler }
{ }
{ Copyright (c) 2005-2006, Talat Dogan }
{ }
{ This program is free software; you can redistribute it and/or modify it }
{ under the terms of the GNU General Public License as published by the Free }
{ Software Foundation; either version 2 of the License, or (at your option) }
{ any later version. }
{ }
{ This program is distributed in the hope that it will be useful, but }
{ WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY }
{ or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for}
{ more details. }
{ }
{ You should have received a copy of the GNU General Public License along }
{ with this program; if not, write to the Free Software Foundation, Inc., }
{ 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA }
{ }
{ Contact : [email protected]
{ }
{****************************************************************************}
unit PrefForm;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, ExtCtrls, StdCtrls, Buttons, Mask, DBCtrls, ComCtrls,
FibsData, JvComponentBase, JvAppStorage, JvAppRegistryStorage,
JvToolEdit, JvExMask, JvDotNetControls, JvExControls, JvComponent,
JvGroupHeader, JvExExtCtrls, JvBevel, JvExStdCtrls, JvCombobox,
JvCheckBox;
type
TfmPref = class(TForm)
lbGbakDir: TLabel;
lbLogDir: TLabel;
lbBackupPriority: TLabel;
lbMailServer: TLabel;
edSMTPServer: TEdit;
edMailAdress: TEdit;
lbSenderEmail: TLabel;
lbUserName: TLabel;
edUserName: TEdit;
lbPassword: TLabel;
edPassword: TEdit;
Label6: TLabel;
lbMailServerInfo: TLabel;
lbSenderEmailInfo: TLabel;
lbUserNameInfo: TLabel;
lbPasswordInfo: TLabel;
lbArchiveDir: TLabel;
arsAutoRun: TJvAppRegistryStorage;
arsFirebird: TJvAppRegistryStorage;
arsEmail: TJvAppRegistryStorage;
edGbakDir: TJvDirectoryEdit;
edLogDir: TJvDirectoryEdit;
edArchiveDir: TJvDirectoryEdit;
ghGeneral: TJvGroupHeader;
ghSMTPServer: TJvGroupHeader;
JvBevel1: TJvBevel;
btCancel: TButton;
btOK: TButton;
cbBackupPriority: TJvComboBox;
cbAutoRun: TJvCheckBox;
cbFtpPassive: TJvCheckBox;
procedure btOkClick(Sender: TObject);
procedure FormCreate(Sender: TObject);
private
{ Private declarations }
public
procedure LoadPreferences(FibsRef: TdmFibs);
procedure SavePreferences(FibsRef: TdmFibs);
class function ShowPrefs(AOwner: TComponent; FibsRef: TdmFibs): Boolean;
end;
implementation
uses Registry, FileCtrl, ProgressForm, UDFConst, UDFValidation, DB, Soap.EncdDecd;
{$R *.dfm}
class function TfmPref.ShowPrefs(AOwner: TComponent; FibsRef: TdmFibs): Boolean;
var
fmPref: TfmPref;
begin
fmPref := TfmPref.Create(AOwner);
try
fmPref.LoadPreferences(FibsRef);
Result := fmPref.ShowModal = mrOk;
if Result then
fmPref.SavePreferences(FibsRef);
finally
fmPref.Release;
end;
end;
procedure TfmPref.LoadPreferences(FibsRef: TdmFibs);
begin
Self.edGbakDir.Text := FibsRef.qrOptionPATHTOGBAK.Value;
Self.edLogDir.Text := FibsRef.qrOptionLOGDIR.Value;
Self.edArchiveDir.Text := FibsRef.qrOptionARCHIVEDIR.Value;
Self.cbBackupPriority.ItemIndex := Self.cbBackupPriority.Items.IndexOf(FibsRef.qrOptionBPRIORTY.AsString);
Self.cbAutoRun.Checked := FibsRef.qrOptionAUTORUN.AsBoolean;
Self.cbFtpPassive.Checked := FibsRef.qrOptionFTPCONNTYPE.AsBoolean;
Self.edSMTPServer.Text := FibsRef.qrOptionSMTPSERVER.Value;
Self.edMailAdress.Text := FibsRef.qrOptionSENDERSMAIL.Value;
Self.edUserName.Text := FibsRef.qrOptionMAILUSERNAME.Value;
Self.edPassword.Text := Soap.EncdDecd.DecodeString(FibsRef.qrOptionMAILPASSWORD.AsString);
if Length(Trim(Self.edGbakDir.Text)) = 0 then
if Self.arsFirebird.PathExists('DefaultInstance') then
Self.edGbakDir.Text := Self.arsFirebird.ReadString('DefaultInstance') + 'bin';
end;
procedure TfmPref.SavePreferences(FibsRef: TdmFibs);
begin
FibsRef.qrOption.Edit;
FibsRef.qrOptionPATHTOGBAK.Value := Self.edGbakDir.Text;
FibsRef.qrOptionLOGDIR.Value := Self.edLogDir.Text;
FibsRef.qrOptionARCHIVEDIR.Value := Self.edArchiveDir.Text;
FibsRef.qrOptionBPRIORTY.Value := Self.cbBackupPriority.Text;
FibsRef.qrOptionAUTORUN.AsBoolean := Self.cbAutoRun.Checked;
FibsRef.qrOptionFTPCONNTYPE.AsBoolean := Self.cbFtpPassive.Checked;
FibsRef.qrOptionSMTPSERVER.Value := Self.edSMTPServer.Text;
FibsRef.qrOptionSENDERSMAIL.Value := Self.edMailAdress.Text;
FibsRef.qrOptionMAILUSERNAME.Value := Self.edUserName.Text;
FibsRef.qrOptionMAILPASSWORD.Value := Soap.EncdDecd.EncodeString(Self.edPassword.Text);
FibsRef.qrOption.Post;
try
if Self.cbAutoRun.Checked then
Self.arsAutoRun.WriteString('FIBS_Backup_Scheduler', System.ParamStr(0))
else
Self.arsAutoRun.DeleteValue('FIBS_Backup_Scheduler');
except
on E: Exception do
MessageDlg('Could not save in the Windows registry!' + #13#10 + E.Message, mtError, [mbOk], 0);
end;
end;
procedure TfmPref.FormCreate(Sender: TObject);
begin
Self.edLogDir.Text := DataFilesPath;
end;
procedure TfmPref.btOkClick(Sender: TObject);
var
vaValidation: TValidation;
begin
vaValidation := TValidation.Create(Self);
try
if Length(Trim(Self.edGbakDir.Text)) = 0 then
vaValidation.Add('Directory Name cannot be empty!', vtWarning);
if not SysUtils.DirectoryExists(Self.edGbakDir.Text) then
vaValidation.Add('There is No Directory given name!', vtWarning);
if not SysUtils.FileExists(Self.edGbakDir.Text + '\gbak.exe') then
vaValidation.Add('Gbak.exe cannot be found onto given dir!', vtWarning);
if Length(Trim(Self.edLogDir.Text)) = 0 then
vaValidation.Add('LOG Directory Name cannot be empty!', vtWarning);
if not SysUtils.DirectoryExists(Self.edLogDir.Text) then
vaValidation.Add('Given LOG Directory is not exists!', vtWarning);
if vaValidation.ShowModal then
Self.ModalResult := mrOk
else
Self.ModalResult := mrNone;
finally
vaValidation.Free;
end;
end;
end.