瀏覽代碼

Parse /INSTDIR flag for installer, replacing broken /D

Thomas Kluyver 5 年之前
父節點
當前提交
c49e6e7be0
共有 2 個文件被更改,包括 17 次插入1 次删除
  1. 16 0
      nsist/pyapp.nsi
  2. 1 1
      nsist/tests/test_main.py

+ 16 - 0
nsist/pyapp.nsi

@@ -26,6 +26,7 @@ SetCompressor lzma
 !define MULTIUSER_INSTALLMODE_FUNCTION correct_prog_files
 [% endif %]
 !include MultiUser.nsh
+!include FileFunc.nsh
 
 [% block modernui %]
 ; Modern UI installer stuff
@@ -52,6 +53,8 @@ Name "${PRODUCT_NAME} ${PRODUCT_VERSION}"
 OutFile "${INSTALLER_NAME}"
 ShowInstDetails show
 
+Var cmdLineInstallDir
+
 Section -SETTINGS
   SetOutPath "$INSTDIR"
   SetOverwrite ifnewer
@@ -217,7 +220,20 @@ Function .onMouseOverSection
 FunctionEnd
 
 Function .onInit
+  ; Multiuser.nsh breaks /D command line parameter. Parse /INSTDIR instead.
+  ; Cribbing from https://nsis-dev.github.io/NSIS-Forums/html/t-299280.html
+  ${GetParameters} $0
+  ClearErrors
+  ${GetOptions} '$0' "/INSTDIR=" $1
+  IfErrors +2  ; Error means flag not found
+    StrCpy $cmdLineInstallDir $1
+  ClearErrors
+
   !insertmacro MULTIUSER_INIT
+
+  ; If cmd line included /INSTDIR, override the install dir set by MultiUser
+  StrCmp $cmdLineInstallDir "" +2
+    StrCpy $INSTDIR $cmdLineInstallDir
 FunctionEnd
 
 Function un.onInit

+ 1 - 1
nsist/tests/test_main.py

@@ -65,7 +65,7 @@ def test_installer(console_eg_copy, tmp_path):
     inst_dir = tmp_path / 'inst'
 
     # Run installer
-    run([str(installer), '/S', '/D={}'.format(inst_dir)], check=True)
+    run([str(installer), '/S', '/INSTDIR={}'.format(inst_dir)], check=True)
     import os
     print(os.listdir(str(inst_dir)))
     inst_python = inst_dir / 'Python' / 'python.exe'