forked from Memnarch/Delphinus
-
Notifications
You must be signed in to change notification settings - Fork 0
/
DN.Settings.pas
152 lines (133 loc) · 3.6 KB
/
DN.Settings.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
unit DN.Settings;
interface
uses
DN.Settings.Intf;
type
TDNSettings = class(TInterfacedObject, IDNSettings, IDNElevatedSettings)
private
function ReadString(const AValueName: string): string;
procedure WriteString(const AValueName, AContent: string);
function GetInstallationDirectory: string;
function GetOAuthToken: string;
procedure SetInstallationDirectory(const Value: string);
procedure SetOAuthToken(const Value: string);
function GetVersion: string;
procedure SetVersion(const Value: string);
function GetInstallDate: TDateTime;
procedure SetInstallDate(const Value: TDateTime);
public
procedure Clear();
property InstallationDirectory: string read GetInstallationDirectory write SetInstallationDirectory;
property OAuthToken: string read GetOAuthToken write SetOAuthToken;
property Version: string read GetVersion write SetVersion;
property InstallDate: TDateTime read GetInstallDate write SetInstallDate;
end;
implementation
uses
Windows,
Registry,
SysUtils,
DateUtils,
StrUtils;
const
CInstallationDirectory = 'InstallationDirectory';
COAuthToken = 'OAuthToken';
CVersion = 'Version';
CInstallDate = 'InstallDate';
CDelphinusKey = 'Software\Delphinus';
CRootKey = HKEY_CURRENT_USER;
CDateFormat = 'yyyy-mm-dd';
CDateSeperator = '-';
CTimeFormat = 'hh:nn:ss:zzz';
CTimeSeperator = ':';
CDateTimeFormat = CDateFormat + ' ' + CTimeFormat;
{ TDNSettings }
procedure TDNSettings.Clear;
var
LRegistry: TRegistry;
begin
LRegistry := TRegistry.Create();
try
LRegistry.RootKey := CRootKey;
LRegistry.DeleteKey(CDelphinusKey)
finally
LRegistry.Free;
end;
end;
function TDNSettings.GetInstallationDirectory: string;
begin
Result := ReadString(CInstallationDirectory)
end;
function TDNSettings.GetInstallDate: TDateTime;
var
LDate: string;
LSettings: TFormatSettings;
begin
LDate := ReadString(CInstallDate);
if LDate <> '' then
begin
LSettings := TFormatSettings.Create();
LSettings.ShortDateFormat := CDateFormat;
LSettings.DateSeparator := CDateSeperator;
LSettings.LongTimeFormat := CTimeFormat;
LSettings.TimeSeparator := CTimeSeperator;
Result := StrToDateTimeDef(LDate, 0, LSettings);
end
else
Result := 0;
end;
function TDNSettings.GetOAuthToken: string;
begin
Result := ReadString(COAuthToken);
end;
function TDNSettings.GetVersion: string;
begin
Result := ReadString(CVersion);
end;
function TDNSettings.ReadString(const AValueName: string): string;
var
LRegistry: TRegistry;
begin
Result := '';
LRegistry := TRegistry.Create();
try
LRegistry.RootKey := CRootKey;
if LRegistry.OpenKeyReadOnly(CDelphinusKey) then
begin
if LRegistry.ValueExists(AValueName) then
Result := LRegistry.ReadString(AValueName);
end;
finally
LRegistry.Free;
end;
end;
procedure TDNSettings.SetInstallationDirectory(const Value: string);
begin
WriteString(CInstallationDirectory, Value);
end;
procedure TDNSettings.SetInstallDate(const Value: TDateTime);
begin
WriteString(CInstallDate, FormatDateTime(CDateTimeFormat, Value));
end;
procedure TDNSettings.SetOAuthToken(const Value: string);
begin
WriteString(COAuthToken, Value);
end;
procedure TDNSettings.SetVersion(const Value: string);
begin
WriteString(CVersion, Value);
end;
procedure TDNSettings.WriteString(const AValueName, AContent: string);
var
LRegistry: TRegistry;
begin
LRegistry := TRegistry.Create();
try
LRegistry.RootKey := CRootKey;
if LRegistry.OpenKey(CDelphinusKey, True) then
LRegistry.WriteString(AValueName, AContent);
finally
LRegistry.Free;
end;
end;
end.