Browse Source

makepanda: installer uses registry to add Panda3D to Python path

rdb 7 years ago
parent
commit
62ae624a95
1 changed files with 23 additions and 9 deletions
  1. 23 9
      makepanda/installer.nsi

+ 23 - 9
makepanda/installer.nsi

@@ -385,26 +385,36 @@ SectionGroup "Python support"
         SetRegView ${REGVIEW}
         SetRegView ${REGVIEW}
         !endif
         !endif
 
 
-        ; Check for a system-wide Python installation.
-        ; We could check for a user installation of Python as well, but there
-        ; is no distinction between 64-bit and 32-bit regviews in HKCU, so we
-        ; can't guess whether it might be a compatible version.
+        ; Check for a non-Panda3D system-wide Python installation.
         ReadRegStr $0 HKLM "Software\Python\PythonCore\${PYVER}\InstallPath" ""
         ReadRegStr $0 HKLM "Software\Python\PythonCore\${PYVER}\InstallPath" ""
+        StrCmp $0 "$INSTDIR\python" UserExternalPthCheck 0
+        StrCmp $0 "" UserExternalPthCheck 0
+        IfFileExists "$0\ppython.exe" UserExternalPthCheck 0
+        IfFileExists "$0\python.exe" AskExternalPth UserExternalPthCheck
+
+        ; Check for a non-Panda3D user installation of Python.
+        UserExternalPthCheck:
+        ReadRegStr $0 HKCU "Software\Python\PythonCore\${PYVER}\InstallPath" ""
         StrCmp $0 "$INSTDIR\python" SkipExternalPth 0
         StrCmp $0 "$INSTDIR\python" SkipExternalPth 0
         StrCmp $0 "" SkipExternalPth 0
         StrCmp $0 "" SkipExternalPth 0
         IfFileExists "$0\ppython.exe" SkipExternalPth 0
         IfFileExists "$0\ppython.exe" SkipExternalPth 0
-        IfFileExists "$0\python.exe" 0 SkipExternalPth
+        IfFileExists "$0\python.exe" AskExternalPth SkipExternalPth
 
 
         ; We're pretty sure this Python build is of the right architecture.
         ; We're pretty sure this Python build is of the right architecture.
+        AskExternalPth:
         MessageBox MB_YESNO|MB_ICONQUESTION \
         MessageBox MB_YESNO|MB_ICONQUESTION \
             "Your system already has a copy of Python ${PYVER} installed in:$\r$\n$0$\r$\nWould you like to configure it to be able to use the Panda3D libraries?$\r$\nIf you choose no, you will only be able to use Panda3D's own copy of Python." \
             "Your system already has a copy of Python ${PYVER} installed in:$\r$\n$0$\r$\nWould you like to configure it to be able to use the Panda3D libraries?$\r$\nIf you choose no, you will only be able to use Panda3D's own copy of Python." \
             IDYES WriteExternalPth IDNO SkipExternalPth
             IDYES WriteExternalPth IDNO SkipExternalPth
 
 
         WriteExternalPth:
         WriteExternalPth:
-        FileOpen $1 "$0\Lib\site-packages\panda.pth" w
-        FileWrite $1 "$INSTDIR$\r$\n"
-        FileWrite $1 "$INSTDIR\bin$\r$\n"
-        FileClose $1
+        ;FileOpen $1 "$0\Lib\site-packages\panda.pth" w
+        ;FileWrite $1 "$INSTDIR$\r$\n"
+        ;FileWrite $1 "$INSTDIR\bin$\r$\n"
+        ;FileClose $1
+
+        ; Actually, it looks like we can just do this instead:
+        WriteRegStr HKCU "Software\Python\PythonCore\${PYVER}\PythonPath\Panda3D" "" "$INSTDIR"
+
         SkipExternalPth:
         SkipExternalPth:
     SectionEnd
     SectionEnd
 
 
@@ -736,6 +746,10 @@ Section Uninstall
     StrCmp $0 "$INSTDIR\python" 0 +2
     StrCmp $0 "$INSTDIR\python" 0 +2
     DeleteRegKey HKCU "Software\Python\PythonCore\${PYVER}"
     DeleteRegKey HKCU "Software\Python\PythonCore\${PYVER}"
 
 
+    ReadRegStr $0 HKCU "Software\Python\PythonCore\${PYVER}\PythonPath\Panda3D" ""
+    StrCmp $0 "$INSTDIR" 0 +2
+    DeleteRegKey HKCU "Software\Python\PythonCore\${PYVER}\PythonPath\Panda3D"
+
     SetDetailsPrint both
     SetDetailsPrint both
     DetailPrint "Deleting files..."
     DetailPrint "Deleting files..."
     SetDetailsPrint listonly
     SetDetailsPrint listonly