Skip to content

Go wrapper for querying windows version-information resource.

License

Notifications You must be signed in to change notification settings

bi-zone/go-fileversion

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

12 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

go-fileversion

GoDoc Go Report Card

Package fileversion provides wrapper for querying properties from windows version-information resource.

Using the package you can extract the following info:

properties example

If you are looking how to add this info to your go binary - look at josephspurrier/goversioninfo.

Examples

Print version info from input file

package main

import (
	"fmt"
	"log"
	"os"

	"github.com/bi-zone/go-fileversion"
)

func main() {
	if len(os.Args) < 2 {
		log.Fatalf("Usage: %s <image-path>", os.Args[0])
	}
	f, err := fileversion.New(os.Args[1])
	if err != nil {
		log.Fatal(err)
	}
	fmt.Println("ProductName:", f.ProductName())
	fmt.Println("LegalCopyright:", f.LegalCopyright())
	fmt.Println("Version:", f.FixedInfo().FileVersion)
}

All string properties in file version-information resource by-design has multiple translations. go-fileversion allows you to query that translations in a 2 ways.

You can create an Info object with "preferred" locale:

germanLocale := fileversion.Locale{
    LangID: 0x0407, // langID German
    CharsetID: fileversion.CSUnicode,
}
f, err := fileversion.NewWithLocale(os.Args[1], germanLocale)
if err != nil {
    log.Fatal(err)
}
fmt.Println("ProductName:", f.ProductName())

Here "German-Unicode" locale will be used to query string properties (like ProductName), but if the german translation will be missing - go-fileversion would try to fetch a property with default translation. (The idea of locales handling was copied from .NET Framework 4.8)

The only way to get necessary translation without any heuristics is to use GetPropertyWithLocale manualy:

f, err := fileversion.New(os.Args[1])
if err != nil {
    log.Fatal(err)
}
germanLocale := fileversion.Locale{
    LangID: 0x0407, // langID German
    CharsetID: fileversion.CSUnicode,
}
fmt.Println(f.GetPropertyWithLocale("ProductName", germanLocale))

Versioning

Project uses semantic versioning for version numbers, which is similar to the version contract of the Go language. Which means that the major version will always maintain backwards compatibility with minor versions. Minor versions will only add new additions and changes. Fixes will always be in patch.

This contract should allow you to upgrade to new minor and patch versions without breakage or modifications to your existing code. Leave a ticket, if there is breakage, so that it could be fixed.