windows ide:

- create rc files instead of res for version info and manifest
- remove no more needed ide resources

git-svn-id: trunk@13045 -
This commit is contained in:
paul 2007-11-27 02:16:20 +00:00
parent 636bc20c12
commit 277aed08b2
6 changed files with 140 additions and 224 deletions

2
.gitattributes vendored
View File

@ -1963,9 +1963,7 @@ ide/mainintf.pas svneol=native#text/pascal
ide/makeresstrdlg.lfm svneol=native#text/plain
ide/makeresstrdlg.lrs svneol=native#text/plain
ide/makeresstrdlg.pas svneol=native#text/pascal
ide/manifest.lrs svneol=native#text/pascal
ide/manifest.rc svneol=native#text/plain
ide/manifest.res -text
ide/miscoptions.pas svneol=native#text/pascal
ide/msgquickfixes.pas svneol=native#text/plain
ide/msgview.lfm svneol=native#text/plain

View File

@ -8399,7 +8399,7 @@ begin
// handle versioninfo
VersionInfo := Project1.VersionInfo;
Result := VersionInfo.CompileRCFile(Project1.MainFilename,
Result := VersionInfo.CreateRCFile(Project1.MainFilename,
MainBuildBoss.GetTargetOS(true));
for Count := 1 to VersionInfo.VersionInfoMessages.Count do
@ -8408,7 +8408,7 @@ begin
if Result <> mrOk then exit;
// handle manifest
Result := Project1.XPManifest.CompileRCFile(Project1.MainFilename,
Result := Project1.XPManifest.CreateRCFile(Project1.MainFilename,
MainBuildBoss.GetTargetOS(true));
for Count := 1 to Project1.XPManifest.Messages.Count do
MessagesView.AddMsg(Format(Project1.XPManifest.Messages[Count - 1],

View File

@ -1,14 +0,0 @@
LazarusResources.Add('manifest','RES',[
#0#0#0#0' '#0#0#0#255#255#0#0#255#255#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#220
+#2#0#0' '#0#0#0#255#255#24#0#255#255#1#0#0#0#0#0'0'#0#25#4#0#0#0#0#0#0#0#0'<'
+'?xml version="1.0" encoding="UTF-8" standalone="yes"?><assembly xmlns="urn:'
+'schemas-microsoft-com:asm.v1" manifestVersion="1.0"><assemblyIdentity versi'
+'on="1.0.0.0" processorArchitecture="*" name="CompanyName.ProductName.YourAp'
+'p" type="win32"/><description>Your application description here.</descripti'
+'on><dependency><dependentAssembly><assemblyIdentity type="win32" name="Micr'
+'osoft.Windows.Common-Controls" version="6.0.0.0" processorArchitecture="*" '
+'publicKeyToken="6595b64144ccf1df" language="*"/></dependentAssembly></depen'
+'dency><trustInfo xmlns="urn:schemas-microsoft-com:asm.v3"><security><reques'
+'tedPrivileges><requestedExecutionLevel level="asInvoker" uiAccess="false"/>'
+'</requestedPrivileges></security></trustInfo></assembly>'
]);

Binary file not shown.

View File

@ -45,14 +45,14 @@ type
FMessages: TStrings;
FModified: boolean;
FUseManifest: boolean;
resFilename: string;
rcFilename: string;
procedure SetUseManifest(const AValue: boolean);
procedure SetFileNames(const MainFilename: string);
public
constructor Create;
destructor Destroy; override;
function CompileRCFile(const MainFilename, TargetOS: string): TModalResult;
function CreateRCFile(const MainFilename, TargetOS: string): TModalResult;
function CreateManifest: Boolean;
function UpdateMainSourceFile(const AFilename: string): TModalResult;
@ -63,13 +63,39 @@ type
implementation
const
sManifest: String =
'#define RT_MANIFEST 24'#$D#$A+
'#define CREATEPROCESS_MANIFEST_RESOURCE_ID 1'#$D#$A+
'#define ISOLATIONAWARE_MANIFEST_RESOURCE_ID 2'#$D#$A+
'#define ISOLATIONAWARE_NOSTATICIMPORT_MANIFEST_RESOURCE_ID 3'#$D#$A#$D#$A+
'CREATEPROCESS_MANIFEST_RESOURCE_ID RT_MANIFEST MOVEABLE PURE'#$D#$A+
'{'#$D#$A+
' "<?xml version=""1.0"" encoding=""UTF-8"" standalone=""yes""?>"'#$D#$A+
' "<assembly xmlns=""urn:schemas-microsoft-com:asm.v1"" manifestVersion=""1.0"">"'#$D#$A+
' "<assemblyIdentity version=""1.0.0.0"" processorArchitecture=""*"" name=""CompanyName.ProductName.YourApp"" type=""win32""/>"'#$D#$A+
' "<description>Your application description here.</description>"'#$D#$A+
' "<dependency>"'#$D#$A+
' "<dependentAssembly>"'#$D#$A+
' "<assemblyIdentity type=""win32"" name=""Microsoft.Windows.Common-Controls"" version=""6.0.0.0"" processorArchitecture=""*"" publicKeyToken=""6595b64144ccf1df"" language=""*""/>"'#$D#$A+
' "</dependentAssembly>"'#$D#$A+
' "</dependency>"'#$D#$A+
' "<trustInfo xmlns=""urn:schemas-microsoft-com:asm.v3"">"'#$D#$A+
' "<security>"'#$D#$A+
' "<requestedPrivileges>"'#$D#$A+
' "<requestedExecutionLevel level=""asInvoker"" uiAccess=""false""/>"'#$D#$A+
' "</requestedPrivileges>"'#$D#$A+
' "</security>"'#$D#$A+
' "</trustInfo>"'#$D#$A+
' "</assembly>"'#$D#$A+
'}';
{-----------------------------------------------------------------------------
TProjectXPManifest CompileRCFile
TProjectXPManifest CreateRCFile
-----------------------------------------------------------------------------}
function TProjectXPManifest.CompileRCFile(const MainFilename, TargetOS: string): TModalResult;
function TProjectXPManifest.CreateRCFile(const MainFilename, TargetOS: string): TModalResult;
begin
// in future we will compile manifest from rc, but now we just add our template
Result := mrOk;
SetFileNames(MainFilename);
if (TargetOS = 'win32') and UseManifest then
@ -81,31 +107,15 @@ end;
function TProjectXPManifest.CreateManifest: Boolean;
var
Res: TLResource;
Stream: TStream;
begin
// here will be better to compile res from rc, but we will only extract
// precompiled res from lazarus resource due to error in windres.
// Error description:
// if we compile manifest by windres then we will not link our project if we
// have other res files before manifest (I tested with version info resource)
// But if we compile that manifest.rc with other resource compiler then we have
// not such errors. So at this moment we decided to extract precompiled res insted
// of have problems with rc compilation and further linking
Result := False;
Res := LazarusResources.Find('manifest');
if (Res <> nil) and (Res.Value <> '') and (Res.ValueType = 'RES') then
begin
Stream := nil;
try
Stream := TFileStream.Create(resFileName, fmCreate);
Stream.Write(Res.Value[1], length(Res.Value));
Result := True;
finally
Stream.Free;
end;
try
Stream := TFileStream.Create(rcFileName, fmCreate);
Stream.Write(sManifest[1], length(sManifest));
Result := True;
finally
Stream.Free;
end;
end;
@ -130,7 +140,7 @@ begin
if ManifestCodeBuf <> nil then
begin
SetFileNames(AFilename);
Filename:=ExtractFileName(resFileName);
Filename:=ExtractFileName(rcFileName);
DebugLn(['TProjectXPManifest.UpdateMainSourceFile ',Filename]);
if CodeToolBoss.FindResourceDirective(ManifestCodeBuf, 1, 1,
NewCode, NewX, NewY,
@ -163,7 +173,7 @@ end;
-----------------------------------------------------------------------------}
procedure TProjectXPManifest.SetFileNames(const MainFilename: string);
begin
resFilename := ExtractFilePath(MainFilename) + 'manifest.res';
rcFilename := ExtractFilePath(MainFilename) + 'manifest.rc';
end;
constructor TProjectXPManifest.Create;
@ -177,7 +187,5 @@ begin
inherited Destroy;
end;
initialization
{$i manifest.lrs}
end.

View File

@ -65,7 +65,6 @@ type
FUseVersionInfo: boolean;
FVersionNr: integer;
rcFilename: string;
resFilename: string;
rcInFile: text;
rcOutFile: text;
rcLine: string;
@ -79,7 +78,6 @@ type
procedure RewriteAndSkipRCFile;
procedure AppendToRCFile;
procedure RewriteRCFile;
function DoTheRealCompile: TModalResult;
procedure SetAutoIncrementBuild(const AValue: boolean);
procedure SetBuildNr(const AValue: integer);
procedure SetCommentsString(const AValue: string);
@ -102,7 +100,7 @@ type
public
constructor Create;
destructor Destroy; override;
function CompileRCFile(const MainFilename, TargetOS: string): TModalResult;
function CreateRCFile(const MainFilename, TargetOS: string): TModalResult;
function UpdateMainSourceFile(const AFilename: string): TModalResult;
property Modified: boolean read FModified write SetModified;
@ -310,70 +308,49 @@ begin
end;
{-----------------------------------------------------------------------------
TProjectVersionInfo CompileRCFile
TProjectVersionInfo CreateRCFile
-----------------------------------------------------------------------------}
function TProjectVersionInfo.CompileRCFile(const MainFilename, TargetOS: string
function TProjectVersionInfo.CreateRCFile(const MainFilename, TargetOS: string
): TModalResult;
begin
Result := mrCancel;
SetFileNames(MainFilename);
if (TargetOS = 'win32') then
Result := mrCancel;
SetFileNames(MainFilename);
if (TargetOS = 'win32') then
begin
// we are building a win32 application
if UseVersionInfo then
begin
// project indicates to use the versioninfo
if AutoIncrementBuild then // project indicate to use autoincrementbuild
BuildNr := BuildNr + 1;
if ProductVersionString = '' then
ProductVersionString := IntToStr(VersionNr) + '.' +
IntToStr(MajorRevNr) + '.' +
IntToStr(MinorRevNr) + '.' +
IntToStr(BuildNr);
if (FileExists(rcFilename)) then // we found an existing .rc file
RewriteRCFile
else
begin
{ we are building a win32 application }
if UseVersionInfo then
begin
{ project indicates to use the versioninfo }
if AutoIncrementBuild then
begin
{ project indicate to use autoincrementbuild }
BuildNr := BuildNr + 1;
end;
if ProductVersionString = '' then
ProductVersionString := IntToStr(VersionNr) + '.' +
IntToStr(MajorRevNr) + '.' +
IntToStr(MinorRevNr) + '.' +
IntToStr(BuildNr);
if (FileExists(rcFilename)) then
begin
{ we found an existing .rc file }
RewriteRCFile;
end
else
begin
{ there is no .rc file }
AssignFile(rcOutFile, rcFilename);
Rewrite(rcOutFile);
AppendToRCFile;
CloseFile(rcOutFile);
end;
{ now it's time to do the real compile }
Result := DoTheRealCompile;
if (Result = mrOk) then
begin
{ compilation succeeded }
VersionInfoMessages.Clear;
VersionInfoMessages.Add('Resource file ' + rcFilename +
' has been compiled successfully!');
end
else
begin
{ compilation failed }
VersionInfoMessages.Add('Errors found while compiling ' +
rcFilename);
end;
end
else
begin
{ project indicates to not use the versioninfo }
Result := mrOk;
end;
end
else
begin
{ on systems other then win32, there is nothing to do, just return
with Result = mrOk }
Result := mrOk;
// there is no .rc file
AssignFile(rcOutFile, rcFilename);
Rewrite(rcOutFile);
AppendToRCFile;
CloseFile(rcOutFile);
end;
Result := mrOk;
end
else
begin
// project indicates to not use the versioninfo
Result := mrOk;
end;
end
else
begin
// on systems other then win32, there is nothing to do, just return with Result = mrOk
Result := mrOk;
end;
end;
{-----------------------------------------------------------------------------
@ -472,64 +449,64 @@ end;
-----------------------------------------------------------------------------}
procedure TProjectVersionInfo.AppendToRCFile;
begin
rcLine := '1 VERSIONINFO';
WriteLn(rcoutFile, rcLine);
rcLine := 'FILEVERSION ' + IntToStr(VersionNr) + ',' +
IntToStr(MajorRevNr) + ',' +
IntToStr(MinorRevNr) + ',' +
IntToStr(BuildNr);
WriteLn(rcoutFile, rcLine);
rcLine := 'PRODUCTVERSION ' + StringReplace(ProductVersionString, '.', ',', [rfReplaceAll]);
WriteLn(rcoutFile, rcLine);
rcLine := '{';
WriteLn(rcoutFile, rcLine);
rcLine := ' BLOCK "StringFileInfo"';
WriteLn(rcoutFile, rcLine);
rcLine := ' {';
WriteLn(rcoutFile, rcLine);
rcLine := ' BLOCK "' + HexLang + HexCharSet + '"';
WriteLn(rcoutFile, rcLine);
rcLine := ' {';
WriteLn(rcoutFile, rcLine);
rcLine := ' VALUE "Comments", "' + CommentsString + '\000"';
WriteLn(rcoutFile, rcLine);
rcLine := ' VALUE "CompanyName", "' + CompanyString + '\000"';
WriteLn(rcoutFile, rcLine);
rcLine := ' VALUE "FileDescription", "' + DescriptionString + '\000"';
WriteLn(rcoutFile, rcLine);
rcLine := ' VALUE "FileVersion", "' + IntToStr(VersionNr) + '.' +
IntToStr(MajorRevNr) + '.' +
IntToStr(MinorRevNr) + '.' +
IntToStr(BuildNr) + '\000"';
WriteLn(rcoutFile, rcLine);
rcLine := ' VALUE "InternalName", "' + InternalNameString + '\000"';
WriteLn(rcoutFile, rcLine);
rcLine := ' VALUE "LegalCopyright", "' + CopyrightString + '\000"';
WriteLn(rcoutFile, rcLine);
rcLine := ' VALUE "LegalTrademarks", "' + TrademarksString + '\000"';
WriteLn(rcoutFile, rcLine);
rcLine := ' VALUE "OriginalFilename", "' + OriginalFilenameString + '\000"';
WriteLn(rcoutFile, rcLine);
rcLine := ' VALUE "ProductName", "' + ProdNameString + '\000"';
WriteLn(rcoutFile, rcLine);
rcLine := ' VALUE "ProductVersion", "' +
StringReplace(ProductVersionString, ',', '.', [rfReplaceAll]) +
'\000"';
WriteLn(rcoutFile, rcLine);
rcLine := ' }';
WriteLn(rcoutFile, rcLine);
rcLine := ' }';
WriteLn(rcoutFile, rcLine);
rcLine := ' BLOCK "VarFileInfo"';
WriteLn(rcoutFile, rcLine);
rcLine := ' {';
WriteLn(rcoutFile, rcLine);
rcLine := ' VALUE "Translation", 0x' + HexLang + ', 0x' + HexCharSet;
WriteLn(rcoutFile, rcLine);
rcLine := ' }';
WriteLn(rcoutFile, rcLine);
rcLine := '}';
WriteLn(rcoutFile, rcLine);
rcLine := '1 VERSIONINFO';
WriteLn(rcoutFile, rcLine);
rcLine := 'FILEVERSION ' + IntToStr(VersionNr) + ',' +
IntToStr(MajorRevNr) + ',' +
IntToStr(MinorRevNr) + ',' +
IntToStr(BuildNr);
WriteLn(rcoutFile, rcLine);
rcLine := 'PRODUCTVERSION ' + StringReplace(ProductVersionString, '.', ',', [rfReplaceAll]);
WriteLn(rcoutFile, rcLine);
rcLine := '{';
WriteLn(rcoutFile, rcLine);
rcLine := ' BLOCK "StringFileInfo"';
WriteLn(rcoutFile, rcLine);
rcLine := ' {';
WriteLn(rcoutFile, rcLine);
rcLine := ' BLOCK "' + HexLang + HexCharSet + '"';
WriteLn(rcoutFile, rcLine);
rcLine := ' {';
WriteLn(rcoutFile, rcLine);
rcLine := ' VALUE "Comments", "' + CommentsString + '\000"';
WriteLn(rcoutFile, rcLine);
rcLine := ' VALUE "CompanyName", "' + CompanyString + '\000"';
WriteLn(rcoutFile, rcLine);
rcLine := ' VALUE "FileDescription", "' + DescriptionString + '\000"';
WriteLn(rcoutFile, rcLine);
rcLine := ' VALUE "FileVersion", "' + IntToStr(VersionNr) + '.' +
IntToStr(MajorRevNr) + '.' +
IntToStr(MinorRevNr) + '.' +
IntToStr(BuildNr) + '\000"';
WriteLn(rcoutFile, rcLine);
rcLine := ' VALUE "InternalName", "' + InternalNameString + '\000"';
WriteLn(rcoutFile, rcLine);
rcLine := ' VALUE "LegalCopyright", "' + CopyrightString + '\000"';
WriteLn(rcoutFile, rcLine);
rcLine := ' VALUE "LegalTrademarks", "' + TrademarksString + '\000"';
WriteLn(rcoutFile, rcLine);
rcLine := ' VALUE "OriginalFilename", "' + OriginalFilenameString + '\000"';
WriteLn(rcoutFile, rcLine);
rcLine := ' VALUE "ProductName", "' + ProdNameString + '\000"';
WriteLn(rcoutFile, rcLine);
rcLine := ' VALUE "ProductVersion", "' +
StringReplace(ProductVersionString, ',', '.', [rfReplaceAll]) +
'\000"';
WriteLn(rcoutFile, rcLine);
rcLine := ' }';
WriteLn(rcoutFile, rcLine);
rcLine := ' }';
WriteLn(rcoutFile, rcLine);
rcLine := ' BLOCK "VarFileInfo"';
WriteLn(rcoutFile, rcLine);
rcLine := ' {';
WriteLn(rcoutFile, rcLine);
rcLine := ' VALUE "Translation", 0x' + HexLang + ', 0x' + HexCharSet;
WriteLn(rcoutFile, rcLine);
rcLine := ' }';
WriteLn(rcoutFile, rcLine);
rcLine := '}';
WriteLn(rcoutFile, rcLine);
end;
{-----------------------------------------------------------------------------
@ -611,58 +588,6 @@ begin
end;
end;
{-----------------------------------------------------------------------------
TProjectVersionInfo DoTheRealCompile
-----------------------------------------------------------------------------}
function TProjectVersionInfo.DoTheRealCompile: TModalResult;
const READ_BYTES = 2048;
var rcProcess: TProcess;
rcMemStream: TMemoryStream;
rcStringList: TStringList;
BytesRead: longint;
n: longint;
begin
Result := mrCancel;
rcMemStream := TMemoryStream.Create;
BytesRead := 0;
try
rcProcess := TProcess.Create(nil);
rcProcess.CommandLine := 'windres -v ' + rcFilename + ' ' + resFilename;
rcProcess.ShowWindow := swoHIDE;
rcProcess.Options := [poUsePipes, poStdErrToOutput];
rcProcess.Execute;
while rcProcess.Running do
begin
rcMemStream.SetSize(BytesRead + READ_BYTES);
n := rcProcess.OutPut.Read((rcMemStream.Memory + BytesRead)^, READ_BYTES);
if n > 0 then
begin
inc(BytesRead, n);
end
else
begin
sleep(100);
end;
end;
repeat
rcMemStream.SetSize(BytesRead + READ_BYTES);
n := rcProcess.Output.Read((rcMemStream.Memory + BytesRead)^, READ_BYTES);
if n > 0 then
begin
inc(BytesRead, n);
end;
until n <= 0;
finally
if rcProcess.ExitStatus = 0 then Result := mrOk;
rcProcess.Free;
end;
rcMemStream.SetSize(BytesRead);
rcStringList := TStringList.Create;
rcStringList.LoadFromStream(rcMemStream);
for n := 1 to rcStringList.Count do
VersionInfoMessages.Add(rcStringList[n - 1]);
end;
procedure TProjectVersionInfo.SetAutoIncrementBuild(const AValue: boolean);
begin
if FAutoIncrementBuild=AValue then exit;
@ -807,7 +732,7 @@ begin
VersionInfoCodeBuf:=CodeToolBoss.LoadFile(AFilename,false,false);
if VersionInfoCodeBuf=nil then exit;
SetFileNames(AFilename);
Filename:=ExtractFileName(resFilename);
Filename:=ExtractFileName(rcFilename);
//DebugLn(['TProjectVersionInfo.UpdateMainSourceFile ',Filename,' UseVersionInfo=',UseVersionInfo]);
if CodeToolBoss.FindResourceDirective(VersionInfoCodeBuf,1,1,
NewCode,NewX,NewY,
@ -843,8 +768,7 @@ end;
-----------------------------------------------------------------------------}
procedure TProjectVersionInfo.SetFileNames(const MainFilename: string);
begin
rcFilename := Copy(MainFilename, 1, Length(MainFilename) - 4) + '.rc';
resFilename := Copy(MainFilename, 1, Length(MainFilename) - 4) + '.res';
rcFilename := Copy(MainFilename, 1, Length(MainFilename) - 4) + '.rc';
end;
finalization