Skip to content

Commit

Permalink
Added ability to include manifest
Browse files Browse the repository at this point in the history
Updated readme, integrated manifest code from github.com/akavel/rsrc
  • Loading branch information
josephspurrier committed Mar 31, 2016
1 parent 4b1b969 commit f8c5d36
Show file tree
Hide file tree
Showing 9 changed files with 181 additions and 3 deletions.
32 changes: 29 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ Copy versioninfo.json into your working directory and then modify the file with

Add a similar text to the top of your Go source code:
~~~ go
//go:generate goversioninfo -icon=icon.ico
//go:generate goversioninfo -icon=icon.ico -manifest=goversioninfo.exe.manifest
~~~

Run the Go commands in this order so goversioninfo will create a file called resource.syso in the same directory as the Go source code.
Expand All @@ -44,6 +44,7 @@ Complete list of the flags for goversioninfo:
-file-version="": StringFileInfo.FileVersion
-icon="": icon file name
-internal-name="": StringFileInfo.InternalName
-manifest="": manifest file name
-o="resource.syso": output file name
-original-name="": StringFileInfo.OriginalFilename
-private-build="": StringFileInfo.PrivateBuild
Expand All @@ -62,8 +63,33 @@ You can look over the Microsoft Resource Information: [VERSIONINFO resource](htt

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)

## Alternatives to this Tool

