Skip to content

Commit

Permalink
Generate windows installer.
Browse files Browse the repository at this point in the history
  • Loading branch information
fnando committed Nov 12, 2024
1 parent 9e15e95 commit aa20b8b
Show file tree
Hide file tree
Showing 2 changed files with 70 additions and 0 deletions.
7 changes: 7 additions & 0 deletions .github/workflows/binaries.yml
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,13 @@ jobs:
with:
name: ${{ env.NAME }}
path: 'target/${{ matrix.sys.target }}/release/${{ env.NAME }}.tar.gz'
- name: Create Windows Installer
if: github.event_name == 'release' && matrix.sys.os == 'windows-latest'
shell: pwsh
run: |
winget install --id NSIS.NSIS
$Env::STELLAR_CLI_BINARY = "target/${{ matrix.sys.target }}/release/stellar.exe"
makensis installer.nsi
- name: Upload to Release (release only)
if: github.event_name == 'release'
uses: actions/github-script@v7
Expand Down
63 changes: 63 additions & 0 deletions installer.nsi
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
OutFile "stellar-cli-installer-$%VERSION%.exe"
InstallDir "$PROGRAMFILES\Stellar CLI"
RequestExecutionLevel admin

; Define WM_SETTINGCHANGE since NSIS doesn’t natively recognize it
!define WM_SETTINGCHANGE 0x1A

Section "Install"
SetOutPath "$INSTDIR"
File "$%STELLAR_CLI_BINARY%"
WriteUninstaller "$INSTDIR\Uninstall.exe"

; Create a shortcut in the Start Menu
CreateDirectory "$SMPROGRAMS\Stellar CLI"
CreateShortCut "$SMPROGRAMS\Stellar CLI\Uninstall.lnk" "$INSTDIR\Uninstall.exe" "" "$INSTDIR\Uninstall.exe" 0

; Add an entry to the Windows "Programs and Features" list
WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\Stellar CLI" "DisplayName" "Stellar CLI"
WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\Stellar CLI" "UninstallString" "$INSTDIR\Uninstall.exe"
WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\Stellar CLI" "DisplayIcon" "$INSTDIR\stellar.exe"
WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\Stellar CLI" "DisplayVersion" "$%VERSION%"
WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\Stellar CLI" "Publisher" "Stellar"
WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\Stellar CLI" "InstallLocation" "$INSTDIR"

; Add install directory to the PATH
ReadRegStr $0 HKLM "SYSTEM\CurrentControlSet\Control\Session Manager\Environment" "Path"
StrCpy $1 "$0;$INSTDIR"
WriteRegStr HKLM "SYSTEM\CurrentControlSet\Control\Session Manager\Environment" "Path" "$1"

; Notify Windows that the PATH has changed
System::Call 'user32::SendMessageA(i 0xFFFF, i ${WM_SETTINGCHANGE}, i 0, i 0)'
SectionEnd

Section "Uninstall"
Delete "$INSTDIR\stellar.exe"
Delete "$INSTDIR\Uninstall.exe"
RMDir "$INSTDIR"

; Remove the Start Menu shortcut
Delete "$SMPROGRAMS\Stellar CLI\Uninstall.lnk"
RMDir "$SMPROGRAMS\Stellar CLI"

; Remove the entry from "Programs and Features"
DeleteRegKey HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\Stellar CLI"

; Restore PATH without the installation directory
ReadRegStr $0 HKLM "SYSTEM\CurrentControlSet\Control\Session Manager\Environment" "Path"
StrCpy $1 "$0" ; Store the original PATH in $1

; Remove install directory from PATH (manual string removal)
StrLen $2 "$INSTDIR"
loop:
StrCpy $3 "$1" "$2"
StrCmp $3 "$INSTDIR" 0 +3
StrCpy $1 "$1" "" $2
goto loop

; Write the modified PATH back to registry
WriteRegStr HKLM "SYSTEM\CurrentControlSet\Control\Session Manager\Environment" "Path" "$1"

; Notify Windows that the PATH has changed
System::Call 'user32::SendMessageA(i 0xFFFF, i ${WM_SETTINGCHANGE}, i 0, i 0)'
SectionEnd

0 comments on commit aa20b8b

Please sign in to comment.