Skip to content

Commit

Permalink
Support prerelease version numbers in nsis installer
Browse files Browse the repository at this point in the history
  • Loading branch information
mircearoata committed Dec 16, 2023
1 parent 8300b8a commit 6368ff7
Show file tree
Hide file tree
Showing 5 changed files with 65 additions and 3 deletions.
3 changes: 3 additions & 0 deletions .github/workflows/push.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}
Expand Down
3 changes: 2 additions & 1 deletion build/windows/installer/.gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
# Generated on each build
wails_tools.nsh
wails_tools.nsh
vi_version.nsh
7 changes: 5 additions & 2 deletions build/windows/installer/project.nsi
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
50 changes: 50 additions & 0 deletions build/windows/installer_version.go
Original file line number Diff line number Diff line change
@@ -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))
}
5 changes: 5 additions & 0 deletions tools.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
//go:build tools

package main

//go:generate go run ./build/windows/installer_version.go

0 comments on commit 6368ff7

Please sign in to comment.