Skip to content

Commit

Permalink
Merge pull request #97 from eco/specify-installed-dir
Browse files Browse the repository at this point in the history
Revamp Windows installer
  • Loading branch information
Jordi Sayol authored and AndrewEdwards committed Jul 21, 2014
1 parent 66f12f7 commit a97316e
Show file tree
Hide file tree
Showing 11 changed files with 1,070 additions and 659 deletions.
3 changes: 2 additions & 1 deletion create_dmd_release/build_all.d
Expand Up @@ -297,9 +297,10 @@ void runBuild(Box box, string gitTag, bool combine)

case OS.windows:
{
immutable build_dir = buildPath("dmd."~ver~".windows-32", "dmd2");
sh = box.shell();
sh.stdin.writeln(`cd clones\installer\windows`);
sh.stdin.writeln(`&'C:\Program Files (x86)\NSIS\makensis' /DVersion2=`~ver~` dinstaller.nsi`);
sh.stdin.writeln(`&'C:\Program Files (x86)\NSIS\makensis' /DEmbedD2Dir=`~build_dir~` /DVersion2=`~ver~` d2-installer.nsi`);
sh.stdin.writeln(`copy dmd-`~ver~`.exe C:\Users\vagrant\dmd-`~ver~`.exe`);
sh.close();
box.scp("default:dmd-"~ver~".exe", ".");
Expand Down
20 changes: 20 additions & 0 deletions windows/d1-installer-descriptions.nsh
@@ -0,0 +1,20 @@
;--------------------------------------------------------
; English
;--------------------------------------------------------

; Sections
LangString DESC_Dmd1Files ${LANG_ENGLISH} "Digital Mars D version 1 compiler"
LangString DESC_AddD1ToPath ${LANG_ENGLISH} "Modify the PATH environment variable so DMD can be used from any command prompt"


; Shortcuts
LangString SHORTCUT_Uninstall ${LANG_ENGLISH} "Uninstall"

;--------------------------------------------------------
; Assign texts to sections
;--------------------------------------------------------

!insertmacro MUI_FUNCTION_DESCRIPTION_BEGIN
!insertmacro MUI_DESCRIPTION_TEXT ${Dmd1Files} $(DESC_Dmd1Files)
!insertmacro MUI_DESCRIPTION_TEXT ${AddD1ToPath} $(DESC_AddD1ToPath)
!insertmacro MUI_FUNCTION_DESCRIPTION_END
Binary file added windows/d1-installer-image.bmp
Binary file not shown.
289 changes: 289 additions & 0 deletions windows/d1-installer.nsi
@@ -0,0 +1,289 @@
; Release Manager:
;
; Preliminary instructions
; ------------------------
;
; Please use the special build of NSIS that supports large strings.
; Updating the PATH will often not work or work incorrectly with the
; regular build of NSIS.
;
; http://nsis.sourceforge.net/Special_Builds
;
;
; Instructions
; ------------
;
; Two defines must be set to use the installer:
; - EmbedD1Dir: The path to the directory tree recursively embedded in the
; generated installer.
; - Version1: The DMD version number.
;
; The easiest way is to use the /D command line options for makensis
; makensis /DEmbedD1Dir=<some path> /DVersion1=1.xxx

;--------------------------------------------------------
; Defines
;--------------------------------------------------------

; Required
; --------
; EmbedD1Dir. Can be specified here rather than on the makensis command line:
;!define EmbedD1Dir "<path to files to install>"

; Version1. Can be specified here rather than on the makensis command line:
;!define Version1 "1.076"


; Publishing Details
!define DPublisher "Digital Mars"
!define DName "DMD 1"
!define ARP "Software\Microsoft\Windows\CurrentVersion\Uninstall\${DName}"


;--------------------------------------------------------
; Includes
;--------------------------------------------------------

!include "MUI.nsh"
!include "EnvVarUpdate.nsh"
!include "FileFunc.nsh"


;------------------------------------------------------------
; Variables
;------------------------------------------------------------

Var I
Var J
Var K
Var InstanceCheck



;--------------------------------------------------------
; General definitions
;--------------------------------------------------------

; Name of the installer
Name "D1 Programming Language"

; Name of the output file of the installer
!define InstallerFilename "dmd-${Version1}.exe"
OutFile ${InstallerFilename}

; Where the program will be installed
InstallDir "C:\D1"

; Take the installation directory from the registry, if possible
InstallDirRegKey HKCU "Software\${DName}" "InstallationFolder"

; This is so no one can corrupt the installer
CRCCheck force

SetCompressor /SOLID lzma


;------------------------------------------------------------
; Macros definition
;------------------------------------------------------------

; Check if a dmd installer instance is already running
!macro OneInstanceOnly
System::Call 'kernel32::CreateMutexA(i 0, i 0, t "digital_mars_d_compiler_installer") ?e'
Pop $R0
StrCmp $R0 0 +3
MessageBox MB_OK|MB_ICONSTOP "An instance of DMD installer is already running"
Abort
!macroend


;--------------------------------------------------------
; Interface settings
;--------------------------------------------------------

; Confirmation when exiting the installer
!define MUI_ABORTWARNING

;!define MUI_ICON "d1-installer-icon.ico"
;!define MUI_UNICON "d1-uninstaller-icon.ico"


;--------------------------------------------------------
; Language selection dialog settings
;--------------------------------------------------------

; Remember the installation language
!define MUI_LANGDLL_REGISTRY_ROOT "HKCU"
!define MUI_LANGDLL_REGISTRY_KEY "Software\D1"
!define MUI_LANGDLL_REGISTRY_VALUENAME "Installer Language"


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

!define MUI_WELCOMEFINISHPAGE_BITMAP "d1-installer-image.bmp"
!insertmacro MUI_PAGE_WELCOME
!insertmacro MUI_PAGE_COMPONENTS
!insertmacro MUI_PAGE_DIRECTORY
!insertmacro MUI_PAGE_INSTFILES
!insertmacro MUI_PAGE_FINISH

!insertmacro MUI_UNPAGE_WELCOME
!insertmacro MUI_UNPAGE_CONFIRM
!insertmacro MUI_UNPAGE_INSTFILES
!insertmacro MUI_UNPAGE_FINISH


;--------------------------------------------------------
; The languages
;--------------------------------------------------------

!insertmacro MUI_LANGUAGE "English"


; Reserve files needed by the installation
!insertmacro MUI_RESERVEFILE_LANGDLL


;--------------------------------------------------------
; Sections
;--------------------------------------------------------

SectionGroup /e "D1"
Section "-D1" Dmd1Files
; This section is mandatory
SectionIn RO

SetOutPath $INSTDIR
CreateDirectory "$INSTDIR"

; Embed the directory specified
File /r ${EmbedD1Dir}

; Create command line batch file
FileOpen $0 "$INSTDIR\dmd1vars.bat" w
FileWrite $0 "@echo.$\n"
FileWrite $0 "@echo Setting up environment for using DMD 1 from %~dp0dmd\windows\bin.$\n"
FileWrite $0 "@set PATH=%~dp0dmd\windows\bin;%PATH%$\n"
FileClose $0

; Write installation dir in the registry
WriteRegStr HKLM "SOFTWARE\${DName}" "InstallationFolder" "$INSTDIR"

; Registry keys for dmd uninstaller
WriteRegStr HKLM "${ARP}" "DisplayName" "${DName}"
WriteRegStr HKLM "${ARP}" "DisplayVersion" "${Version1}"
WriteRegStr HKLM "${ARP}" "UninstallString" "$INSTDIR\uninstall.exe"
WriteRegStr HKLM "${ARP}" "DisplayIcon" "$INSTDIR\uninstall.exe"
WriteRegStr HKLM "${ARP}" "Publisher" "${DPublisher}"
WriteRegStr HKLM "${ARP}" "HelpLink" "http://www.digitalmars.com/d/1.0/index.html"
WriteRegDWORD HKLM "${ARP}" "NoModify" 1
WriteRegDWORD HKLM "${ARP}" "NoRepair" 1
WriteUninstaller "uninstall.exe"
SectionEnd


Section /o "Add to PATH" AddD1ToPath
${EnvVarUpdate} $0 "PATH" "A" "HKLM" "$INSTDIR\dmd\windows\bin"
SectionEnd


Section "Start Menu" StartMenuShortcuts
CreateDirectory "$SMPROGRAMS\D"

CreateShortCut "$SMPROGRAMS\D\D1 HTML Documentation.lnk" "$INSTDIR\dmd\html\d\index.html"
CreateShortCut "$SMPROGRAMS\D\D1 Command Prompt.lnk" '%comspec%' '/k ""$INSTDIR\dmd1vars.bat""' "" "" SW_SHOWNORMAL "" "Open D1 Command Prompt"
SectionEnd
SectionGroupEnd


;--------------------------------------------------------
; Installer functions
;--------------------------------------------------------

Function .onInit
; Check if a dmd installer instance is already running
!insertmacro OneInstanceOnly


; Force install without uninstall (useful if uninstall is broken)
${GetParameters} $R0
StrCmp $R0 "/f" done


; Remove if dmd is already installed
ReadRegStr $R0 HKLM "${ARP}" "UninstallString"
StrCmp $R0 "" done

ReadRegStr $I HKLM "${ARP}" "DisplayName"
ReadRegStr $J HKLM "${ARP}" "DisplayVersion"
MessageBox MB_OKCANCEL|MB_ICONQUESTION \
"$I v$J is installed on your system$\n$\nPress 'OK' to replace by ${DName} ${Version1}" \
IDOK uninst
Abort

uninst:
ClearErrors
; Run uninstaller from installed directory
ExecWait '$R0 /IC False _?=$INSTDIR' $K
; Exit if uninstaller return an error
IfErrors 0 +3
MessageBox MB_OK|MB_ICONSTOP \
"An error occurred when removing $I v$J$\n$\nRun '${InstallerFilename} /f' to force install ${DName} ${Version1}"
Abort
; Exit if uninstaller is cancelled by user
StrCmp $K 0 +2
Abort
; Remove in background the remaining uninstaller program itself
Exec '$R0 /IC False /S'

done:
FunctionEnd


; Contains descriptions of components and other stuff
!include d1-installer-descriptions.nsh


;--------------------------------------------------------
; Uninstaller
;--------------------------------------------------------

Section "Uninstall"
; Remove directories from PATH (for all users)
${un.EnvVarUpdate} $0 "PATH" "R" "HKLM" "$INSTDIR\dmd\windows\bin"

; Remove stuff from registry
DeleteRegKey HKLM "${ARP}"
DeleteRegKey HKLM "SOFTWARE\${DName}"

; Remove the uninstaller
Delete $INSTDIR\uninstall.exe

; Remove the generated batch files
Delete $INSTDIR\dmd1vars.bat

; Remove shortcuts
Delete "$SMPROGRAMS\D\D1 HTML Documentation.lnk"
RMDir /r /REBOOTOK "$SMPROGRAMS\D"

; Remove used directories
RMDir /r /REBOOTOK "$INSTDIR\dmd"
RMDir /REBOOTOK "$INSTDIR"
SectionEnd


;--------------------------------------------------------
; Uninstaller functions
;--------------------------------------------------------

Function un.onInit
; Check if a dmd installer instance is already running
; Do not check if "/IC False" argument is passed to uninstaller
${GetOptions} $CMDLINE "/IC" $InstanceCheck
${IfNot} "$InstanceCheck" == "False"
!insertmacro OneInstanceOnly
${EndIf}
FunctionEnd

Expand Up @@ -4,14 +4,14 @@

; Sections
LangString DESC_Dmd2Files ${LANG_ENGLISH} "Digital Mars D version 2 compiler"
LangString DESC_cURLFiles ${LANG_ENGLISH} "Install DMD compatible libcurl"
LangString DESC_DetectMSVC ${LANG_ENGLISH} "Configure DMD to use the version of Visual C++ and Windows SDK that is installed"
LangString DESC_AddD2ToPath ${LANG_ENGLISH} "Modify the PATH environment variable so DMD can be used from any command prompt"
LangString DESC_Dmd1Files ${LANG_ENGLISH} "Digital Mars D version 1 compiler (discontinued)"
LangString DESC_DmcFiles ${LANG_ENGLISH} "Digital Mars C/C++ compiler"

LangString DESC_VisualDDownload ${LANG_ENGLISH} "Visual Studio package providing both project management and language services. It works with Visual Studio 2005-2013 (and the free VS Shells)"
LangString DESC_DmcDownload ${LANG_ENGLISH} "Digital Mars C/C++ compiler"
LangString DESC_Dmd1Download ${LANG_ENGLISH} "Digital Mars D version 1 compiler (discontinued)"


LangString DESC_VisualD ${LANG_ENGLISH} "Visual Studio package providing both project management and language services. It works with Visual Studio 2005-2013 (and the free VS Shells)"

; Shortcuts
LangString SHORTCUT_Uninstall ${LANG_ENGLISH} "Uninstall"
Expand All @@ -22,10 +22,9 @@ LangString SHORTCUT_Uninstall ${LANG_ENGLISH} "Uninstall"

!insertmacro MUI_FUNCTION_DESCRIPTION_BEGIN
!insertmacro MUI_DESCRIPTION_TEXT ${Dmd2Files} $(DESC_Dmd2Files)
!insertmacro MUI_DESCRIPTION_TEXT ${cURLFiles} $(DESC_cURLFiles)
!insertmacro MUI_DESCRIPTION_TEXT ${DetectMSVC} $(DESC_DetectMSVC)
!insertmacro MUI_DESCRIPTION_TEXT ${AddD2ToPath} $(DESC_AddD2ToPath)
!insertmacro MUI_DESCRIPTION_TEXT ${Dmd1Files} $(DESC_Dmd1Files)
!insertmacro MUI_DESCRIPTION_TEXT ${DmcFiles} $(DESC_DmcFiles)
!insertmacro MUI_DESCRIPTION_TEXT ${VisualD} $(DESC_VisualD)
!insertmacro MUI_DESCRIPTION_TEXT ${VisualDDownload} $(DESC_VisualDDownload)
!insertmacro MUI_DESCRIPTION_TEXT ${DmcDownload} $(DESC_DmcDownload)
!insertmacro MUI_DESCRIPTION_TEXT ${Dmd1Download} $(DESC_Dmd1Download)
!insertmacro MUI_FUNCTION_DESCRIPTION_END
File renamed without changes.

0 comments on commit a97316e

Please sign in to comment.