From 4b5cf332cadd4c918ec262bba3ee0b61fc305ae5 Mon Sep 17 00:00:00 2001 From: Andreas Schneider Date: Sat, 26 Mar 2011 22:13:57 +0100 Subject: [PATCH] - Changed versions to be read from the resource stream --- Client/CentrED.lpi | 2 +- Client/UfrmAbout.lfm | 35 +++++++------- Client/UfrmAbout.pas | 8 ++-- Server/cedserver.lpi | 5 +- Server/cedserver.lpr | 12 ++--- vinfo.pas | 111 +++++++++++++++++++++++++++++++++++++++++++ 6 files changed, 140 insertions(+), 33 deletions(-) create mode 100644 vinfo.pas diff --git a/Client/CentrED.lpi b/Client/CentrED.lpi index ff8b85a..0f820ad 100644 --- a/Client/CentrED.lpi +++ b/Client/CentrED.lpi @@ -19,7 +19,7 @@ - + diff --git a/Client/UfrmAbout.lfm b/Client/UfrmAbout.lfm index 55fbf27..f6fa6b9 100644 --- a/Client/UfrmAbout.lfm +++ b/Client/UfrmAbout.lfm @@ -12,11 +12,11 @@ object frmAbout: TfrmAbout Font.Height = -11 OnCreate = FormCreate Position = poScreenCenter - LCLVersion = '0.9.29' + LCLVersion = '0.9.31' object Label3: TLabel Left = 8 Height = 53 - Top = 189 + Top = 178 Width = 338 Align = alTop BorderSpacing.Top = 16 @@ -28,7 +28,7 @@ object frmAbout: TfrmAbout object Label5: TLabel Left = 8 Height = 14 - Top = 98 + Top = 87 Width = 338 Align = alTop BorderSpacing.Left = 8 @@ -39,7 +39,7 @@ object frmAbout: TfrmAbout object Label6: TLabel Left = 16 Height = 53 - Top = 112 + Top = 101 Width = 330 Align = alTop BorderSpacing.Left = 16 @@ -50,7 +50,7 @@ object frmAbout: TfrmAbout object Label7: TLabel Left = 8 Height = 14 - Top = 84 + Top = 73 Width = 338 Align = alTop BorderSpacing.Left = 8 @@ -61,32 +61,32 @@ object frmAbout: TfrmAbout end object Panel2: TPanel Left = 0 - Height = 76 + Height = 65 Top = 0 Width = 354 Align = alTop AutoSize = True BorderSpacing.Bottom = 8 BevelOuter = bvNone - ClientHeight = 76 + ClientHeight = 65 ClientWidth = 354 TabOrder = 0 object Panel1: TPanel Left = 0 - Height = 76 + Height = 65 Top = 0 - Width = 167 + Width = 190 AutoSize = True BevelInner = bvRaised BevelOuter = bvLowered - ClientHeight = 76 - ClientWidth = 167 + ClientHeight = 65 + ClientWidth = 190 TabOrder = 0 object Label1: TLabel Left = 2 Height = 38 Top = 2 - Width = 163 + Width = 186 Align = alTop Alignment = taCenter AutoSize = False @@ -99,9 +99,9 @@ object frmAbout: TfrmAbout end object lblVersion: TLabel Left = 6 - Height = 14 + Height = 1 Top = 40 - Width = 155 + Width = 178 Align = alTop Alignment = taRightJustify BorderSpacing.Left = 4 @@ -111,11 +111,12 @@ object frmAbout: TfrmAbout object lblCopyright: TLabel Left = 6 Height = 14 - Top = 58 - Width = 155 + Top = 45 + Width = 178 Align = alTop Alignment = taCenter BorderSpacing.Around = 4 + Caption = 'Copyright 2011 Andreas Schneider' ParentColor = False end end @@ -123,7 +124,7 @@ object frmAbout: TfrmAbout object Panel3: TPanel Left = 8 Height = 25 - Top = 250 + Top = 239 Width = 338 Align = alTop BorderSpacing.Around = 8 diff --git a/Client/UfrmAbout.pas b/Client/UfrmAbout.pas index 97e495c..917664f 100644 --- a/Client/UfrmAbout.pas +++ b/Client/UfrmAbout.pas @@ -21,7 +21,7 @@ * CDDL HEADER END * * - * Portions Copyright 2007 Andreas Schneider + * Portions Copyright 2011 Andreas Schneider *) unit UfrmAbout; @@ -62,7 +62,8 @@ var implementation -{$I version.inc} +uses + vinfo; { TfrmAbout } @@ -73,8 +74,7 @@ end; procedure TfrmAbout.FormCreate(Sender: TObject); begin - lblVersion.Caption := Format('Version %s', [ProductVersion]); - lblCopyright.Caption := Format('Copyright %s', [Copyright]); + lblVersion.Caption := Format('Version %s', [VersionInfo.GetProductVersionString]); end; initialization diff --git a/Server/cedserver.lpi b/Server/cedserver.lpi index 5799a60..0adfb97 100644 --- a/Server/cedserver.lpi +++ b/Server/cedserver.lpi @@ -15,7 +15,7 @@ - + @@ -219,7 +219,6 @@ - @@ -242,4 +241,4 @@ - \ No newline at end of file + diff --git a/Server/cedserver.lpr b/Server/cedserver.lpr index 761c739..627b3f6 100644 --- a/Server/cedserver.lpr +++ b/Server/cedserver.lpr @@ -21,7 +21,7 @@ * CDDL HEADER END * * - * Portions Copyright 2008 Andreas Schneider + * Portions Copyright 2011 Andreas Schneider *) program cedserver; @@ -31,18 +31,14 @@ uses {$IFDEF UNIX}{$IFDEF UseCThreads} cthreads, {$ENDIF}{$ENDIF} - SysUtils, UConfig, UCEDServer; + SysUtils, UConfig, UCEDServer, vinfo; -{$I version.inc} - -{$IFDEF WINDOWS}{$R cedserver.rc}{$ENDIF} - {$R *.res} begin Writeln(''); - Writeln('CentrED Server Version ', ProductVersion); - Writeln('Copyright ', Copyright); + Writeln('CentrED Server Version ', versionInfo.GetProductVersionString); + Writeln('Copyright 2011 Andreas Schneider'); //Writeln('================================'); Writeln(''); diff --git a/vinfo.pas b/vinfo.pas new file mode 100644 index 0000000..b6bec70 --- /dev/null +++ b/vinfo.pas @@ -0,0 +1,111 @@ +unit vinfo; + +{$mode objfpc} + +interface + +uses + Classes, SysUtils, resource, versiontypes, versionresource; + +type + TVersionPrecision = 1..4; + + { TVersionInfo } + + TVersionInfo = class + private + FVersResource: TVersionResource; + function GetFixedInfo: TVersionFixedInfo; + function GetStringFileInfo: TVersionStringFileInfo; + function GetVarFileInfo: TVersionVarFileInfo; + public + constructor Create; + destructor Destroy; override; + + procedure Load(Instance: THandle); + property FixedInfo: TVersionFixedInfo read GetFixedInfo; + property StringFileInfo: TVersionStringFileInfo read GetStringFileInfo; + property VarFileInfo: TVersionVarFileInfo read GetVarFileInfo; + + //Helper functions + function GetProductVersionString(AMinPrecision: TVersionPrecision = 2): String; + end; + +var + VersionInfo: TVersionInfo; + +implementation + +{ TVersionInfo } + +function TVersionInfo.GetFixedInfo: TVersionFixedInfo; +begin + Result := FVersResource.FixedInfo; +end; + +function TVersionInfo.GetStringFileInfo: TVersionStringFileInfo; +begin + Result := FVersResource.StringFileInfo; +end; + +function TVersionInfo.GetVarFileInfo: TVersionVarFileInfo; +begin + Result := FVersResource.VarFileInfo; +end; + +constructor TVersionInfo.Create; +begin + inherited Create; + FVersResource := TVersionResource.Create; +end; + +destructor TVersionInfo.Destroy; +begin + FVersResource.Free; + inherited Destroy; +end; + +procedure TVersionInfo.Load(Instance: THandle); +var + Stream: TResourceStream; +begin + Stream := TResourceStream.CreateFromID(Instance, 1, PChar(RT_VERSION)); + try + FVersResource.SetCustomRawDataStream(Stream); + // access some property to load from the stream + FVersResource.FixedInfo; + // clear the stream + FVersResource.SetCustomRawDataStream(nil); + finally + Stream.Free; + end; +end; + +function TVersionInfo.GetProductVersionString(AMinPrecision: TVersionPrecision = 2): String; +var + productVersion: TFileProductVersion; + lastVersion, i: Integer; +begin + productVersion := FixedInfo.ProductVersion; + lastVersion := 3; + while (lastVersion >= AMinPrecision) and (productVersion[lastVersion] = 0) do + dec(lastVersion); + + Result := ''; + for i := 0 to lastVersion do + begin + Result := Result + IntToStr(productVersion[i]); + if i < lastVersion then + Result := Result + '.'; + end; +end; + +initialization + VersionInfo := TVersionInfo.Create; + VersionInfo.Load(HINSTANCE); + +finalization + VersionInfo.Free; + +end. +