Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fixup: Windows installer #1

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ jobs:
- name: Build
run: |
. .\venv\Scripts\activate.ps1
fbs freeze
fbs freeze
Compress-Archive -Path "target\Vial" -DestinationPath vial-win.zip

- uses: actions/upload-artifact@v1
Expand Down
9 changes: 9 additions & 0 deletions src/build/settings/windows.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"installer": "${app_name}Setup.exe",
"files_to_filter": [
"src/freeze/windows/version_info.py",
"src/installer/windows/Installer.nsi"
],
"show_console_window": false,
"url": ""
}
55 changes: 55 additions & 0 deletions src/freeze/windows/version_info.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
# For more details about fixed file info 'ffi' see:
# http://msdn.microsoft.com/en-us/library/ms646997.aspx

VSVersionInfo(
ffi=FixedFileInfo(
# filevers and prodvers should be always a tuple with four items: (1, 2, 3, 4)
# Set not needed items to zero 0. Must always contain 4 elements.
# MS conventions: major.minor.build.revision
filevers=(
int('${version}'.split('.')[0]),
int('${version}'.split('.')[1]),
int('${version}'.split('.')[2]),
0
),
prodvers=(
int('${version}'.split('.')[0]),
int('${version}'.split('.')[1]),
int('${version}'.split('.')[2]),
0
),
# Contains a bitmask that specifies the valid bits 'flags'r
mask=0x3f,
# Contains a bitmask that specifies the Boolean attributes of the file.
flags=0x0,
# The operating system for which this file was designed.
# 0x4 - NT and there is no need to change it.
OS=0x40004,
# The general type of file.
# 0x1 - the file is an application.
fileType=0x1,
# The function of the file.
# 0x0 - the function is not defined for this fileType
subtype=0x0,
# Most and least significant 32 bits of creation FILETIME.
# https://learn.microsoft.com/en-us/windows/win32/sysinfo/file-times
# Not worth calculating. Most Windows executables set zero.
date=(0, 0)
),
kids=[
StringFileInfo(
[
StringTable(
'040904B0',
[StringStruct('CompanyName', '${author}'),
StringStruct('FileDescription', '${app_name}'),
StringStruct('FileVersion', '${version}.0'),
StringStruct('InternalName', '${app_name}'),
StringStruct('LegalCopyright', '© ${author}. All rights reserved.'),
StringStruct('OriginalFilename', '${app_name}.exe'),
StringStruct('ProductName', '${app_name}'),
StringStruct('ProductVersion', '${version}.0')])
]),
VarFileInfo([VarStruct('Translation', [1033, 1200])])
]
)
40 changes: 31 additions & 9 deletions src/installer/windows/Installer.nsi
Original file line number Diff line number Diff line change
@@ -1,5 +1,18 @@
!include MUI2.nsh
!include FileFunc.nsh
!define MUI_ICON "..\${app_name}\Icon.ico" ;Install icon
!define MUI_UNICON "..\${app_name}\Icon.ico" ;Uninstall icon

;extract individual parts of version to prefixed variables
!getdllversion "..\${app_name}\${app_name}.exe" ver
!define WIN_VERSION "${ver1}.${ver2}.${ver3}.${ver4}"

VIProductVersion "${WIN_VERSION}"
VIAddVersionKey "ProductName" "${app_name}"
VIAddVersionKey "FileVersion" "${WIN_VERSION}"
VIAddVersionKey "ProductVersion" "${WIN_VERSION}"
VIAddVersionKey "LegalCopyright" "(C) ${author}"
VIAddVersionKey "FileDescription" "${app_name}"

;--------------------------------
;Perform Machine-level install, if possible
Expand Down Expand Up @@ -49,7 +62,7 @@ FunctionEnd
!define MUI_FINISHPAGE_RUN
!define MUI_FINISHPAGE_RUN_CHECKED
!define MUI_FINISHPAGE_RUN_TEXT "Run ${app_name}"
; !define MUI_FINISHPAGE_RUN_FUNCTION "LaunchLink"
!define MUI_FINISHPAGE_RUN_FUNCTION "LaunchAsNonAdmin"
!insertmacro MUI_PAGE_FINISH

!insertmacro MUI_UNPAGE_CONFIRM
Expand Down Expand Up @@ -77,16 +90,20 @@ Section
WriteRegStr SHCTX "${UNINST_KEY}" "QuietUninstallString" \
"$\"$InstDir\uninstall.exe$\" /$MultiUser.InstallMode /S"
WriteRegStr SHCTX "${UNINST_KEY}" "Publisher" "${author}"
WriteRegStr SHCTX "${UNINST_KEY}" "DisplayIcon" "$InstDir\uninstall.exe"
; NOTE: GetSize supposedly superseded by Locate plugin, watch for future removal
; https://nsis.sourceforge.io/Locate_plugin
${GetSize} "$InstDir" "/S=0K" $0 $1 $2
IntFmt $0 "0x%08X" $0
WriteRegDWORD SHCTX "${UNINST_KEY}" "EstimatedSize" "$0"
WriteRegStr SHCTX "${UNINST_KEY}" "DisplayVersion" "${WIN_VERSION}"
; TODO: Investigate VersionConvert etc. The following will blow up if major/minor version is non-numeric.
; fbs forces numeric versioning but PyInstaller might not.
WriteRegDWORD SHCTX "${UNINST_KEY}" "VersionMajor" "${ver1}"
WriteRegDWORD SHCTX "${UNINST_KEY}" "VersionMinor" "${ver2}"

SectionEnd

Function .onVerifyInstDir
StrCpy $InstDir "$InstDir\${app_name}"
FunctionEnd

;--------------------------------
;Uninstaller Section

Expand All @@ -99,7 +116,12 @@ Section "Uninstall"

SectionEnd

; Function LaunchLink
; !addplugindir "."
; ShellExecAsUser::ShellExecAsUser "open" "$SMPROGRAMS\${app_name}.lnk"
; FunctionEnd
;--------------------------------
;Additional Functions
Function .onVerifyInstDir
StrCpy $InstDir "$InstDir\${app_name}"
FunctionEnd

Function LaunchAsNonAdmin
Exec '"$WINDIR\explorer.exe" "$InstDir\${app_name}.exe"'
FunctionEnd