Da offenbar kaum jemand Bescheid weiss wie die ResourceUtils von Clin Wilson eingesetzt werden können um Delphi resource Dateien zu bearbeiten, blieb mir nichts anderes übrig als dies selber zu erstellen. Hier den Relevanten Auszug aus meinem Ergebnis.
type
TVersionNumber = record
Major: Integer;
Minor: Integer;
Release: Integer;
Build: Integer;
procedure FromULargeInteger(aULargeInteger: TULargeInteger);
function AsULargeInteger: TULargeInteger;
end;
TSetVersion = class
private
{ Private declarations }
fResFile: string;
fOnMessageLog: TEventLog;
fOnErrorLog: TEventLog;
fOnHintLog: TEventLog;
fFileVerMajor: integer;
fFileVerMinor: integer;
fFileVerRelease: integer;
fFileVerBuild: integer;
fProductVerMajor: integer;
fProductVerMinor: integer;
fProductVerRelease: integer;
fProductVerBuild: integer;
fCompanyName: string;
fFileDescription: string;
fFileVersion: string;
fInternalName: string;
fLegalCopyright: string;
fLegalTrademarks: string;
fOriginalFilename: string;
fProductName: string;
fProductVersion: string;
fComments: string;
function VersionToString(version: TULargeInteger): string;
function StringToVersion(const version: string): TULargeInteger;
procedure logMessage(sMessage: string);
procedure logError(sMessage: string);
procedure logHint(sMessage: string);
public
{ Public declarations }
property FileVerMajor: integer read fFileVerMajor write fFileVerMajor;
property FileVerMinor: integer read fFileVerMinor write fFileVerMinor;
property FileVerRelease: integer read fFileVerRelease write fFileVerRelease;
property FileVerBuild: integer read fFileVerBuild write fFileVerBuild;
property ProductVerMajor: integer read fProductVerMajor write fProductVerMajor;
property ProductVerMinor: integer read fProductVerMinor write fProductVerMinor;
property ProductVerRelease: integer read fProductVerRelease write fProductVerRelease;
property ProductVerBuild: integer read fProductVerBuild write fProductVerBuild;
property CompanyName: string read fCompanyName write fCompanyName;
property FileDescription: string read fFileDescription write fFileDescription;
property FileVersion: string read fFileVersion write fFileVersion;
property InternalName: string read fInternalName write fInternalName;
property LegalCopyright: string read fLegalCopyright write fLegalCopyright;
property LegalTrademarks: string read fLegalTrademarks write fLegalTrademarks;
property OriginalFilename: string read fOriginalFilename write fOriginalFilename;
property ProductName: string read fProductName write fProductName;
property ProductVersion: string read fProductVersion write fProductVersion;
property Comments: string read fComments write fComments;
property OnMessageLog: TEventLog read fOnMessageLog write fOnMessageLog;
property OnHintLog: TEventLog read fOnHintLog write fOnHintLog;
property OnErrorLog: TEventLog read fOnErrorLog write fOnErrorLog;
function UpdateResVersion(aResFile: string): boolean;
end;
implementation
uses StrUtils, uMisc,
unitPEFile, unitResFile, unitNTModule, unitResourceDetails, unitResourceVersionInfo;
function TSetVersion.UpdateResVersion(aResFile: string): boolean;
var
i: Integer;
ResModule: TResModule;
VersionInfoResourceDetails: TVersionInfoResourceDetails;
VersionNumber: TVersionNumber;
function GetVersionInfoResourceDetails(aResModule: TResModule): TVersionInfoResourceDetails;
var
i: Integer;
begin
Result := nil;
for i := 0 to aResModule.ResourceCount - 1 do
begin
aResModule.ResourceDetails[i];
if aResModule.ResourceDetails[i] is TVersionInfoResourceDetails then
begin
Result := (aResModule.ResourceDetails[i]) as TVersionInfoResourceDetails;
Break; // I believe there should only ever be one Version resource.
end;
end;
end;
begin
result := true;
ResModule := TResModule.Create;
try
ResModule.LoadFromFile(aResFile);
VersionInfoResourceDetails := GetVersionInfoResourceDetails(ResModule);
if not Assigned(VersionInfoResourceDetails) then
begin
raise
Exception.CreateFmt('No VersionInfo found in %s', [aResFile]);
end
else
begin
// logMessage('------------------------------------------ ');
// for I := 0 to VersionInfoResourceDetails.KeyCount - 1 do
// begin
// logHint(VersionInfoResourceDetails.Key[i].KeyName + ': ' + VersionInfoResourceDetails.Key[i].Value);
// end;
// logHint(format('Set Version File <%s>',[aResFile]));
VersionInfoResourceDetails.SetKeyValue('CompanyNam e', fCompanyName);
VersionInfoResourceDetails.SetKeyValue('FileDescri ption', fFileDescription);
VersionInfoResourceDetails.SetKeyValue('FileVersio n', fFileVersion);
VersionInfoResourceDetails.SetKeyValue('InternalNa me', fInternalName);
VersionInfoResourceDetails.SetKeyValue('LegalCopyr ight', fLegalCopyright);
VersionInfoResourceDetails.SetKeyValue('LegalTrade marks', fLegalTrademarks);
VersionInfoResourceDetails.SetKeyValue('OriginalFi lename', fOriginalFilename);
VersionInfoResourceDetails.SetKeyValue('ProductNam e', fProductName);
VersionInfoResourceDetails.SetKeyValue('ProductVer sion', fProductVersion);
VersionInfoResourceDetails.SetKeyValue('Comments', fComments);
VersionNumber.FromULargeInteger(VersionInfoResourc eDetails.FileVersion);
VersionNumber.Major := fProductVerMajor;
VersionNumber.Minor := fProductVerMinor;
VersionNumber.Release := fProductVerRelease;
VersionNumber.Build := fProductVerBuild;
VersionInfoResourceDetails.ProductVersion := VersionNumber.AsULargeInteger;
VersionNumber.FromULargeInteger(VersionInfoResourc eDetails.FileVersion);
VersionNumber.Major := fFileVerMajor;
VersionNumber.Minor := fFileVerMinor;
VersionNumber.Release := fFileVerRelease;
VersionNumber.Build := fFileVerBuild;
VersionInfoResourceDetails.FileVersion := VersionNumber.AsULargeInteger;
// commenting this out will copy existing RES files to [resfile].~res backup files
DeleteFile(PChar(aResFile));
ResModule.SaveToFile(aResFile);
// logMessage('------------------------------------------');
// logMessage(' ');
// for I := 0 to VersionInfoResourceDetails.KeyCount - 1 do
// begin
// if length(VersionInfoResourceDetails.Key[i].Value) > 0 then
// logHint(VersionInfoResourceDetails.Key[i].KeyName + ': ' + VersionInfoResourceDetails.Key[i].Value);
// end;
end;
finally
// ResModule.Free;
FreeAndNil(ResModule);
end;
end;
{ TVersionNumber }
function TVersionNumber.AsULargeInteger: TULargeInteger;
begin
Result.HighPart := Major shl 16 or Minor;
Result.LowPart := Release shl 16 or Build
end;
procedure TVersionNumber.FromULargeInteger(aULargeInteger: TULargeInteger);
begin
Major := aULargeInteger.HighPart shr 16;
Minor := aULargeInteger.HighPart and ((1 shl 16) - 1);
Release := aULargeInteger.LowPart shr 16;
Build := aULargeInteger.LowPart and ((1 shl 16) - 1);
end;
Softconsult GmbH Widen Schweiz.