Class AnELFFileVersionInfoResource

DescriptionHierarchyFieldsMethodsProperties

Unit

Declaration

type AnELFFileVersionInfoResource = class(AFileVersionInfoResource)

Description

This class represents version information that is stored as a resource within the ELF object file that represents main code segment of the current process. This information is automatically compiled into the ELF object file by Lazarus and FPC when the developer requests version information be included on compilation.

This class is targeted specifically at ELF files, since Microsoft Windows provides the functions necessary to obtain version information from Windows executables.

Hierarchy

Overview

Fields

Protected myHandleFromFile: TFPResourceHandle;
Protected myHandleInMemory: TFPResourceHGlobal;
Protected myFixedInfoLength: word;
Protected myDataType: word;
Protected myKey: WideString;
Protected myFixedInfo: PVSFixedFileInfo;

Methods

Protected function parseVSVersionInfo(var rawdata: pchar): boolean; virtual;
Protected function parseStringFileInfo(var rawdata: pchar): boolean; virtual;
Protected function parseStringTable(var rawdata: pchar): boolean; virtual;
Protected function parseString(var rawdata: pchar): boolean; virtual;
Public function init: boolean; override;
Public destructor destroy; override;
Public function readInto(const ThisDictionary: ADictionary): boolean; override;
Public function fixedInfoLength: word; virtual;
Public function dataType: word; virtual;
Public function key: WideString; virtual;
Public function fixedInfo: PVSFixedFileInfo; virtual;

Description

Fields

Protected myHandleFromFile: TFPResourceHandle;

Stores the handle to the resource before it is loaded into memory

Protected myHandleInMemory: TFPResourceHGlobal;

Stores the handle to the resource

Protected myFixedInfoLength: word;

Stores the length, in bytes, of any fixed version information

Protected myDataType: word;

Stores the type of data stored in the version resource

Protected myKey: WideString;

Stores the key that identifies valid valid version information

Protected myFixedInfo: PVSFixedFileInfo;

Stores fixed version information, if any

Methods

Protected function parseVSVersionInfo(var rawdata: pchar): boolean; virtual;

Read the VS_VERSIONINFO pseudo-structure.

This method reads the VS_VERSIONINFO pseudo-structure from the raw resource data. This pseudo-structure defines the overall attributes of the version information contained within the version resource. It is called a pseudo-structure because its size and the position of some of its members cannot be known at compile-time. Nonetheless, the structure begins with some elements whose sizes and positions are known; these are represented by the TTypicalVersionInfoHeader structure.

This method checks that the szKey member of the pseudo-structure matches the value of vsVersionInfoKey; this is one way of validating that the correct pseudo-structure is being read. If the values do not match, the method exits immediately, returning False.

If the wValueLength member of the pseudo-structure has a value that is greater than zero (0), then this method will point Self.fixedInfo at the data represented by the Value member of the pseudo-structure, which is described by TVSFixedFileInfo.

Finally, the method will call AnELFFileVersionInfoResource.parseStringFileInfo to parse the StringFileInfo structure that is contained in the Children pseudo-field of the pseudo-structure. The return value of that call is returned by this method.

rawdata must point to the raw resource data which will be used to parse the VS_VERSIONINFO pseudo-structure. This pointer will be advanced as the structure is parsed. If rawdata is Nil, then this method will do nothing and will return False.

Protected function parseStringFileInfo(var rawdata: pchar): boolean; virtual;

This method reads the StringFileInfo pseudo-structure from the raw resource data. This pseudo-structure defines the attributes of the string tables which make up the version information in the file. There can be more than one string table in the version resource.

The structure is called a pseudo-structure because its overall size and the position of some of its members cannot be known at compile-time. However, the structure begins with some elements whose sizes and positions are known; these are represented by the TTypicalVersionInfoHeader structure.

This method checks that the szKey member of the pseudo-structure matches the value of vsStringInfoKey; this is one way of validating that the correct pseudo-structure is being read. If the values do not match, the method exits immediately, returning False.

