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
|
{
/***************************************************************************
w32manifest.pas - Lazarus IDE unit
---------------------------------------
TProjectXPManifest is responsible for the inclusion of the
manifest in windows executables.
***************************************************************************/
***************************************************************************
* *
* This source 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 2 of the License, or *
* (at your option) any later version. *
* *
* This code 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. *
* *
* A copy of the GNU General Public License is available on the World *
* Wide Web at <http://www.gnu.org/copyleft/gpl.html>. You can also *
* obtain it by writing to the Free Software Foundation, *
* Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
* *
***************************************************************************
}
unit W32Manifest;
{$mode objfpc}{$H+}
interface
uses
Classes, SysUtils, FileUtil, Process, LCLProc, Controls, Forms,
CodeToolManager, LazConf, LResources, projectresourcesintf;
type
{ TProjectXPManifest }
TProjectXPManifest = class(TAbstractProjectResource)
private
FUseManifest: boolean;
FManifestFileName: string;
procedure SetFileNames(const MainFilename: string);
procedure SetUseManifest(const AValue: boolean);
public
function UpdateResources(AResources: TAbstractProjectResources; const MainFilename: string): Boolean; override;
function CreateManifestFile: Boolean;
property UseManifest: boolean read FUseManifest write SetUseManifest;
property ManifestFileName: String read FManifestFileName write FManifestFileName;
end;
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';
sManifestFileData: String =
'<?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>';
procedure TProjectXPManifest.SetFileNames(const MainFilename: string);
begin
FManifestFileName := ChangeFileExt(MainFilename, '.manifest');
end;
procedure TProjectXPManifest.SetUseManifest(const AValue: boolean);
begin
if FUseManifest = AValue then exit;
FUseManifest := AValue;
Modified := True;
end;
function TProjectXPManifest.UpdateResources(AResources: TAbstractProjectResources;
const MainFilename: string): Boolean;
var
ManifestName: String;
begin
Result := True;
if not UseManifest then
Exit;
SetFileNames(MainFilename);
if not FilenameIsAbsolute(FManifestFileName) or CreateManifestFile then
begin
ManifestName := ExtractFileName(FManifestFileName);
AResources.AddSystemResource(sManifest + ' "' + ManifestName + '"');
end
else
Result := False;
end;
function TProjectXPManifest.CreateManifestFile: Boolean;
var
FileStream: TStream;
begin
Result := False;
FileStream := nil;
try
FileStream := TFileStream.Create(UTF8ToSys(FManifestFileName), fmCreate);
FileStream.Write(sManifestFileData[1], Length(sManifestFileData));
Result := True;
finally
FileStream.Free;
end;
end;
end.
|