1 |
tony |
209 |
(* |
2 |
|
|
* IBX For Lazarus (Firebird Express) |
3 |
|
|
* |
4 |
|
|
* The contents of this file are subject to the Initial Developer's |
5 |
|
|
* Public License Version 1.0 (the "License"); you may not use this |
6 |
|
|
* file except in compliance with the License. You may obtain a copy |
7 |
|
|
* of the License here: |
8 |
|
|
* |
9 |
|
|
* http://www.firebirdsql.org/index.php?op=doc&id=idpl |
10 |
|
|
* |
11 |
|
|
* Software distributed under the License is distributed on an "AS |
12 |
|
|
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or |
13 |
|
|
* implied. See the License for the specific language governing rights |
14 |
|
|
* and limitations under the License. |
15 |
|
|
* |
16 |
|
|
* The Initial Developer of the Original Code is Tony Whyman. |
17 |
|
|
* |
18 |
|
|
* The Original Code is (C) 2014 Tony Whyman, MWA Software |
19 |
|
|
* (http://www.mwasoftware.co.uk). |
20 |
|
|
* |
21 |
|
|
* All Rights Reserved. |
22 |
|
|
* |
23 |
|
|
* Contributor(s): ______________________________________. |
24 |
|
|
* |
25 |
|
|
*) |
26 |
|
|
unit IBXSaveDatabaseDlg; |
27 |
|
|
|
28 |
|
|
interface |
29 |
|
|
|
30 |
|
|
{$mode objfpc}{$H+} |
31 |
|
|
|
32 |
|
|
uses |
33 |
|
|
LCLIntf, LCLType, SysUtils, Variants, Classes, Graphics, Controls, Forms, |
34 |
|
|
Dialogs, IBXServices, StdCtrls, ExtCtrls; |
35 |
|
|
|
36 |
|
|
type |
37 |
|
|
|
38 |
|
|
{ TSaveDatabaseDlg } |
39 |
|
|
|
40 |
|
|
TSaveDatabaseDlg = class(TForm) |
41 |
|
|
IBBackupService1: TIBXServerSideBackupService; |
42 |
|
|
Panel1: TPanel; |
43 |
|
|
Status: TLabel; |
44 |
|
|
Label1: TLabel; |
45 |
|
|
SaveDialog1: TSaveDialog; |
46 |
|
|
Timer1: TTimer; |
47 |
|
|
procedure FormShow(Sender: TObject); |
48 |
|
|
procedure IBBackupService1GetNextLine(Sender: TObject; var Line: string); |
49 |
|
|
procedure Timer1Timer(Sender: TObject); |
50 |
|
|
private |
51 |
|
|
{ Private declarations } |
52 |
|
|
procedure DoBackup(Data: PtrInt); |
53 |
|
|
public |
54 |
|
|
{ Public declarations } |
55 |
|
|
end; |
56 |
|
|
|
57 |
|
|
var |
58 |
|
|
SaveDatabaseDlg: TSaveDatabaseDlg; |
59 |
|
|
|
60 |
|
|
function SaveDatabaseToArchive(aBackupService: TIBXServerSideBackupService; aFilename: string): boolean; |
61 |
|
|
|
62 |
|
|
implementation |
63 |
|
|
|
64 |
|
|
uses Registry; |
65 |
|
|
|
66 |
|
|
{$IFDEF WINDOWS} |
67 |
|
|
const |
68 |
|
|
rgShellFolders = 'Software\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders'; |
69 |
|
|
rgPersonal = 'Personal'; |
70 |
|
|
{$ENDIF} |
71 |
|
|
|
72 |
|
|
function SaveDatabaseToArchive(aBackupService: TIBXServerSideBackupService; |
73 |
|
|
aFilename: string): boolean; |
74 |
|
|
begin |
75 |
|
|
with TSaveDatabaseDlg.Create(Application) do |
76 |
|
|
try |
77 |
|
|
if aFilename = '' then |
78 |
|
|
begin |
79 |
|
|
SaveDialog1.InitialDir := GetUserDir; |
80 |
|
|
{$IFDEF WINDOWS} |
81 |
|
|
with TRegistry.Create do |
82 |
|
|
try |
83 |
|
|
if OpenKey(rgShellFolders,false) then |
84 |
|
|
begin |
85 |
|
|
SaveDialog1.InitialDir := ReadString(rgPersonal) |
86 |
|
|
end; |
87 |
|
|
finally |
88 |
|
|
Free |
89 |
|
|
end; |
90 |
|
|
{$ENDIF} |
91 |
|
|
if SaveDialog1.Execute then |
92 |
|
|
aFilename := SaveDialog1.FileName |
93 |
|
|
else |
94 |
|
|
Exit; |
95 |
|
|
end; |
96 |
|
|
IBBackupService1.Assign(aBackupService); |
97 |
|
|
IBBackupService1.BackupFiles.Clear; |
98 |
|
|
IBBackupService1.BackupFiles.Add(aFileName); |
99 |
|
|
Result := ShowModal = mrOK |
100 |
|
|
finally |
101 |
|
|
Free |
102 |
|
|
end; |
103 |
|
|
end; |
104 |
|
|
|
105 |
|
|
{$R *.lfm} |
106 |
|
|
|
107 |
|
|
{ TSaveDatabaseDlg } |
108 |
|
|
|
109 |
|
|
procedure TSaveDatabaseDlg.FormShow(Sender: TObject); |
110 |
|
|
begin |
111 |
|
|
Status.Caption := ''; |
112 |
|
|
Application.QueueAsyncCall(@DoBackup,0); |
113 |
|
|
end; |
114 |
|
|
|
115 |
|
|
procedure TSaveDatabaseDlg.IBBackupService1GetNextLine(Sender: TObject; |
116 |
|
|
var Line: string); |
117 |
|
|
begin |
118 |
|
|
Status.Caption := Line; |
119 |
|
|
Application.ProcessMessages; |
120 |
|
|
end; |
121 |
|
|
|
122 |
|
|
procedure TSaveDatabaseDlg.Timer1Timer(Sender: TObject); |
123 |
|
|
begin |
124 |
|
|
Timer1.Interval := 0; |
125 |
|
|
if FileExists(IBBackupService1.BackupFiles[0]) then |
126 |
|
|
ModalResult := mrOK |
127 |
|
|
else |
128 |
|
|
ModalResult := mrCancel |
129 |
|
|
end; |
130 |
|
|
|
131 |
|
|
procedure TSaveDatabaseDlg.DoBackup(Data: PtrInt); |
132 |
|
|
begin |
133 |
|
|
try |
134 |
|
|
IBBackupService1.Execute(nil); |
135 |
|
|
except |
136 |
|
|
ModalResult := mrCancel; |
137 |
|
|
raise |
138 |
|
|
end; |
139 |
|
|
Timer1.Interval := 500; |
140 |
|
|
end; |
141 |
|
|
|
142 |
|
|
end. |