A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://github.com/resourcelib/resourcelib/wiki/Version-(RT_VERSION) below:

Version (RT_VERSION) · resourcelib/resourcelib Wiki · GitHub

When ResourceInfo encounters a resource of type 16 (RT_VERSION), it creates an object of type VersionResource.

A version resource is stored in a VS_VERSIONINFO root structure, which contains the following file-version information.

Reading Version Resources

The following example loads file version information directly, without enumerating all resources.

string filename = Path.Combine(Environment.SystemDirectory, "atl.dll");
VersionResource versionResource = new VersionResource();
versionResource.LoadFrom(filename);
Console.WriteLine("File version: {0}", versionResource.FileVersion);
StringFileInfo stringFileInfo = (StringFileInfo) versionResource["StringFileInfo"];
foreach (KeyValuePair<string, StringTableEntry> stringTableEntry in stringFileInfo.Default.Strings)
{
  Console.WriteLine("{0} = {1}", stringTableEntry.Value.Key, stringTableEntry.Value.StringValue);
}
Writing Version Information

The easiest way to update version information is to load an existing binary resource, update it and save it back.

string filename = "test.dll";
VersionResource versionResource = new VersionResource();
versionResource.LoadFrom(filename);
Console.WriteLine("File version: {0}", versionResource.FileVersion);
versionResource.FileVersion = "1.2.3.4";
StringFileInfo stringFileInfo = (StringFileInfo) versionResource["StringFileInfo"];
stringFileInfo["CompanyName"] = "My Company\0";
stringFileInfo["Weather"] = "Sunshine, beach volleyball.\0"; 
versionResource.SaveTo(filename);

Note that internally string resources are stored with an extra null terminator, a requirement of the Windows operating system. The library is consistent with this and always stores the value with a unicode null terminator while doing the work of appending it to the assigned value when required.

Generating a complete version resource header allows you to save version information into a file that doesn't have any. This is more involved because you must generate all the structures. ResourceLib makes it easy since you don't have to worry about structure sizes or data alignment.

VersionResource versionResource = new VersionResource();
versionResource.FileVersion = "1.2.3.4";
versionResource.ProductVersion = "4.5.6.7";

StringFileInfo stringFileInfo = new StringFileInfo();
versionResource[stringFileInfo.Key] = stringFileInfo;
StringTable stringFileInfoStrings = new StringTable();
stringFileInfoStrings.LanguageID = 1033;
stringFileInfoStrings.CodePage = 1200;
stringFileInfo.Strings.Add(stringFileInfoStrings.Key, stringFileInfoStrings);
stringFileInfoStrings["ProductName"] = "ResourceLib";
stringFileInfoStrings["FileDescription"] = "File updated by ResourceLib";
stringFileInfoStrings["CompanyName"] = "Vestris Inc.\0"; // \0 is optional, ResourceLib will append it
stringFileInfoStrings["LegalCopyright"] = "All Rights Reserved";
stringFileInfoStrings["Comments"] = "This file has a version resource updated by ResourceLib";
stringFileInfoStrings["ProductVersion"] = string.Format("{0}\0", versionResource.ProductVersion);

VarFileInfo varFileInfo = new VarFileInfo();
versionResource[varFileInfo.Key] = varFileInfo;
VarTable varFileInfoTranslation = new VarTable("Translation");
varFileInfo.Vars.Add(varFileInfoTranslation.Key, varFileInfoTranslation);
varFileInfoTranslation[ResourceUtil.USENGLISHLANGID] = 1300;

versionResource.SaveTo(filename);

.NET assemblies use slightly different headers for strings in a StringFileInfo block. (The indicated length for a string also considers the padding). You can write in this format by setting the static flag StringTableEntry.ConsiderPaddingForLength = true before saving.


RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4