forked from vladk1973/npp.connections
-
Notifications
You must be signed in to change notification settings - Fork 0
/
regUnit.pas
242 lines (213 loc) · 6.47 KB
/
regUnit.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
238
239
240
241
242
unit regUnit;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, NppForms, StdCtrls, Buttons, ExtCtrls,
ConstUnit,
{$IFNDEF NPPCONNECTIONS}diaConstUnit,{$ENDIF}
IniFiles, Registry, System.Actions;
type
TOptionsReg = class
public
procedure SaveConnectToString(bd: TBdType; const Key,Value: string);
function GetConnectToList(bd: TBdType): TStringList;
class function GetConnectionString(bd: TBdType): string;
{$IFNDEF NPPCONNECTIONS}
class function GetPostgreSQLConvertString: string;
{$ENDIF}
class procedure SaveFavoriteConnection(bd: TBdType; const Key,Value: string);
class procedure DeleteFavoriteConnection(bd: TBdType; const Value: string);
class function GetFavoriteList(bd: TBdType): TStringList;
class function GetVisibleStatusBDButton(bd: TBdType): boolean;
class procedure SetVisibleStatusBDButton(bd: TBdType; const Value: boolean);
end;
implementation
{ TOptionsReg }
function TOptionsReg.GetConnectToList(bd: TBdType): TStringList;
var
i: Integer;
Registry: TRegistry;
Servers: TStringList;
begin
Registry := TRegistry.Create(KEY_READ);
Result := TStringList.Create;
Servers := TStringList.Create;
try
Registry.RootKey := HKEY_CURRENT_USER;
if Registry.OpenKeyReadOnly(cnstDllKey + '\' + constLoginBDCaptionArray[bd] + '\ConnectTo') then
Registry.GetValueNames(Servers);
if Servers.Count = 0 then Exit;
Servers.Sorted := True;
for i := 0 to Servers.Count - 1 do
begin
Result.Add(Registry.ReadString(Servers[i]));
end;
finally
Registry.CloseKey;
Registry.Free;
Servers.Free;
end;
end;
class function TOptionsReg.GetFavoriteList(bd: TBdType): TStringList;
var
i: Integer;
Registry: TRegistry;
Servers: TStringList;
begin
Registry := TRegistry.Create(KEY_READ);
Result := TStringList.Create;
Servers := TStringList.Create;
try
Registry.RootKey := HKEY_CURRENT_USER;
if Registry.OpenKeyReadOnly(cnstDllKey + '\' + constLoginBDCaptionArray[bd] + '\Favorite') then
Registry.GetValueNames(Servers);
if Servers.Count = 0 then Exit;
Servers.Sorted := True;
for i := 0 to Servers.Count - 1 do
begin
Result.Add(Registry.ReadString(Servers[i]));
end;
finally
Registry.CloseKey;
Registry.Free;
Servers.Free;
end;
end;
{$IFNDEF NPPCONNECTIONS}
class function TOptionsReg.GetPostgreSQLConvertString: string;
var
S: string;
Registry: TRegistry;
begin
S := '';
Registry := TRegistry.Create(KEY_ALL_ACCESS);
try
Registry.RootKey := HKEY_CURRENT_USER;
Registry.CreateKey(cnstDllKey + '\' + constLoginBDCaptionArray[bdPostgreSQL] + '\Conversion');
if Registry.OpenKey(cnstDllKey + '\' + constLoginBDCaptionArray[bdPostgreSQL] + '\Conversion',True) then
S := Registry.ReadString('ConversionString');
if S = '' then
begin
S := cnstConvert;
Registry.WriteString('ConversionString', S);
end;
finally
Registry.CloseKey;
Registry.Free;
end;
Result := S;
end;
{$ENDIF}
class function TOptionsReg.GetVisibleStatusBDButton(bd: TBdType): boolean;
var
Registry: TRegistry;
begin
Result := True;
Registry := TRegistry.Create(KEY_READ);
try
Registry.RootKey := HKEY_CURRENT_USER;
if Registry.OpenKeyReadOnly(cnstDllKey + '\' + constLoginBDCaptionArray[bd] + '\Visible\') then
Result := Registry.ReadBool('Visible');
finally
Registry.CloseKey;
Registry.Free;
end;
end;
class procedure TOptionsReg.SetVisibleStatusBDButton(bd: TBdType;
const Value: boolean);
var
Registry: TRegistry;
begin
Registry := TRegistry.Create(KEY_WRITE or KEY_WOW64_64KEY);
try
try
Registry.RootKey := HKEY_CURRENT_USER;
Registry.CreateKey(cnstDllKey + '\' + constLoginBDCaptionArray[bd] + '\Visible');
if Registry.OpenKey(cnstDllKey + '\' + constLoginBDCaptionArray[bd] + '\Visible',True) then
Registry.WriteBool('Visible', Value);
finally
Registry.CloseKey;
end;
finally
Registry.Free;
end;
end;
class procedure TOptionsReg.DeleteFavoriteConnection(bd: TBdType; const Value: string);
var
Registry: TRegistry;
Deleted: boolean;
begin
Registry := TRegistry.Create(KEY_ALL_ACCESS or KEY_WOW64_64KEY);
try
try
Registry.RootKey := HKEY_CURRENT_USER;
if Registry.OpenKey(cnstDllKey + '\' + constLoginBDCaptionArray[bd] + '\Favorite',True) then
Deleted := Registry.DeleteValue(Value);
finally
Registry.CloseKey;
end;
finally
Registry.Free;
end;
end;
class function TOptionsReg.GetConnectionString(bd: TBdType): string;
var
S: string;
Registry: TRegistry;
begin
S := '';
Registry := TRegistry.Create(KEY_ALL_ACCESS);
try
Registry.RootKey := HKEY_CURRENT_USER;
Registry.CreateKey(cnstDllKey + '\' + constLoginBDCaptionArray[bd] + '\Connection');
if Registry.OpenKey(cnstDllKey + '\' + constLoginBDCaptionArray[bd] + '\Connection',True) then
S := Registry.ReadString('ConnectionString');
if S = '' then
begin
S := constConnectionStringArray[bd];
Registry.WriteString('ConnectionString', S);
end;
finally
Registry.CloseKey;
Registry.Free;
end;
Result := S;
end;
procedure TOptionsReg.SaveConnectToString(bd: TBdType; const Key,Value: string);
var
Registry: TRegistry;
begin
Registry := TRegistry.Create(KEY_WRITE or KEY_WOW64_64KEY);
try
try
Registry.RootKey := HKEY_CURRENT_USER;
Registry.CreateKey(cnstDllKey + '\' + constLoginBDCaptionArray[bd] + '\ConnectTo');
if Registry.OpenKey(cnstDllKey + '\' + constLoginBDCaptionArray[bd] + '\ConnectTo',True) then
Registry.WriteString(Key, Value);
finally
Registry.CloseKey;
end;
finally
Registry.Free;
end;
end;
class procedure TOptionsReg.SaveFavoriteConnection(bd: TBdType; const Key,
Value: string);
var
Registry: TRegistry;
begin
Registry := TRegistry.Create(KEY_WRITE or KEY_WOW64_64KEY);
try
try
Registry.RootKey := HKEY_CURRENT_USER;
Registry.CreateKey(cnstDllKey + '\' + constLoginBDCaptionArray[bd] + '\Favorite');
if Registry.OpenKey(cnstDllKey + '\' + constLoginBDCaptionArray[bd] + '\Favorite',True) then
Registry.WriteString(Key, Value);
finally
Registry.CloseKey;
end;
finally
Registry.Free;
end;
end;
end.