-
Notifications
You must be signed in to change notification settings - Fork 7
/
CMW.ModuleStruct.pas
296 lines (257 loc) · 7.09 KB
/
CMW.ModuleStruct.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
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
unit CMW.ModuleStruct;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls,
System.IniFiles, Dialogs, ComCtrls, TLHelp32, PSAPI, Vcl.StdCtrls, CMW.OSInfo,
System.Win.Registry;
type
TGlobalState = (gsNone, gsProcess, gsFinished, gsStopped, gsError);
TGetState = (gsIsNotGetted, gsIsGetted, gsGetting, gsCantGet);
TInformProc = procedure(Value: string) of object;
TStateProc = procedure(Value: TGlobalState) of object;
TOnSetCurElement = procedure(var Value: string) of object;
TProc = procedure of object;
TTypeOfItem = (tiNone, tiAutorun, tiApp, tiEvent, tiProcess, tiService, tiTask, tiWindow);
TListItemData = record
ItemType: TTypeOfItem;
ItemData: Pointer;
end;
TMainThread = class(TThread)
private
FProc: TProc;
FUpd: TProc;
FEnable: Boolean;
function FTermed: Boolean;
public
property Termed: Boolean read FTermed;
procedure Execute; override;
procedure ExecuteUpdate(Sender: TObject);
property Proc: TProc read FProc write FProc;
property Enable: Boolean read FEnable write FEnable;
end;
TSystemUnit = class
Roll: TRegistry;
FName: string;
FRootAccess: Cardinal;
//FHandler:TSmart
FRestrictions: Boolean;
FInform: TInformProc;
FStateProc: TStateProc;
FStop: Boolean;
FState: TGlobalState;
FLoadIcons: Boolean;
FListView: TListView;
FLabelCount: TLabel;
FGrouping: Boolean;
FCurrentOS: TCurrentOS;
FColumnSort: Integer;
FIncreasingSort: Boolean;
//FMainThread:TMainThread;
function Save(Ini: TIniFile): Boolean; virtual;
function Load(Ini: TIniFile): Boolean; virtual;
procedure Stop; virtual;
procedure Inform(Value: string); virtual;
procedure SetListView(Value: TListView); virtual;
procedure OnChanged; virtual;
function Stopping: Boolean; virtual;
function FGet: TGlobalState; virtual; abstract;
procedure ListViewColumnSortClick(Sender: TObject; Column: TListColumn);
procedure OnListViewSort;
private
procedure FThreadGet;
procedure SetLabelCount(const Value: TLabel);
public
procedure SetStateToPB;
procedure SetGlState(Value: TGlobalState);
procedure Initialize; virtual; abstract;
procedure Get; virtual;
constructor Create; virtual;
destructor Destroy; override;
property RootAccess: Cardinal read FRootAccess;
property ListView: TListView read FListView write SetListView;
property Restrictions: Boolean read FRestrictions;
property HandleInform: TInformProc read FInform write FInform;
property StateProc: TStateProc read FStateProc write FStateProc;
property LabelCount: TLabel read FLabelCount write SetLabelCount;
property State: TGlobalState read FState;
property LoadIcons: Boolean read FLoadIcons write FLoadIcons default True;
property CurrentOSLink: TCurrentOS read FCurrentOS write FCurrentOS;
property Grouping: Boolean read FGrouping write FGrouping;
property Name: string read FName write FName;
end;
function SetListItemData(AType: TTypeOfItem; AData: Pointer): Pointer;
implementation
uses
CMW.Utils, Forms;
function SetListItemData(AType: TTypeOfItem; AData: Pointer): Pointer;
begin
Result := AllocMem(SizeOf(TListItemData));
with TListItemData(Result^) do
begin
ItemType := AType;
ItemData := AData;
end;
end;
function TMainThread.FTermed: Boolean;
begin
Result := Terminated;
end;
procedure TMainThread.ExecuteUpdate(Sender: TObject);
begin
if FEnable then
if Assigned(FProc) then
FProc();
end;
procedure TMainThread.Execute;
begin
Log(['mon init']);
end;
procedure TSystemUnit.FThreadGet;
begin
//ShowMessage(Self.FName);
if (FState = gsProcess) and (not FStop) then
Exit;
SetGlState(gsProcess);
FState := gsProcess;
FStop := False;
try
try
FState := FGet;
finally
begin
ListView.Items.EndUpdate;
//Self.Suspend;
end;
end;
except
FState := gsError;
end;
if FState = gsProcess then
begin
Log(['Ïîëó÷åí ôëàã î íåçàâåðøåííîñòè ïðîöåññà FState = gsProcess is', FState = gsProcess, GetLastError]);
MessageBox(Application.Handle, 'Ïðîöåññ íåáûë óñïåøíî çàâåðø¸í. Ðåêîìåíäóþ ïîâòîðèòü.', 'Âíèìàíèå', MB_ICONWARNING or MB_OK);
FState := gsError;
FStop := True;
end;
if FState = gsStopped then
begin
Inform(LangText(-1, 'Ïðîöåññ îñòàíîâëåí.'));
end;
SetGlState(FState);
//if FMainThread <> nil then FMainThread.Terminate;
end;
procedure TSystemUnit.SetLabelCount(const Value: TLabel);
begin
FLabelCount := Value;
FLabelCount.Caption := 'Ýëåìåíòîâ: íå èçâåñòíî';
end;
procedure TSystemUnit.SetListView(Value: TListView);
begin
if Assigned(FListView) then
FListView.Free;
FListView := Value;
FListView.OnColumnClick := ListViewColumnSortClick;
end;
procedure TSystemUnit.ListViewColumnSortClick(Sender: TObject; Column: TListColumn);
begin
if Column.Index - 1 = FColumnSort then
FIncreasingSort := not FIncreasingSort
else
FColumnSort := Column.Index - 1;
OnListViewSort;
end;
procedure TSystemUnit.OnListViewSort;
begin
if FIncreasingSort then
FListView.Tag := 0
else
FListView.Tag := 1;
FListView.CustomSort(@CustomUniSortProc, FColumnSort);
if FListView.Groups.Count = 1 then
FListView.Groups[0].State := FListView.Groups[0].State - [lgsCollapsed];
end;
function TSystemUnit.Save(Ini: TIniFile): Boolean;
begin
Result := True;
end;
function TSystemUnit.Load(Ini: TIniFile): Boolean;
begin
Result := True;
end;
function TSystemUnit.Stopping: Boolean;
begin
Application.ProcessMessages;
Result := FStop;
end;
procedure TSystemUnit.SetStateToPB;
begin
if Assigned(FStateProc) then
FStateProc(FState);
end;
procedure TSystemUnit.SetGlState(Value: TGlobalState);
begin
FState := Value;
if Assigned(FStateProc) then
FStateProc(Value);
end;
procedure TSystemUnit.OnChanged;
begin
if Assigned(FLabelCount) then
FLabelCount.Caption := 'Ýëåìåíòîâ: ' + IntToStr(FListView.Items.Count);
end;
procedure TSystemUnit.Inform(Value: string);
begin
if not Assigned(FInform) then
Exit;
FInform(Value);
end;
destructor TSystemUnit.Destroy;
begin
if not Assigned(FListView.Owner) then FListView.Free;
Roll.Free;
inherited;
end;
constructor TSystemUnit.Create;
begin
inherited Create;
FState := gsNone;
FRestrictions := True;
FColumnSort := -1;
FIncreasingSort := True;
if (Info.Bits = x64) and (AppBits = x32) then
FRootAccess := KEY_ALL_ACCESS or KEY_WOW64_64KEY
else
FRootAccess := KEY_ALL_ACCESS;
try
Roll := TRegistry.Create(FRootAccess);
FRestrictions := False;
except
FRestrictions := True;
end;
if FRestrictions then
try
if (Info.Bits = x64) and (AppBits = x32) then
FRootAccess := KEY_READ or KEY_WOW64_64KEY
else
FRootAccess := KEY_READ;
Roll := TRegistry.Create(FRootAccess);
FRestrictions := False;
except
FRestrictions := True;
end;
FListView := TListView.Create(nil);
with FListView do
begin
Name := 'FListView';
OnColumnClick := ListViewColumnSortClick;
end;
end;
procedure TSystemUnit.Stop;
begin
FStop := True;
end;
procedure TSystemUnit.Get;
begin
FThreadGet;
end;
end.