From 6368ff7626b1598f6cdd20103f10cc3f1c339bd4 Mon Sep 17 00:00:00 2001 From: mircearoata Date: Sat, 16 Dec 2023 22:34:06 +0100 Subject: [PATCH] Support prerelease version numbers in nsis installer --- .github/workflows/push.yml | 3 ++ build/windows/installer/.gitignore | 3 +- build/windows/installer/project.nsi | 7 ++-- build/windows/installer_version.go | 50 +++++++++++++++++++++++++++++ tools.go | 5 +++ 5 files changed, 65 insertions(+), 3 deletions(-) create mode 100644 build/windows/installer_version.go create mode 100644 tools.go diff --git a/.github/workflows/push.yml b/.github/workflows/push.yml index 843b0874..ef0350c4 100644 --- a/.github/workflows/push.yml +++ b/.github/workflows/push.yml @@ -47,6 +47,9 @@ jobs: - name: Install Wails run: go install github.com/wailsapp/wails/v2/cmd/wails@latest + + - name: Generate files + run: go generate -x -tags tools ./... - name: Build run: wails build ${{ matrix.buildArgs }} diff --git a/build/windows/installer/.gitignore b/build/windows/installer/.gitignore index 44115b54..0f937e92 100644 --- a/build/windows/installer/.gitignore +++ b/build/windows/installer/.gitignore @@ -1,2 +1,3 @@ # Generated on each build -wails_tools.nsh \ No newline at end of file +wails_tools.nsh +vi_version.nsh \ No newline at end of file diff --git a/build/windows/installer/project.nsi b/build/windows/installer/project.nsi index 3e95e6c6..1d68d2b3 100644 --- a/build/windows/installer/project.nsi +++ b/build/windows/installer/project.nsi @@ -13,9 +13,12 @@ Unicode true !define MULTIUSER_INSTALLMODE_INSTDIR_REGISTRY_VALUENAME "InstallPath" !include MultiUser.nsh +BrandingText "${INFO_PRODUCTNAME} ${INFO_PRODUCTVERSION}" + # The version information for this two must consist of 4 parts -VIProductVersion "${INFO_PRODUCTVERSION}.0" -VIFileVersion "${INFO_PRODUCTVERSION}.0" +!include "vi_version.nsh" +VIProductVersion "${VI_VERSION}" +VIFileVersion "${VI_VERSION}" VIAddVersionKey "CompanyName" "${INFO_COMPANYNAME}" VIAddVersionKey "FileDescription" "${INFO_PRODUCTNAME} Installer" diff --git a/build/windows/installer_version.go b/build/windows/installer_version.go new file mode 100644 index 00000000..ffface0c --- /dev/null +++ b/build/windows/installer_version.go @@ -0,0 +1,50 @@ +package main + +import ( + "encoding/json" + "fmt" + "io" + "os" + "strings" + + "github.com/satisfactorymodding/SatisfactoryModManager/backend/projectfile" +) + +var ( + wailsJSONFilePath = "wails.json" + viVersionFilePath = "build/windows/installer/vi_version.nsh" +) + +func main() { + wailsJSONFile, err := os.Open(wailsJSONFilePath) + if err != nil { + panic(err) + } + defer wailsJSONFile.Close() + + projectFile, err := io.ReadAll(wailsJSONFile) + if err != nil { + panic(err) + } + + err = json.Unmarshal(projectFile, &projectfile.ProjectFile) + if err != nil { + panic(err) + } + + f, err := os.OpenFile(viVersionFilePath, os.O_RDWR|os.O_CREATE|os.O_TRUNC, 0o777) + if err != nil { + panic(err) + } + defer f.Close() + + version, _, _ := strings.Cut(projectfile.ProjectFile.Info.ProductVersion, "-") + version, _, _ = strings.Cut(version, "+") + + for strings.Count(version, ".") < 3 { + version += ".0" + } + + _, _ = f.WriteString("# DO NOT EDIT - Generated automatically by build/windows/installer_version.go\n\n") + _, _ = f.WriteString(fmt.Sprintf("!define VI_VERSION \"%s\"\n", version)) +} diff --git a/tools.go b/tools.go new file mode 100644 index 00000000..f9a604e2 --- /dev/null +++ b/tools.go @@ -0,0 +1,5 @@ +//go:build tools + +package main + +//go:generate go run ./build/windows/installer_version.go