Skip to content

Commit

Permalink
Set version info for windows exe#
Browse files Browse the repository at this point in the history
Fixes #3046
  • Loading branch information
andydotxyz committed Jun 20, 2022
1 parent 4a11847 commit d38731c
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 0 deletions.
34 changes: 34 additions & 0 deletions cmd/fyne/internal/commands/package-windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,10 @@ import (
"os"
"path/filepath"
"runtime"
"strconv"
"strings"

"fyne.io/fyne/v2"
"fyne.io/fyne/v2/cmd/fyne/internal/templates"
"github.com/fyne-io/image/ico"
"github.com/josephspurrier/goversioninfo"
Expand Down Expand Up @@ -72,6 +75,8 @@ func (p *Packager) packageWindows() error {
vi.ProductName = p.Name
vi.IconPath = icoPath
vi.ManifestPath = manifest
vi.StringFileInfo.ProductVersion = p.combinedVersion()
vi.FixedFileInfo.FileVersion = fixedVersionInfo(p.combinedVersion())

vi.Build()
vi.Walk()
Expand Down Expand Up @@ -131,3 +136,32 @@ func runAsAdminWindows(args ...string) error {

return execabs.Command("powershell.exe", "Start-Process", "cmd.exe", "-Verb", "runAs", "-ArgumentList", cmd).Run()
}

func fixedVersionInfo(ver string) (ret goversioninfo.FileVersion) {
ret.Build = 1 // as 0,0,0,0 is not valid
if len(ver) == 0 {
return ret
}
split := strings.Split(ver, ".")
setVersionField(&ret.Major, split[0])
if len(split) > 1 {
setVersionField(&ret.Minor, split[1])
}
if len(split) > 2 {
setVersionField(&ret.Patch, split[2])
}
if len(split) > 3 {
setVersionField(&ret.Build, split[3])
}
return ret
}

func setVersionField(to *int, ver string) {
num, err := strconv.Atoi(ver)
if err != nil {
fyne.LogError("Failed to parse app version field", err)
return
}

*to = num
}
18 changes: 18 additions & 0 deletions cmd/fyne/internal/commands/package_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"runtime"
"testing"

"github.com/josephspurrier/goversioninfo"
"github.com/stretchr/testify/assert"

"fyne.io/fyne/v2/cmd/fyne/internal/metadata"
Expand All @@ -21,6 +22,23 @@ func Test_calculateExeName(t *testing.T) {
assert.Equal(t, "testdata", nonModulesApp)
}

func Test_fixedVersionInfo(t *testing.T) {
tests := []struct {
ver string
fixed goversioninfo.FileVersion
}{
{"", goversioninfo.FileVersion{0, 0, 0, 1}},
{"1.1.1.1", goversioninfo.FileVersion{1, 1, 1, 1}},
{"2.2.2", goversioninfo.FileVersion{2, 2, 2, 1}},
{"3.3.3.3.3", goversioninfo.FileVersion{3, 3, 3, 3}},
}

for _, tt := range tests {
parsed := fixedVersionInfo(tt.ver)
assert.Equal(t, tt.fixed, parsed)
}
}

func Test_isValidVersion(t *testing.T) {
assert.True(t, isValidVersion("1"))
assert.True(t, isValidVersion("1.2"))
Expand Down

0 comments on commit d38731c

Please sign in to comment.