version

package
v0.3.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 18, 2024 License: 0BSD Imports: 10 Imported by: 22

Documentation

Overview

Package version provides functions to build a VERSIONINFO structure for Windows applications.

This what Windows displays in the Details tab of file properties.

Index

Examples

Constants

View Source
const (
	Comments         = "Comments"
	CompanyName      = "CompanyName"
	FileDescription  = "FileDescription"
	FileVersion      = "FileVersion"
	InternalName     = "InternalName"
	LegalCopyright   = "LegalCopyright"
	LegalTrademarks  = "LegalTrademarks"
	OriginalFilename = "OriginalFilename"
	PrivateBuild     = "PrivateBuild"
	ProductName      = "ProductName"
	ProductVersion   = "ProductVersion"
	SpecialBuild     = "SpecialBuild"
)
View Source
const (
	App fileType = iota
	DLL
	Unknown
)
View Source
const (
	// LangNeutral is the LCID for language agnostic data.
	LangNeutral = 0
	// LangDefault is the LCID for en-US, and it is the default in many tools and APIs.
	LangDefault = 0x409
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Info

type Info struct {
	FileVersion    [4]uint16
	ProductVersion [4]uint16
	Flags          versionFlags
	Type           fileType
	Timestamp      time.Time
	// contains filtered or unexported fields
}

Info is the main struct of this package. Create one as Info{}, use Info.Set() to add key/value pairs, set other members, then add it to the resource set with Info.AddTo.

Example
vi := Info{}
// Set some info in the fixed structure
vi.ProductVersion = [4]uint16{1, 0, 0, 1}
// Set some info in the string table
vi.Set(0x409, ProductName, "Good Product")
vi.Set(0x40C, ProductName, "Bon Produit")
// Once it's complete, make a resource
// resourceData := vi.Bytes()
// ...
Output:

func FromBytes

func FromBytes(data []byte) (*Info, error)

FromBytes loads an Info from the binary representation of a VS_VERSIONINFO struct.

func MergeTranslations

func MergeTranslations(translations map[uint16]*Info) *Info

MergeTranslations merges several VERSIONINFO structs into one multilingual struct.

The fixed part will be taken in priority from:

  1. The neutral language (zero)
  2. The default language (en-US)
  3. The first language ID in ascending order

Each struct corresponds to one translation, and its language ID will be the one it is mapped to.

This means that each struct is supposed to contain exactly one translation, either neutral or of same language ID as it is mapped to.

If a struct contains several translations, those that don't correspond to the map key will be ignored.

If a struct contains one translation with a different language ID, it will be imported as if it had been the same value as the map key.

func (*Info) Bytes

func (vi *Info) Bytes() []byte

Bytes returns the binary representation of the VS_VERSIONINFO struct.

func (*Info) MarshalJSON

func (vi *Info) MarshalJSON() ([]byte, error)

func (*Info) Set

func (vi *Info) Set(langID uint16, key string, value string) error

Set sets a key/value pair in the Info structure for a specific locale.

Standard keys are defined as constants in this package: version.ProductName, version.CompanyName, ...

Strings must not contain NUL characters.

Language Code Identifiers (LCID) are listed there: https://docs.microsoft.com/en-us/openspecs/windows_protocols/ms-lcid/

langID may also be 0 for neutral.

Example
vi := Info{}
// 0x409 is en-US, and the default language
vi.Set(0x409, ProductName, "Good Product")
// 0x40C is fr-FR
vi.Set(0x40C, ProductName, "Bon Produit")
// 0 is neutral
vi.Set(0, "Smile", "😀")
Output:

func (*Info) SetFileVersion

func (vi *Info) SetFileVersion(fileVersion string)

SetFileVersion sets the file version, ensuring this is the only one in the structure.

This should be called after json.Unmarshal to override the version.

func (*Info) SetProductVersion

func (vi *Info) SetProductVersion(productVersion string)

SetProductVersion sets the product version, ensuring this is the only one in the structure.

This should be called after json.Unmarshal to override the version.

func (*Info) SplitTranslations

func (vi *Info) SplitTranslations() map[uint16]*Info

SplitTranslations splits the Info struct by language. It returns a map indexed by language ID.

Windows Explorer doesn't seem to search for a proper translation inside the VERSIONINFO struct. So one has to embed a whole VERSIONINFO for each language as a resource translation.

func (*Info) Table added in v0.3.0

func (vi *Info) Table() LangTable

Table returns a copy of the language and containing string tables, which hold key/value metadata.

func (*Info) UnmarshalJSON

func (vi *Info) UnmarshalJSON(b []byte) error

type LangTable added in v0.3.0

type LangTable map[uint16]*StringTable

LangTable holds different languages.

func (LangTable) GetMainTranslation added in v0.3.0

func (lt LangTable) GetMainTranslation() StringTable

GetMainTranslation returns the main translation.

type StringTable added in v0.3.0

type StringTable map[string]string

StringTable holds key/value metadata.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL