diff --git a/.github/workflows/binaries.yml b/.github/workflows/binaries.yml index 25cea73668..20962c0c94 100644 --- a/.github/workflows/binaries.yml +++ b/.github/workflows/binaries.yml @@ -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 diff --git a/installer.nsi b/installer.nsi new file mode 100644 index 0000000000..42975d0a23 --- /dev/null +++ b/installer.nsi @@ -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