-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathversioninfo.pas
More file actions
230 lines (193 loc) · 6.95 KB
/
versioninfo.pas
File metadata and controls
230 lines (193 loc) · 6.95 KB
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
{
This file is part of Rifas - a raffle generator program.
Copyright (C) 2011 João Marcelo S. Vaz
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
}
unit VersionInfo;
{$mode objfpc}
interface
uses
Classes, SysUtils, versionresource;
type
{ TVersionInfo }
TVersionInfo = record
MajorVersion: Integer;
MinorVersion: Integer;
Release: Integer;
Build: Integer;
end;
{ TProductInfo }
TProductInfo = class
private
fVersionResource: TVersionResource;
fFPCVersion: TVersionInfo;
fLCLVersion: TVersionInfo;
function GetBuildDate: TDateTime;
function GetComments: String;
function GetCompanyName: String;
function GetCPU: String;
function GetFileDescription: String;
function GetFileVersion: TVersionInfo;
function GetInternalName: String;
function GetLegalCopyright: String;
function GetLegalTrademarks: String;
function GetOriginalFilename: String;
function GetOS: String;
function GetProductName: String;
function GetProductVersion: TVersionInfo;
function GetWidgetSet: String;
public
constructor Create;
destructor Destroy; override;
property FileVersion: TVersionInfo read GetFileVersion; // Version number of the file — for example, "3.10"
property ProductVersion: TVersionInfo read GetProductVersion; // Version of the product with which the file is distributed — for example, "3.10"
property ProductName: String read GetProductName; // Name of the product with which the file is distributed.
property CompanyName: String read GetCompanyName; // Company that produced the file — for example, "Standard Microsystems Corporation, Inc."
property FileDescription: String read GetFileDescription; // File description to be presented to users.
property InternalName: String read GetInternalName; // Internal name of the file, if one exists
property OriginalFilename: String read GetOriginalFilename; // Original name of the file, not including a path. This information enables an application to determine whether a file has been renamed by a user.
property LegalCopyright: String read GetLegalCopyright; // Copyright notices that apply to the file. This should include the full text of all notices, legal symbols, copyright dates, and so on.
property LegalTrademarks: String read GetLegalTrademarks; // Trademarks and registered trademarks that apply to the file. This should include the full text of all notices, legal symbols, trademark numbers, and so on.
property Comments: String read GetComments; // Additional information that can be displayed for diagnostic purposes.
property BuildDate: TDateTime read GetBuildDate;
property CPU: String read GetCPU;
property OS: String read GetOS;
property WidgetSet: String read GetWidgetSet;
property FPCVersion: TVersionInfo read fFPCVersion; // FreePascal Compiler version
property LCLVersion: TVersionInfo read fLCLVersion; // Lazarus Component Library version
end;
function VersionInfoToStr(VI: TVersionInfo): String;
function VersionInfo3ToStr(VI: TVersionInfo): String;
implementation
uses
resource, lclversion, interfacebase,LCLPlatformDef;
function VersionInfoToStr(VI: TVersionInfo): String;
begin
Result := Format('%d.%d.%d.%d', [VI.MajorVersion,VI.MinorVersion,VI.Release,VI.Build])
end;
function VersionInfo3ToStr(VI: TVersionInfo): String;
begin
Result := Format('%d.%d.%d', [VI.MajorVersion,VI.MinorVersion,VI.Release])
end;
{ TProductInfo }
function TProductInfo.GetComments: String;
begin
Result:= '';
end;
function TProductInfo.GetBuildDate: TDateTime;
var
dt: string;
SlashPos1, SlashPos2: integer;
begin
// code from Lazarus IDE aboutfrm.pas
dt:= {$I %date%};
SlashPos1:= Pos('/',dt);
SlashPos2:= SlashPos1 + Pos('/', Copy(dt, SlashPos1+1, Length(dt)-SlashPos1));
Result:= EncodeDate(StrToInt(Copy(dt,1,SlashPos1-1)),
StrToInt(Copy(dt,SlashPos1+1,SlashPos2-SlashPos1-1)),
StrToInt(Copy(dt,SlashPos2+1,Length(dt)-SlashPos2)));
end;
function TProductInfo.GetCompanyName: String;
begin
Result:= '';
end;
function TProductInfo.GetCPU: String;
begin
Result:= {$I %FPCTARGETCPU%};
end;
function TProductInfo.GetFileDescription: String;
begin
Result:= '';
end;
function TProductInfo.GetFileVersion: TVersionInfo;
begin
Result.MajorVersion:= fVersionResource.FixedInfo.FileVersion[0];
Result.MinorVersion:= fVersionResource.FixedInfo.FileVersion[1];
Result.Release:= fVersionResource.FixedInfo.FileVersion[2];
Result.Build:= fVersionResource.FixedInfo.FileVersion[3];
end;
function TProductInfo.GetInternalName: String;
begin
Result:= '';
end;
function TProductInfo.GetLegalCopyright: String;
begin
Result:= '';
end;
function TProductInfo.GetLegalTrademarks: String;
begin
Result:= '';
end;
function TProductInfo.GetOriginalFilename: String;
begin
Result:= '';
end;
function TProductInfo.GetOS: String;
begin
Result:= {$I %FPCTARGETOS%};
end;
function TProductInfo.GetProductName: String;
begin
Result:= '';
end;
function TProductInfo.GetProductVersion: TVersionInfo;
begin
Result.MajorVersion:= fVersionResource.FixedInfo.ProductVersion[0];
Result.MinorVersion:= fVersionResource.FixedInfo.ProductVersion[1];
Result.Release:= fVersionResource.FixedInfo.ProductVersion[2];
Result.Build:= fVersionResource.FixedInfo.ProductVersion[3];
end;
function TProductInfo.GetWidgetSet: String;
begin
if Assigned(interfacebase.WidgetSet) then
Result:= LCLPlatformDisplayNames[GetBuildLCLWidgetType];
end;
constructor TProductInfo.Create;
var
Stream: TResourceStream;
begin
{$IFOPT m+}
{$DEFINE MacroOn}
{$ELSE}
{$MACRO ON}
{$UNDEF MacroOn}
{$ENDIF}
fFPCVersion.MajorVersion:= FPC_VERSION;
fFPCVersion.MinorVersion:= FPC_RELEASE;
fFPCVersion.Release:= FPC_PATCH;
fFPCVersion.Build:= 0;
{$IFNDEF MacroOn}
{$MACRO OFF}
{$ENDIF}
{$UNDEF MacroOn}
fLCLVersion.MajorVersion:= lcl_major;
fLCLVersion.MinorVersion:= lcl_minor;
fLCLVersion.Release:= lcl_release;
fLCLVersion.Build:= lcl_patch;
fVersionResource:= TVersionResource.Create;
Stream := TResourceStream.CreateFromID(HINSTANCE, 1, PChar(RT_VERSION));
try
fVersionResource.SetCustomRawDataStream(Stream);
// access some property to load from the stream
fVersionResource.FixedInfo;
// clear the stream
fVersionResource.SetCustomRawDataStream(nil);
finally
Stream.Free;
end;
end;
destructor TProductInfo.Destroy;
begin
fVersionResource.Free;
inherited Destroy;
end;
end.