-
Notifications
You must be signed in to change notification settings - Fork 14
/
Versions.Info.pas
182 lines (157 loc) · 5.54 KB
/
Versions.Info.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
unit Versions.Info;
interface
uses
Winapi.Windows, System.SysUtils,
Versions;
type
LANGANDCODEPAGE = record
wLanguage: Word;
wCodePage: Word;
end;
TVersionInfo = class
private
class var FFileName: TFileName;
class var FLanguageInfo: string;
class var FCompanyName: string;
class var FFileDescription: string;
class var FFileVersion: TVersion;
class var FInternalName: string;
class var FLegalCopyright: string;
class var FOriginalFileName: string;
class var FProductName: string;
class var FProductVersion: TVersion;
class var FComments: string;
class var FBinaryType: DWORD;
class procedure SetFileName(const Value: TFileName); static;
class function GetBinaryTypeAsString: string; static;
class function GetBinaryTypeAsShortString: string; static;
class procedure Load; static;
class procedure Clear; static;
class constructor Create;
public
class function GetBuildOnly: string; static;
class function GetRealFileName: string; static;
class property FileName: TFileName read FFileName write SetFileName;
class property LanguageInfo: string read FLanguageInfo;
class property CompanyName: string read FCompanyName;
class property FileDescription: string read FFileDescription;
class property FileVersion: TVersion read FFileVersion;
class property InternalName: string read FInternalName;
class property LegalCopyright: string read FLegalCopyright;
class property OriginalFileName: string read FOriginalFileName;
class property ProductName: string read FProductName;
class property ProductVersion: TVersion read FProductVersion;
class property Comments: string read FComments;
class property BinaryType: DWORD read FBinaryType;
class property BinaryTypeAsString: string read GetBinaryTypeAsString;
class property BinaryTypeAsShortString: string read GetBinaryTypeAsShortString;
end;
implementation
uses
Winapi.Messages, System.Classes;
{ TVersionInfo }
class function TVersionInfo.GetBuildOnly: string;
var
Delimiter: Integer;
begin
Delimiter:= LastDelimiter('.', FFileVersion);
Result:= Copy(FFileVersion, Delimiter + 1, Length(FFileVersion) - Delimiter);
end;
class function TVersionInfo.GetRealFileName: string;
var
nSize: DWORD;
begin
nSize := MAX_PATH;
SetLength(Result, nSize);
nSize:= GetModuleFileName(0, LPTSTR(Result), nSize);
if nSize <> 0 then
SetLength(Result, nSize)
else
Result := '';
end;
class procedure TVersionInfo.Load;
var
VInfo, Trans: Pointer;
VInfoSize, Handle: DWORD;
TransSize: UINT;
function GetStringValue(const From: string): string;
var
Size: UINT;
tempStr: string;
Value: PChar;
begin
tempStr := Format('%s%.4x%.4x\%s%s', ['\StringFileInfo\', LoWord(LongInt(Trans^)), HiWord(LongInt(Trans^)), From, #0]);
VerQueryValue(PChar(VInfo), PChar(tempStr), Pointer(Value), Size);
if Size > 0 then Result:= Value else Result:= '';
end;
begin
Clear;
if not FileExists(FFileName) then Exit;
VInfoSize:= GetFileVersionInfoSize(PChar(FFileName), Handle);
if VInfoSize < 1 then Exit;
VInfo:= AllocMem(VInfoSize);
GetFileVersionInfo(PChar(FFileName), Handle, VInfoSize, VInfo);
VerQueryValue(VInfo,'\VarFileInfo\Translation', Trans, TransSize);
if TransSize < 4 then Exit;
FCompanyName:= GetStringValue('CompanyName');
FFileDescription:= GetStringValue('FileDescription');
FFileVersion:= GetStringValue('FileVersion');
FInternalName:= GetStringValue('InternalName');
FLegalCopyright:= GetStringValue('LegalCopyright');
FOriginalFilename:= GetStringValue('OriginalFilename');
FProductName:= GetStringValue('ProductName');
FProductVersion:= GetStringValue('ProductVersion');
FComments:= GetStringValue('Comments');
FreeMem(VInfo, VInfoSize);
if not GetBinaryType(LPTSTR(FFileName), FBinaryType) then FBinaryType:= DWORD(-1);
end;
class procedure TVersionInfo.Clear;
begin
FLanguageInfo:= '';
FCompanyName:= '';
FFileDescription:= '';
FFileVersion:= '';
FInternalName:= '';
FLegalCopyright:= '';
FOriginalFileName:= '';
FProductName:= '';
FProductVersion:= '';
FComments:= '';
FBinaryType:= DWORD(-1);
end;
class procedure TVersionInfo.SetFileName(const Value: TFileName);
begin
FFileName := Value;
Load;
end;
class function TVersionInfo.GetBinaryTypeAsString: string;
begin
case FBinaryType of
SCS_32BIT_BINARY : Result:= 'A 32-bit Windows-based application';
SCS_64BIT_BINARY : Result:= 'A 64-bit Windows-based application';
SCS_DOS_BINARY : Result:= 'An MS-DOS - based application';
SCS_OS216_BINARY : Result:= 'A 16-bit OS/2-based application';
SCS_PIF_BINARY : Result:= 'A PIF file that executes an MS-DOS – based application';
SCS_POSIX_BINARY : Result:= 'A POSIX – based application';
SCS_WOW_BINARY : Result:= 'A 16-bit Windows-based application';
else Result:= '';
end
end;
class function TVersionInfo.GetBinaryTypeAsShortString: string;
begin
case FBinaryType of
SCS_32BIT_BINARY : Result:= 'x86';
SCS_64BIT_BINARY : Result:= 'x64';
SCS_DOS_BINARY : Result:= 'MS-DOS';
SCS_OS216_BINARY : Result:= '16-bit OS/2';
SCS_PIF_BINARY : Result:= 'PIF';
SCS_POSIX_BINARY : Result:= 'POSIX';
SCS_WOW_BINARY : Result:= 'Win16';
else Result:= '';
end
end;
class constructor TVersionInfo.Create;
begin
TVersionInfo.FileName := GetRealFileName;
end;
end.