Skip to content

Commit

Permalink
NSIS Installer tweaks (#15)
Browse files Browse the repository at this point in the history
  • Loading branch information
benlye authored Jan 15, 2020
1 parent 9c3fb9d commit df01ae9
Show file tree
Hide file tree
Showing 5 changed files with 169 additions and 89 deletions.
233 changes: 152 additions & 81 deletions src/flash-multi.nsi
Original file line number Diff line number Diff line change
@@ -1,103 +1,87 @@

# Use the modern UI
; Plugins to Include
!include MUI2.nsh
!include "FileFunc.nsh"
!include "nsProcess.nsh"
!include "StrFunc.nsh"

; The name of the installer
Name "Flash Multi"

; The file to write
OutFile "flash-multi\bin\flash-multi-${VERSION}.exe"

; Use Unicode
Unicode True

; The default installation directory
InstallDir $PROGRAMFILES\FlashMulti

; Registry key to check for directory (so if you install again, it will
; overwrite the old one automatically)
InstallDirRegKey HKLM "Software\FlashMulti" "Install_Dir"
; Get the previous installation path from the registry
InstallDirRegKey HKLM "Software\FlashMulti" "InstallDir"

; Add/Remove programs registry key
!define AddRemoveProgsReg "Software\Microsoft\Windows\CurrentVersion\Uninstall\FlashMulti"

; Request application privileges
RequestExecutionLevel admin

; Installer initialization function - checks for previous installation
Function .onInit
IfFileExists "$INSTDIR\unins000.exe" PreviousVersionWarn
IfFileExists "$INSTDIR\uninstall.exe" PreviousVersionWarn
Goto End

PreviousVersionWarn:
MessageBox MB_YESNO|MB_ICONQUESTION "Remove the existing installation of Flash Multi?$\n$\nAnswering $\"No$\" will abort the installation." /SD IDYES IDYES Uninstall
Goto AbortInstall

Uninstall:
IfFileExists "$INSTDIR\unins000.exe" InnoUninstall
IfFileExists "$INSTDIR\uninstall.exe" NsisUninstall
Goto End

InnoUninstall:
ExecWait '"$INSTDIR\unins000.exe" /SILENT'
Goto End

NsisUninstall:
ExecWait '"$INSTDIR\uninstall.exe" /S _=$INSTDIR'
Goto End

AbortInstall:
abort

End:

FunctionEnd

; Uninstaller initialization function - checks for running program
Function un.onInit
${nsProcess::FindProcess} "flash-multi.exe" $R0
${If} $R0 == 0
MessageBox MB_OKCANCEL|MB_ICONEXCLAMATION "Flash Multi is running. Click OK to close it or Cancel to abort." /SD IDOK IDOK Close
Abort
${Else}
Goto End
${EndIf}

Close:
${nsProcess::CloseProcess} "flash-multi.exe" $R0
Goto End
;--------------------------------
; Variables
Var StartMenuFolder

End:
${nsProcess::Unload}
FunctionEnd
;--------------------------------
; 'Declare' functions used in StrFunc.nsh
${StrRep}

;--------------------------------
;Interface Settings

!define MUI_ABORTWARNING

;--------------------------------
;Pages
; Installer pages

!define MUI_COMPONENTSPAGE_NODESC
; License page
!define MUI_LICENSEPAGE_RADIOBUTTONS
!insertmacro MUI_PAGE_LICENSE ".\flash-multi\bin\Release\license.txt"

; Components page
!define MUI_COMPONENTSPAGE_NODESC
!insertmacro MUI_PAGE_COMPONENTS

; Directory page
!insertmacro MUI_PAGE_DIRECTORY

; Start menu page
!define MUI_STARTMENUPAGE_DEFAULTFOLDER "Flash Multi"
!define MUI_STARTMENUPAGE_REGISTRY_ROOT "HKLM"
!define MUI_STARTMENUPAGE_REGISTRY_KEY "Software\FlashMulti"
!define MUI_STARTMENUPAGE_REGISTRY_VALUENAME "StartMenuFolder"
!insertmacro MUI_PAGE_STARTMENU Application $StartMenuFolder

; Files page
!insertmacro MUI_PAGE_INSTFILES
!insertmacro MUI_UNPAGE_CONFIRM
!insertmacro MUI_UNPAGE_INSTFILES

; Finish page
!define MUI_FINISHPAGE_NOAUTOCLOSE
!define MUI_FINISHPAGE_SHOWREADME "$INSTDIR\README.txt"
!define MUI_FINISHPAGE_RUN "$INSTDIR\flash-multi.exe"
!define MUI_FINISHPAGE_LINK 'https://github.com/benlye/flash-multi/'
!define MUI_FINISHPAGE_LINK_LOCATION https://github.com/benlye/flash-multi/
!define /file MUI_FINISHPAGE_TEXT ".\installer_infoafter.txt"
!insertmacro MUI_PAGE_FINISH

;--------------------------------
;Languages

!insertmacro MUI_LANGUAGE "English"
; Uninstaller pages
!insertmacro MUI_UNPAGE_CONFIRM
!insertmacro MUI_UNPAGE_INSTFILES

;--------------------------------
;Languages
!insertmacro MUI_LANGUAGE "English"

;--------------------------------
; The stuff to install
Section "Flash Multi"
Section "Flash Multi" "flash_multi"

SectionIn RO

Expand All @@ -112,16 +96,18 @@ Section "Flash Multi"
File ".\flash-multi\bin\Release\flash-multi.exe.config"
File ".\flash-multi\bin\Release\GPL.txt"
File ".\flash-multi\bin\Release\license.txt"
File ".\flash-multi\bin\Release\README.txt"

; Write the uninstaller
WriteUninstaller "$INSTDIR\uninstall.exe"

; Write the installation path into the registry
WriteRegStr HKLM SOFTWARE\FlashMulti "Install_Dir" "$INSTDIR"
WriteRegStr HKLM SOFTWARE\FlashMulti "InstallDir" "$INSTDIR"

; Write a flag indicating the component selections
WriteRegDWORD HKLM SOFTWARE\FlashMulti "InstallDrivers" "0"

; Write the uninstall keys for Windows
!define AddRemoveProgsReg "Software\Microsoft\Windows\CurrentVersion\Uninstall\FlashMulti"

${GetSize} "$INSTDIR" "/S=0K" $0 $1 $2
IntFmt $0 "0x%08X" $0
WriteRegDWORD HKLM "${AddRemoveProgsReg}" "EstimatedSize" "$0"
Expand All @@ -135,10 +121,17 @@ Section "Flash Multi"
WriteRegDWORD HKLM "${AddRemoveProgsReg}""NoModify" 1
WriteRegDWORD HKLM "${AddRemoveProgsReg}""NoRepair" 1

; Create Start Menu shortcuts
!insertmacro MUI_STARTMENU_WRITE_BEGIN Application
CreateDirectory "$SMPROGRAMS\$StartMenuFolder"
CreateShortcut "$SMPROGRAMS\$StartMenuFolder\Flash Multi.lnk" "$INSTDIR\flash-multi.exe" "" "$INSTDIR\flash-multi.exe" 0
CreateShortcut "$SMPROGRAMS\$StartMenuFolder\Run Maple Driver Installer.lnk" "$INSTDIR\drivers\install_drivers.bat"
CreateShortcut "$SMPROGRAMS\$StartMenuFolder\Uninstall Flash Multi.lnk" "$INSTDIR\uninstall.exe" "" "$INSTDIR\uninstall.exe" 0
!insertmacro MUI_STARTMENU_WRITE_END
SectionEnd

; Optional section (can be disabled by the user)
Section "Run the Maple USB driver installer"
Section "Run the Maple USB driver installer" "install_drivers"
; Install the drivers - https://github.com/pbatard/libwdi/blob/master/examples/wdi-simple.iss

SetDetailsPrint textonly ; or both
Expand All @@ -151,24 +144,16 @@ Section "Run the Maple USB driver installer"
SetDetailsPrint none ; or listonly
nsExec::Exec '"$INSTDIR\drivers\wdi-simple.exe" --vid 0x1EAF --pid 0x0004 --type 3 --name "Maple Serial" --dest "$TEMP\maple-serial" --progressbar=$HWNDPARENT --timeout 120000"'

SectionEnd

; Optional section (can be disabled by the user)
Section "Start Menu Shortcuts"

CreateDirectory "$SMPROGRAMS\Flash Multi"
CreateShortcut "$SMPROGRAMS\Flash Multi\Flash Multi.lnk" "$INSTDIR\flash-multi.exe" "" "$INSTDIR\flash-multi.exe" 0
CreateShortcut "$SMPROGRAMS\Flash Multi\Run Maple Driver Installer.lnk" "$INSTDIR\drivers\install_drivers.bat"
CreateShortcut "$SMPROGRAMS\Flash Multi\Uninstall Flash Multi.lnk" "$INSTDIR\uninstall.exe" "" "$INSTDIR\uninstall.exe" 0

; Remember that drivers were selected
WriteRegDWORD HKLM SOFTWARE\FlashMulti "InstallDrivers" "1"
SectionEnd

;--------------------------------

; Uninstaller

Section "Uninstall"

; Get the start menu folder
!insertmacro MUI_STARTMENU_GETFOLDER Application $StartMenuFolder

; Remove registry keys
DeleteRegKey HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\FlashMulti"
DeleteRegKey HKLM SOFTWARE\FlashMulti
Expand All @@ -177,10 +162,96 @@ Section "Uninstall"
Delete $INSTDIR\*.*

; Remove shortcuts, if any
Delete "$SMPROGRAMS\Flash Multi\*.*"
Delete "$SMPROGRAMS\$StartMenuFolder\*.*"

; Remove directories used
RMDir "$SMPROGRAMS\Flash Multi"
RMDir "$SMPROGRAMS\$StartMenuFolder"
RMDir /r "$INSTDIR"

SectionEnd

; Installer initialization function - checks for previous installation
Function .onInit
; Select/unselect the components based on previous selections
ReadRegDWORD $0 HKLM "Software\FlashMulti" "InstallDrivers"
${If} $0 == 0
SectionSetFlags ${install_drivers} 0
${Else}
SectionSetFlags ${install_drivers} 1
${EndIf}

; Check for an NSIS uninstaller in the registry
ReadRegStr $R0 HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\FlashMulti" "UninstallString"
${If} $R0 != ""
StrCpy $0 $R0
${EndIf}

; Check for an InnoSetup uninstaller in the registry
ReadRegStr $R1 HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\Flash Multi_is1" "UninstallString"
${If} $R1 != ""
StrCpy $0 $R1
${EndIf}

; If we have an uninstaller, parse the path to find the installation directory
${If} $0 != ""
; Strip any double quotes from the uninstaller path
${StrRep} '$1' '$0' '$\"' ''

; Get the parent folder of the uninstaller executable
${GetParent} $1 $2

; If the uninstaller folder is not the same as the default install dir, update the install dir
${If} $2 != $INSTDIR
StrCpy $INSTDIR $2
${EndIf}
${EndIf}

; Check if an uninstaller executable exists
IfFileExists "$INSTDIR\unins000.exe" PreviousVersionWarn
IfFileExists "$INSTDIR\uninstall.exe" PreviousVersionWarn
Goto End

PreviousVersionWarn:
; An uninstaller exists so ask the user if we should uninstall
MessageBox MB_YESNO|MB_ICONQUESTION "Remove the existing installation of Flash Multi?$\n$\nAnswering $\"No$\" will abort the installation." /SD IDYES IDYES Uninstall
Goto AbortInstall

Uninstall:
; Check for InnoSetup uninstaller
IfFileExists "$INSTDIR\unins000.exe" InnoUninstall
; Check for NSIS uninstaller
IfFileExists "$INSTDIR\uninstall.exe" NsisUninstall
Goto End

InnoUninstall:
; Run the InnoSetup uninstaller silently
ExecWait '"$INSTDIR\unins000.exe" /SILENT'
Goto End

NsisUninstall:
; Run the NSIS uninstaller silently
ExecWait '"$INSTDIR\uninstall.exe" /S _=$INSTDIR'
Goto End

AbortInstall:
abort

End:
FunctionEnd

; Uninstaller initialization function - checks for running program
Function un.onInit
${nsProcess::FindProcess} "flash-multi.exe" $R0
${If} $R0 == 0
MessageBox MB_OKCANCEL|MB_ICONEXCLAMATION "Flash Multi is running. Click OK to close it or Cancel to abort." /SD IDOK IDOK Close
Abort
${Else}
Goto End
${EndIf}

Close:
${nsProcess::CloseProcess} "flash-multi.exe" $R0
Goto End

End:
${nsProcess::Unload}
FunctionEnd
14 changes: 14 additions & 0 deletions src/flash-multi/README.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@

Flash Multi Readme
==============================

1. MULTI-Module Drivers

The Flash Multi installer only installs USB and DFU mode drivers for
the native 'Maple' serial port (if they are selected).

If your version of Windows requires additional serial port drivers
for your MULTI-Module, you will need to install those manually.

See the Flash Multi documentation for more information.
https://github.com/benlye/flash-multi/
3 changes: 3 additions & 0 deletions src/flash-multi/flash-multi.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,9 @@
<Content Include="license.txt">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
<Content Include="README.txt">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
</ItemGroup>
<ItemGroup>
<Analyzer Include="..\packages\StyleCop.Analyzers.1.1.118\analyzers\dotnet\cs\StyleCop.Analyzers.CodeFixes.dll" />
Expand Down
1 change: 0 additions & 1 deletion src/flash-multi/license.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

Copyright 2019 Ben Lye

Flash Multi is free software: you can redistribute it and/or modify
Expand Down
7 changes: 0 additions & 7 deletions src/installer_infoafter.txt

This file was deleted.

0 comments on commit df01ae9

Please sign in to comment.