Finally, the method will loop through calls to AnELFFileVersionInfoResource.parseStringTable to parse the array of StringTable pseudo-structures which are contained in the Children pseudo-field of the pseudo-structure. If the call should return False at any point in the loop, then the loop is broken. The loop ends when rawdata passes beyond the end of the pseudo-structure's boundaries, as determined by comparing rawdata to the value of rawdata + StringFileInfo.wLength.

rawdata must point to the raw resource data which will be used to parse the StringInfo pseudo-structure. The pointer will be advanced as the structure is parsed. If rawdata is Nil, then this routine will do nothing and will return False.

Protected function parseStringTable(var rawdata: pchar): boolean; virtual;

This method reads a StringTable pseudo-structure from the raw resource data. This pseudo-structure defines the attributes of the key/value pairs which make up the version information in the file. There can be more than one string table in the version resource; typically, there is one for each language and code page supported by the program.

The structure is called a pseudo-structure because its overall size and the position of some of its members cannot be known at compile-time. However, the structure begins with some elements whose sizes and positions are known; these are represented by the TTypicalVersionInfoHeader structure.

Finally, the method will loop through calls to AnELFFileVersionInfoResource.parseString to parse the array of String pseudo-structures which are contained in the Children pseudo-field of the pseudo-structure. If the call should return False at any point in the loop, then the loop is broken. The loop ends when rawdata passes beyond the end of the pseudo-structure's boundaries, as determined by comparing rawdata to the value of rawdata + StringTable.wLength.

rawdata must point to the raw resource data which will be used to parse the StringTable pseudo-structure. The pointer will be advanced as the structure is parsed. If rawdata is Nil, then this routine will do nothing and will return False.

Protected function parseString(var rawdata: pchar): boolean; virtual;

This method reads a String pseudo-structure from the raw resource data. This pseudo-structure defines the key/value pairs which make up the version information in the file. There are typicall several such pairs in the version resource.

The structure is called a pseudo-structure because its overall size and the position of some of its members cannot be known at compile-time. However, the structure begins with some elements whose sizes and positions are known; these are represented by the TTypicalVersionInfoHeader structure.

If the Children pseudo-field of the structure defines a non-empty string, then this method will insert the value of the szKey member of the pseudo-structure, along with the value of the Children pseudo-field, into Self.VersionInfo.

rawdata must point to the raw resource data which will be used to parse the String pseudo-structure. The pointer will be advanced as the structure is parsed. If rawdata is Nil, then this routine will do nothing and will return False.

Public function init: boolean; override;

Initializer

Public destructor destroy; override;

Destroy the version resource.

This method will call System.unlockResource() and System.freeResource() to release and free the raw resource data before calling the inherited routine.

Public function readInto(const ThisDictionary: ADictionary): boolean; override;

Read version information from the resource information for the current executable.

This method makes use of a few routines that are available in the FPC System unit, including System.findResource(), System.loadResource(), System.sizeOfResource() and System.lockResource().

The method first calls System.findResource() to find the RT_VERSION resource in the current executable. If the resource is found, the method then calls System.loadResource() to load the resource into memory, and then System.sizeOfResource() to determine its size and System.lockResource() to obtain access to the raw resource data. It then calls AnELFFileVersionInfoResource.parseVSVersionInfo to parse the VS_VERSIONINFO pseudo-structure from the resource data.

Returns

True if the version information was successfully loaded and parsed; False otherwise. If the version information was parsed successfully, the keys and values that make up the version information will be added to ThisDictionary. If ThisDictionary is Nil, this routine will do nothing and will return False.

Public function fixedInfoLength: word; virtual;

Retrieve the length, in bytes, of any fixed information in the resource

Public function dataType: word; virtual;

Retrieve the type of data stored in the version resource.

The value returned by this method will be zero (0) if the resource contains binary data and one (1) if the resource contains strings.

Public function key: WideString; virtual;

Retrieve the key that identifies valid version information

Public function fixedInfo: PVSFixedFileInfo; virtual;

Retrieve a reference to the fixed version information, if any


Generated by PasDoc 0.13.0 on 2015-01-10 17:13:18