You can also use [windres](https://sourceware.org/binutils/docs/binutils/windres.html) to create the syso file. The windres executable is available in either [MinGW](http://www.mingw.org/) or [tdm-gcc](http://tdm-gcc.tdragon.net/).

Below is a sample batch file you can use to create a .syso file from a .rc file. There are sample .rc files in the rc folder.

~~~
@ECHO OFF
SET PATH=C:\TDM-GCC-64\bin;%PATH%
REM SET PATH=C:\mingw64\bin;%PATH%
windres -i versioninfo.rc -O coff -o versioninfo.syso
PAUSE
~~~

The information on how to create a .rc file is available [here](https://msdn.microsoft.com/en-us/library/windows/desktop/aa381043(v=vs.85).aspx). You can use the versioninfo.rc file to create a syso file that contains version info, icon, and manifest.

## Issues

The majority of the code for the creation of the syso file is from this package: [https://github.com/akavel/rsrc](https://github.com/akavel/rsrc)

There is an issue with adding the icon resource that prevents your application from being compressed or modified with a resource editor. Please use with caution.

## Major Contributions

Thanks to [Tamás Gulácsi](https://github.com/tgulacsi) for his superb code additions, refactoring, optimization to make this a solid package.
Thanks to [Tamás Gulácsi](https://github.com/tgulacsi) for his superb code additions, refactoring, and optimization to make this a solid package.

Thanks to [Mateusz Czaplinski](https://github.com/akavel/rsrc) for his embedded binary resource package.
Thanks to [Mateusz Czaplinski](https://github.com/akavel/rsrc) for his embedded binary resource package with icon and manifest functionality.
4 changes: 4 additions & 0 deletions cmd/goversioninfo/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ 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")
flagManifest := flag.String("manifest", "", "manifest file name")

flagComment := flag.String("comment", "", "StringFileInfo.Comments")
flagCompany := flag.String("company", "", "StringFileInfo.CompanyName")
Expand Down Expand Up @@ -83,6 +84,9 @@ func main() {
if *flagIcon != "" {
vi.IconPath = *flagIcon
}
if *flagManifest != "" {
vi.ManifestPath = *flagManifest
}
if *flagComment != "" {
vi.StringFileInfo.Comments = *flagComment
}
Expand Down
22 changes: 22 additions & 0 deletions goversioninfo.exe.manifest
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0">
<dependency>
<dependentAssembly>
<assemblyIdentity
type="win32"
name="Github.com.JosephSpurrier.GoVersionInfo"
version="1.0.0.0"
language="*"
processorArchitecture="*"/>
</dependentAssembly>
</dependency>
<trustInfo xmlns="urn:schemas-microsoft-com:asm.v3">
<security>
<requestedPrivileges>
<requestedExecutionLevel
level="asInvoker"
uiAccess="false"/>
</requestedPrivileges>
</security>
</trustInfo>
</assembly>
14 changes: 14 additions & 0 deletions goversioninfo.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ type VersionInfo struct {
Buffer bytes.Buffer
Structure VSVersionInfo
IconPath string
ManifestPath string
}

// Translation with langid and charsetid.
Expand Down Expand Up @@ -186,6 +187,19 @@ func (vi *VersionInfo) WriteSyso(filename string) error {
// ID 16 is for Version Information
coff.AddResource(16, 1, SizedReader{&vi.Buffer})

// If manifest is enabled
if vi.ManifestPath != "" {

manifest, err := binutil.SizedOpen(vi.ManifestPath)
if err != nil {
return err
}
defer manifest.Close()

id := <-newID
coff.AddResource(rtManifest, id, manifest)
}

// If icon is enabled
if vi.IconPath != "" {
if err := addIcon(coff, vi.IconPath, newID); err != nil {
Expand Down
1 change: 1 addition & 0 deletions icon.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ THE SOFTWARE.
const (
rtIcon = coff.RT_ICON
rtGroupIcon = coff.RT_GROUP_ICON
rtManifest = coff.RT_MANIFEST
)

// on storing icons, see: http://blogs.msdn.com/b/oldnewthing/archive/2012/07/20/10331787.aspx
Expand Down
28 changes: 28 additions & 0 deletions rc/cmd.rc
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
1 VERSIONINFO
FILEVERSION 6,3,9600,16384
PRODUCTVERSION 6,3,9600,16384
FILEFLAGSMASK 0X3FL
FILEFLAGS 0L
FILEOS 0X40004L
FILETYPE 0X1
FILESUBTYPE 0
BEGIN
BLOCK "StringFileInfo"
BEGIN
BLOCK "040904B0"
BEGIN
VALUE "CompanyName", "Microsoft Corporation"
VALUE "FileDescription", "Windows Command Processor"
VALUE "FileVersion", "6.3.9600.16384 (winblue_rtm.130821-1623)"
VALUE "InternalName", "cmd"
VALUE "LegalCopyright", "© Microsoft Corporation. All rights reserved."
VALUE "OriginalFilename", "Cmd.Exe"
VALUE "ProductName", "Microsoft® Windows® Operating System"
VALUE "ProductVersion", "6.3.9600.16384"
END
END
BLOCK "VarFileInfo"
BEGIN
VALUE "Translation", 0x0409, 0x04B0
END
END
28 changes: 28 additions & 0 deletions rc/control.rc
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
1 VERSIONINFO
FILEVERSION 6,3,9600,16384
PRODUCTVERSION 6,3,9600,16384
FILEFLAGSMASK 0X3FL
FILEFLAGS 0L
FILEOS 0X40004L
FILETYPE 0X1
FILESUBTYPE 0
BEGIN
BLOCK "StringFileInfo"
BEGIN
BLOCK "040904B0"
BEGIN
VALUE "CompanyName", "Microsoft Corporation"
VALUE "FileDescription", "Windows Control Panel"
VALUE "FileVersion", "6.3.9600.16384 (winblue_rtm.130821-1623)"
VALUE "InternalName", "Control"
VALUE "LegalCopyright", "© Microsoft Corporation. All rights reserved."
VALUE "OriginalFilename", "CONTROL.EXE"
VALUE "ProductName", "Microsoft® Windows® Operating System"
VALUE "ProductVersion", "6.3.9600.16384"
END
END
BLOCK "VarFileInfo"
BEGIN
VALUE "Translation", 0x0409, 0x04B0
END
END
28 changes: 28 additions & 0 deletions rc/explorer.rc
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
1 VERSIONINFO
FILEVERSION 6,3,9600,17284
PRODUCTVERSION 6,3,9600,17284
FILEFLAGSMASK 0X3FL
FILEFLAGS 0L
FILEOS 0X40004L
FILETYPE 0X1
FILESUBTYPE 0
BEGIN
BLOCK "StringFileInfo"
BEGIN
BLOCK "040904B0"
BEGIN
VALUE "CompanyName", "Microsoft Corporation"
VALUE "FileDescription", "Windows Explorer"
VALUE "FileVersion", "6.3.9600.17284 (winblue_r2.140822-1915)"
VALUE "InternalName", "explorer"
VALUE "LegalCopyright", "© Microsoft Corporation. All rights reserved."
VALUE "OriginalFilename", "EXPLORER.EXE"
VALUE "ProductName", "Microsoft® Windows® Operating System"
VALUE "ProductVersion", "6.3.9600.17284"
END
END
BLOCK "VarFileInfo"
BEGIN
VALUE "Translation", 0x0409, 0x04B0
END
END
27 changes: 27 additions & 0 deletions rc/versioninfo.rc
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#define RT_MANIFEST 24

1 VERSIONINFO
FILEVERSION 1,0,0,0
PRODUCTVERSION 1,0,0,0
FILEFLAGSMASK 0X3FL
FILEFLAGS 0L
FILEOS 0X40004L
FILETYPE 0X1
FILESUBTYPE 0
BEGIN
BLOCK "StringFileInfo"
BEGIN
BLOCK "040904B0"
BEGIN
VALUE "ProductVersion", "v1.0.0.0"
END
END
BLOCK "VarFileInfo"
BEGIN
VALUE "Translation", 0x0409, 0x04B0
END
END

1 ICON "icon.ico"

1 RT_MANIFEST "goversioninfo.exe.manifest"

0 comments on commit f8c5d36

Please sign in to comment.