Skip to content

Commit

Permalink
Update readme, add icon flag to main.go
Browse files Browse the repository at this point in the history
  • Loading branch information
josephspurrier committed Jan 24, 2015
1 parent e96bcb0 commit 491ad42
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 47 deletions.
88 changes: 43 additions & 45 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,59 +2,57 @@ GoVersionInfo
==========
[![Build Status](https://travis-ci.org/josephspurrier/goversioninfo.svg)](https://travis-ci.org/josephspurrier/goversioninfo) [![Coverage Status](https://coveralls.io/repos/josephspurrier/goversioninfo/badge.png)](https://coveralls.io/r/josephspurrier/goversioninfo) [![GoDoc](https://godoc.org/github.com/josephspurrier/goversioninfo?status.svg)](https://godoc.org/github.com/josephspurrier/goversioninfo)

Golang Microsoft Version Info and Icon Resource Generator
Microsoft Version Info and Icon Resource Generator for the Go Language

Package creates a syso file which contains Microsoft Version Information and an optional icon. When you run "go build", Go will embed the version information and icon in the executable. Go will automatically use the syso if it's in the same directory as the main() function. Documentation available on [GoDoc](https://godoc.org/github.com/josephspurrier/goversioninfo).

## Using the Package
## Instructions

Copy versioninfo.json and an icon named icon.ico into your working directory. Fill versioninfo.json with your own information. Use the code below to generate a syso file named resource.syso.
To install, run the following command:

~~~ go
package main

import (
"fmt"
"io/ioutil"

"github.com/josephspurrier/goversioninfo"
)

func main() {
// Read the config file
jsonBytes, err := ioutil.ReadFile("versioninfo.json")
if err != nil {
log.Printf("Error reading %q: %v", configFile, err)
os.Exit(1)
}

// Create a new container
vi := &goversioninfo.VersionInfo{}

// Parse the config
if err := vi.ParseJSON(jsonBytes); err != nil {
log.Printf("Could not parse the .json file: %v", err)
os.Exit(2)
}

// Fill the structures with config data
vi.Build()

// Write the data to a buffer
vi.Walk()

// Optionally, embed an icon by path
// If the icon has multiple sizes, all of the sizes will be embedded
vi.IconPath = "icon.ico"

// Create the file
if err := vi.WriteSyso("resource.syso"); err != nil {
log.Printf("Error writing syso: %v", err)
os.Exit(3)
}
}
go get github.com/josephspurrier/goversioninfo/cmd/goversioninfo
~~~

Then to utilize the wonderful "go generate" command, add a similar text to the top of your Go source code:
~~~ go
//go:generate goversioninfo -file-version=v2.0.0.0 -ver-major=2 -ver-minor=0 -ver-patch=0 -ver-build=0 -icon=icon.ico
~~~

Run "go generate" before each build and goversioninfo.exe will create a file called resource.syso in the same directory as the Go source code.

## Comman-Line Flags

A complete list of the flags you can pass to goversioninfo.exe are below:

~~ go
-charset=0: charset ID
-comment="": StringFileInfo.Comments
-company="": StringFileInfo.CompanyName
-copyright="": StringFileInfo.LegalCopyright
-description="": StringFileInfo.FileDescription
-example=false: just dump out an example versioninfo.json to stdout
-file-version="": StringFileInfo.FileVersion
-icon="": icon file name
-internal-name="": StringFileInfo.InternalName
-o="resource.syso": output file name
-original-name="": StringFileInfo.OriginalFilename
-private-build="": StringFileInfo.PrivateBuild
-product-name="": StringFileInfo.ProductName
-product-version="": StringFileInfo.ProductVersion
-special-build="": StringFileInfo.SpecialBuild
-trademark="": StringFileInfo.LegalTrademarks
-translation=0: translation ID
-ver-build=-1: FileVersion.Build
-ver-major=-1: FileVersion.Major
-ver-minor=-1: FileVersion.Minor
-ver-patch=-1: FileVersion.Patch
~~~
You can look over the Microsoft Resource Information: (VERSIONINFO resource)[https://msdn.microsoft.com/en-us/library/windows/desktop/aa381058(v=vs.85).aspx]
You can look through the Microsoft Version Information structures: (Version Information Structures)[https://msdn.microsoft.com/en-us/library/windows/desktop/ff468916(v=vs.85).aspx]
## Major Contributions
Thanks to [Mateusz Czaplinski](https://github.com/akavel/rsrc) for his embedded binary resource package.
Expand Down
4 changes: 4 additions & 0 deletions cmd/goversioninfo/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import (
func main() {
flagExample := flag.Bool("example", false, "just dump out an example versioninfo.json to stdout")
flagOut := flag.String("o", "resource.syso", "output file name")
flagIcon := flag.String("icon", "", "icon file name")

flagComment := flag.String("comment", "", "StringFileInfo.Comments")
flagCompany := flag.String("company", "", "StringFileInfo.CompanyName")
Expand Down Expand Up @@ -92,6 +93,9 @@ func main() {
}

// Override from flags
if *flagIcon != "" {
vi.IconPath = *flagIcon
}
if *flagComment != "" {
vi.StringFileInfo.Comments = *flagComment
}
Expand Down
4 changes: 2 additions & 2 deletions versioninfo.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@
"Patch": 0,
"Build": 0
},
"FileFlagsMask": "0b",
"FileFlagsMask": "3f",
"FileFlags ": "00",
"FileOS": "04",
"FileOS": "040004",
"FileType": "01",
"FileSubType": "00"
},
Expand Down

0 comments on commit 491ad42

Please sign in to comment.