-
Notifications
You must be signed in to change notification settings - Fork 2
/
FileVersion.pas
179 lines (158 loc) · 4.51 KB
/
FileVersion.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
unit FileVersion;
interface
type
TFileVersionInfo = class
private
FInfo: array of Char;
FInfoSize: Cardinal;
FFilename, FKey,
FCompanyName,
FDescription,
FVersion,
FInternalName,
FLegalCopyright,
FLegalTrademarks,
FOriginalFilename,
FProductName,
FProductVersion,
FComments: string;
function GetFilename: string;
function GetVersion: string;
function GetFileVersionString(const KeyName: string): string;
function GetDescription: string;
function GetNLSKey: string;
function GetInternalName: string;
function GetLegalCopyright: string;
function GetLegalTrademarks: string;
function GetCompanyName: string;
function GetComments: string;
function GetOriginalFilename: string;
function GetProductName: string;
function GetProductVersion: string;
function GetValue(const KeyName: string): string;
protected
property Key: string read GetNLSKey;
public
constructor Create(const Filename: string);
property Filename: string read GetFilename;
property CompanyName: string read GetCompanyName;
property Description: string read GetDescription;
property Version: string read GetVersion;
property InternalName: string read GetInternalName;
property LegalCopyright: string read GetLegalCopyright;
property LegalTrademarks: string read GetLegalTrademarks;
property OriginalFilename: string read GetOriginalFilename;
property ProductName: string read GetProductName;
property ProductVersion: string read GetProductVersion;
property Comments: string read GetComments;
property Values[const KeyName: string]: string read GetValue; default;
end;
implementation
uses Windows, SysUtils;
{ TFilenameVersion }
constructor TFileVersionInfo.Create(const Filename: string);
begin
inherited Create;
FFileName := Filename;
end;
function TFileVersionInfo.GetComments: string;
begin
if FComments = '' then
FComments := Values['Comments'];
Result := FComments;
end;
function TFileVersionInfo.GetCompanyName: string;
begin
if FCompanyName = '' then
FCompanyName := Values['CompanyName'];
Result := FCompanyName;
end;
function TFileVersionInfo.GetDescription: string;
begin
if FDescription = '' then
FDescription := Values['FileDescription'];
Result := FDescription;
end;
function TFileVersionInfo.GetFilename: string;
begin
Result := FFilename;
end;
function TFileVersionInfo.GetFileVersionString(
const KeyName: string): string;
var
Temp: Cardinal;
Buffer: PChar;
begin
if FInfoSize = 0 then
begin
FInfoSize := GetFileVersionInfoSize(PChar(Filename), Temp);
SetLength(FInfo, FInfoSize);
GetFileVersionInfo(PChar(Filename), 0, FInfoSize, FInfo);
end;
if FInfoSize > 0 then
begin
if VerQueryValue(FInfo, PChar(Format('%s\%s', [Key, KeyName])),
Pointer(Buffer), FInfoSize) then
Result := Buffer;
end;
end;
function TFileVersionInfo.GetInternalName: string;
begin
if FInternalName = '' then
FInternalName := Values['InternalName'];
Result := FInternalName;
end;
function TFileVersionInfo.GetValue(const KeyName: string): string;
begin
Result := GetFileVersionString(KeyName);
end;
function TFileVersionInfo.GetLegalCopyright: string;
begin
if FLegalCopyright = '' then
FLegalCopyright := Values['LegalCopyright'];
Result := FLegalCopyright;
end;
function TFileVersionInfo.GetLegalTrademarks: string;
begin
if FLegalTrademarks = '' then
FLegalTrademarks := Values['LegalTrademarks'];
Result := FLegalTrademarks;
end;
function TFileVersionInfo.GetNLSKey: string;
var
P: Pointer;
Len: Cardinal;
begin
if FKey = '' then
begin
VerQueryValue(FInfo, '\VarFileInfo\Translation', P, Len);
if Assigned(P) then
FKey := Format('\StringFileInfo\%4.4x%4.4x', [LoWord(Longint(P^)), HiWord(Longint(P^))]);
end;
Result := FKey;
end;
function TFileVersionInfo.GetOriginalFilename: string;
begin
if FOriginalFilename = '' then
FOriginalFilename := Values['OriginalFilename'];
Result := FOriginalFilename;
end;
function TFileVersionInfo.GetProductName: string;
begin
if FProductName = '' then
FProductName := Values['ProductName'];
Result := FProductName;
end;
function TFileVersionInfo.GetProductVersion: string;
begin
if FProductVersion = '' then
FProductVersion := Values['ProductVersion'];
Result := FProductVersion;
end;
function TFileVersionInfo.GetVersion: string;
begin
if FVersion = '' then
FVersion := Values['FileVersion'];
Result := FVersion;
end;
end.