diff --git a/README.md b/README.md index b060092..252f162 100644 --- a/README.md +++ b/README.md @@ -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. @@ -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 @@ -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. diff --git a/cmd/goversioninfo/main.go b/cmd/goversioninfo/main.go index 536cbe3..aee3f0e 100644 --- a/cmd/goversioninfo/main.go +++ b/cmd/goversioninfo/main.go @@ -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") @@ -83,6 +84,9 @@ func main() { if *flagIcon != "" { vi.IconPath = *flagIcon } + if *flagManifest != "" { + vi.ManifestPath = *flagManifest + } if *flagComment != "" { vi.StringFileInfo.Comments = *flagComment } diff --git a/goversioninfo.exe.manifest b/goversioninfo.exe.manifest new file mode 100644 index 0000000..63b484d --- /dev/null +++ b/goversioninfo.exe.manifest @@ -0,0 +1,22 @@ + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/goversioninfo.go b/goversioninfo.go index 6827c36..8b94260 100644 --- a/goversioninfo.go +++ b/goversioninfo.go @@ -34,6 +34,7 @@ type VersionInfo struct { Buffer bytes.Buffer Structure VSVersionInfo IconPath string + ManifestPath string } // Translation with langid and charsetid. @@ -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 { diff --git a/icon.go b/icon.go index 151aad0..f75e72c 100644 --- a/icon.go +++ b/icon.go @@ -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 diff --git a/rc/cmd.rc b/rc/cmd.rc new file mode 100644 index 0000000..4ad5d34 --- /dev/null +++ b/rc/cmd.rc @@ -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 \ No newline at end of file diff --git a/rc/control.rc b/rc/control.rc new file mode 100644 index 0000000..66579b7 --- /dev/null +++ b/rc/control.rc @@ -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 \ No newline at end of file diff --git a/rc/explorer.rc b/rc/explorer.rc new file mode 100644 index 0000000..3553abc --- /dev/null +++ b/rc/explorer.rc @@ -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 \ No newline at end of file diff --git a/rc/versioninfo.rc b/rc/versioninfo.rc new file mode 100644 index 0000000..4d0538a --- /dev/null +++ b/rc/versioninfo.rc @@ -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" \ No newline at end of file