-
Notifications
You must be signed in to change notification settings - Fork 9
/
GS.System.Infos.Extended.pas
141 lines (112 loc) · 3.11 KB
/
GS.System.Infos.Extended.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
unit GS.System.Infos.Extended;
interface
Uses Classes, SysUtils,
System.Generics.Collections;
Type
IgsSysInfo = interface
function getPlatform: String;
function getPlatformVer: String;
function getArchitecture: String;
function getDevice: String;
function getExtFieldCount : integer;
function getExtFieldName(index : integer) : string;
function getFieldNames : string;
function getExtFieldValue(fieldName : string) : string;
end;
IgsSysInfoFactory = interface
function GetImplementation : IgsSysInfo;
end;
TGSInfoFactory = Class(TInterfacedObject,IGSSysInfoFactory)
function GetImplementation : IgsSysInfo; virtual; abstract;
End;
//Impl
TgsSysInfoBase = class(TInterfacedObject, IgsSysInfo)
protected
FValues : TStringList;
public
Constructor Create; virtual;
Destructor Destroy; override;
function getPlatform: String; virtual; abstract;
function getPlatformVer: String; virtual; abstract;
function getArchitecture: String; virtual; abstract;
function getDevice: String; virtual; abstract;
function getExtFieldCount : integer;
function getExtFieldName(index : integer) : string;
function getFieldNames : string;
function getExtFieldValue(fieldName : string) : string;
end;
TgsSysInfoImplManager = class
private
class var flist : TDictionary<string,IgsSysInfoFactory>;
class procedure internalCheck;
public
class procedure registerSysInfo(name : String; factory : IGSSysInfoFactory);
class function GetImpl(name : String) : IgsSysInfo;
class function ImplList : string;
class procedure releaseRes;
end;
implementation
{ TgsSysInfoImplManager }
class function TgsSysInfoImplManager.GetImpl(name: String): IgsSysInfo;
var l : IgsSysInfoFactory;
begin
internalCheck;
if flist.TryGetValue(name,l) then
result := l.GetImplementation;
end;
class function TgsSysInfoImplManager.ImplList: string;
var l : TPair<string,IgsSysInfoFactory>;
begin
for l in flist do
result := result + l.Key + sLineBreak;
result := result.Trim;
end;
class procedure TgsSysInfoImplManager.internalCheck;
begin
if Not(assigned(flist)) then
flist := TDictionary<string,IgsSysInfoFactory>.Create;
end;
class procedure TgsSysInfoImplManager.registerSysInfo(name: String;
factory: IGSSysInfoFactory);
begin
internalCheck;
Assert(Assigned(factory));
Assert(name.Trim.Length>0);
flist.Add(name,TGSInfoFactory(factory));
end;
class procedure TgsSysInfoImplManager.releaseRes;
begin
if assigned(flist) then
FreeAndNil(flist);
end;
{ TgsSysInfoBase }
constructor TgsSysInfoBase.Create;
begin
Inherited;
FValues := TStringList.Create;
end;
destructor TgsSysInfoBase.Destroy;
begin
FreeAndNil(FValues);
inherited;
end;
function TgsSysInfoBase.getExtFieldCount: integer;
begin
result := FValues.Count;
end;
function TgsSysInfoBase.getExtFieldName(index: integer): string;
begin
result := FValues.Names[index];
end;
function TgsSysInfoBase.getExtFieldValue(fieldName: string): string;
begin
result := FValues.Values[fieldName];
end;
function TgsSysInfoBase.getFieldNames: string;
begin
result := FValues.Text;
end;
Initialization
Finalization
TgsSysInfoImplManager.releaseRes;
end.