-
Notifications
You must be signed in to change notification settings - Fork 29
/
Copy pathuConfig.pas
181 lines (164 loc) · 5.15 KB
/
uConfig.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
unit uConfig;
interface
uses Classes;
type
TTimeDisplay = (tdMs, tdPercent);
(**
* Holds configuration options and other system-wide data
* (sorry, no user-specific stuff).
*)
TConfig = class
private
FMRU: TStringList;
FMRUTitles: TStringList;
FClearMRUOnExit: Boolean;
FHideLibFuncs: Boolean;
FTrackMRU: Boolean;
FShowFullPath: Boolean;
FTimeDisplay: TTimeDisplay;
FMaxMRUCount: Integer;
FWorkingDir: string;
FHideFastFuncs: Boolean;
FFastThreshold: Integer;
FEditorPath: string;
procedure SetMaxMRUCount(const Value: Integer);
public
property ClearMRUOnExit: Boolean read FClearMRUOnExit write FClearMRUOnExit;
property FastThreshold: Integer read FFastThreshold write FFastThreshold;
property HideFastFuncs: Boolean read FHideFastFuncs write FHideFastFuncs;
property HideLibFuncs: Boolean read FHideLibFuncs write FHideLibFuncs;
property MaxMRUCount: Integer read FMaxMRUCount write SetMaxMRUCount;
property MRU: TStringList read FMRU;
property MRUTitles: TStringList read FMRUTitles;
property TimeDisplay: TTimeDisplay read FTimeDisplay write FTimeDisplay;
property TrackMRU: Boolean read FTrackMRU write FTrackMRU;
property ShowFullPath: Boolean read FShowFullPath write FShowFullPath;
property WorkingDir: string read FWorkingDir write FWorkingDir;
property EditorPath: string read FEditorPath write FEditorPath;
procedure AddMRU(AFileName, ATitle: string);
procedure ClearMRU;
constructor Create;
destructor Destroy; override;
procedure Load;
procedure PurgeMRU;
procedure Save;
end;
implementation
uses IniFiles, SysUtils, Forms, ShlObj;
{ TConfig }
(**
* Adds an MRU entry.
*
* Note that this function will do nothing if TrackMRU is disabled.
*)
procedure TConfig.AddMRU(AFileName, ATitle: string);
begin
if not TrackMRU then Exit;
if MRU.IndexOf(AFileName) >= 0 then begin
MRUTitles.Delete(MRU.IndexOf(AFileName));
MRU.Delete(MRU.IndexOf(AFileName));
end;
MRU.Insert(0, AFileName);
MRUTitles.Insert(0, ATitle);
PurgeMRU;
end;
procedure TConfig.ClearMRU;
begin
MRU.Clear;
MRUTitles.Clear;
end;
constructor TConfig.Create;
begin
FMRU := TStringList.Create;
FMRUTitles := TStringList.Create;
// set defaults
TimeDisplay := tdMs;
TrackMRU := True;
MaxMRUCount := 4;
FastThreshold := 1;
end;
destructor TConfig.Destroy;
begin
FMRUTitles.Free;
FMRU.Free;
inherited;
end;
procedure TConfig.Load;
var
F: TIniFile;
I: Integer;
begin
F := TIniFile.Create(ExtractFilePath(Application.ExeName) + 'WinCacheGrind.ini');
try
// Main
WorkingDir := F.ReadString('Main', 'WorkingDir', WorkingDir);
// Display
TimeDisplay := TTimeDisplay(F.ReadInteger('Display', 'TimeDisplay', Ord(TimeDisplay)));
HideFastFuncs := F.ReadBool('Display', 'HideFastFuncs', HideFastFuncs);
FastThreshold := F.ReadInteger('Display', 'FastThreshold', FastThreshold);
HideLibFuncs := F.ReadBool('Display', 'HideLibFuncs', HideLibFuncs);
ShowFullPath := F.ReadBool('Display', 'ShowFullPath', ShowFullPath);
// Privacy
TrackMRU := F.ReadBool('Privacy', 'TrackMRU', TrackMRU);
ClearMRUOnExit := F.ReadBool('Privacy', 'ClearMRUOnExit', ClearMRUOnExit);
MaxMRUCount := F.ReadInteger('Privacy', 'MaxMRUCount', MaxMRUCount);
// MRU
ClearMRU;
for I := 0 to F.ReadInteger('MRU', 'Count', 0) - 1 do begin
MRU.Add(F.ReadString('MRU', 'Entry' + IntToStr(I), ''));
MRUTitles.Add(F.ReadString('MRU', 'Title' + IntToStr(I), 'Untitled'));
end;
//editor
EditorPath := F.ReadString('Editor', 'EditorPath', '');
finally
F.Free;
end;
end;
(**
* Deletes excessive MRU entries.
*)
procedure TConfig.PurgeMRU;
begin
while MRU.Count > MaxMRUCount do begin
MRU.Delete(MRU.Count - 1);
MRUTitles.Delete(MRUTitles.Count - 1);
end;
end;
procedure TConfig.Save;
var
F: TIniFile;
I: Integer;
begin
F := TIniFile.Create(ExtractFilePath(Application.ExeName) + 'WinCacheGrind.ini');
try
// Main
F.WriteString('Main', 'WorkingDir', WorkingDir);
// Display
F.WriteInteger('Display', 'TimeDisplay', Ord(TimeDisplay));
F.WriteBool('Display', 'HideFastFuncs', HideFastFuncs);
F.WriteInteger('Display', 'FastThreshold', FastThreshold);
F.WriteBool('Display', 'HideLibFuncs', HideLibFuncs);
F.WriteBool('Display', 'ShowFullPath', ShowFullPath);
// Privacy
F.WriteBool('Privacy', 'TrackMRU', TrackMRU);
F.WriteBool('Privacy', 'ClearMRUOnExit', ClearMRUOnExit);
F.WriteInteger('Privacy', 'MaxMRUCount', MaxMRUCount);
// MRU
F.EraseSection('MRU');
F.WriteInteger('MRU', 'Count', MRU.Count);
for I := 0 to MRU.Count - 1 do begin
F.WriteString('MRU', 'Entry' + IntToStr(I), MRU[I]);
F.WriteString('MRU', 'Title' + IntToStr(I), MRUTitles[I]);
end;
//editor
F.WriteString('Editor', 'EditorPath', EditorPath);
finally
F.Free;
end;
end;
procedure TConfig.SetMaxMRUCount(const Value: Integer);
begin
FMaxMRUCount := Value;
PurgeMRU;
end;
end.