I'm trying to create an NSIS installer for maxscripts in 3ds max. All works, when I create a simple script from a template, but when I tried to add a function that reads data from the registry to determine the installed versions of 3ds max and finding their location, then there was a problem. The script is compiled without any errors, but when I try to run it hangs and nothing happens.
Below is the code fragment of the NSIS script, in which the process of reading from the registry is performed, writing the found information about the installed versions of 3ds max to the ini file. As a result, during installation, the user should see the target folders with 3ds max installed:
;The path where 3ds Max is located:
Var MAX_DIR
;Page setup:
Page custom getMAX_DIR
Page instfiles
Function .onInit
!insertmacro MUI_LANGDLL_DISPLAY
InitPluginsDir
File /oname=$PLUGINSDIR\max_installdir.ini "max_installdir.ini"
; Scan for possible REG-entries:
MAX2013:
setRegView 64
ReadRegStr $MAX_DIR HKLM "SOFTWARE\Autodesk\3dsMax\15.0\MAX-1:409" "Installdir"
StrCmp $MAX_DIR "" MAX2013 FOUND_MOST_CURRENT
MAX2014:
setRegView 64
ReadRegStr $MAX_DIR HKLM "SOFTWARE\Autodesk\3dsMax\16.0\MAX-1:409" "Installdir"
StrCmp $MAX_DIR "" MAX2014 FOUND_MOST_CURRENT
MAX2015:
setRegView 64
ReadRegStr $MAX_DIR HKLM "SOFTWARE\Autodesk\3dsMax\17.0\MAX-1:409" "Installdir"
StrCmp $MAX_DIR "" MAX2015 FOUND_MOST_CURRENT
MAX2016:
setRegView 64
ReadRegStr $MAX_DIR HKLM "SOFTWARE\Autodesk\3dsMax\18.0\MAX-1:409" "Installdir"
StrCmp $MAX_DIR "" MAX2016 FOUND_MOST_CURRENT
MAX2017:
setRegView 64
ReadRegStr $MAX_DIR HKLM "SOFTWARE\Autodesk\3dsMax\19.0\MAX-1:409" "Installdir"
StrCmp $MAX_DIR "" MAX2017 FOUND_MOST_CURRENT
MAX2018:
setRegView 64
ReadRegStr $MAX_DIR HKLM "SOFTWARE\Autodesk\3dsMax\20.0\MAX-1:409" "Installdir"
StrCmp $MAX_DIR "" MAX2018 FOUND_MOST_CURRENT
FOUND_MOST_CURRENT:
; Write max dir into form:
WriteINIStr "$PLUGINSDIR\max_installdir.ini" "Field 3" "state" $MAX_DIR
FunctionEnd
Function getMAX_DIR
Push $R0
InstallOptions::dialog "$PLUGINSDIR\max_installdir.ini"
Pop $R0
ReadINIStr $MAX_DIR "$PLUGINSDIR\max_installdir.ini" "Field 3" "state"
; MessageBox MB_OK "$MAX_DIR"
Pop $R0
FunctionEnd
Here code max_installdir.ini:
[Settings]
NumFields=3
[Field 1]
Type=Groupbox
Text=Install uMax
Left=0
Right=264
Top=0
Bottom=130
[Field 2]
Type=Label
Text=Please locate your 3ds Max ROOT directory:
Left=20
Right=168
Top=26
Bottom=40
[Field 3]
Type=DirRequest
State=test
Left=22
Right=220
Top=68
Bottom=80
Show me, please, where there can be a error? Why can the installer freeze up on startup? When I remove this code snippet everything works fine, but it certainly does not detect the installed versions of 3ds max and does not find the location.
UP: NSIS 3.03, Windows 7x64
UP2: I tried to remove from the check version of 3ds max, which are not installed and it worked.. It turns out that the installer hangs if any of the specified versions are not installed. But how then can we make it simply skip the undetected versions and show the location paths of only those versions that are installed? I can not know in advance which versions are installed by users, and which are not installed.
UP3: And another question: how can I make the list of installed versions of 3ds max to be displayed so that the user could simply check the version on which he wants to install the script? Now only one field with the location of one of the versions of 3ds max (the first in the list) is displayed and in order to select a different version the user should click the browse button and manualy specify the location of another installed version of 3ds max.
UP4: I changed my code a little and now it works. I added a check for found installed versions:
Function .onInit
!insertmacro MUI_LANGDLL_DISPLAY
; Scan reg for possible 3ds Max version is installed:
; MAX2013:
setRegView 64
ReadRegStr $1 HKLM "SOFTWARE\Autodesk\3dsMax\15.0" "Installdir"
${If} $1 != ""
StrCpy $INSTDIR $1
${EndIf}
; MAX2014:
setRegView 64
ReadRegStr $1 HKLM "SOFTWARE\Autodesk\3dsMax\16.0" "Installdir"
${If} $1 != ""
StrCpy $INSTDIR $1
${EndIf}
; MAX2015:
setRegView 64
ReadRegStr $1 HKLM "SOFTWARE\Autodesk\3dsMax\17.0" "Installdir"
${If} $1 != ""
StrCpy $INSTDIR $1
${EndIf}
; MAX2016:
setRegView 64
ReadRegStr $1 HKLM "SOFTWARE\Autodesk\3dsMax\18.0" "Installdir"
${If} $1 != ""
StrCpy $INSTDIR $1
${EndIf}
; MAX2017:
setRegView 64
ReadRegStr $1 HKLM "SOFTWARE\Autodesk\3dsMax\19.0" "Installdir"
${If} $1 != ""
StrCpy $INSTDIR $1
${EndIf}
; MAX2018:
setRegView 64
ReadRegStr $1 HKLM "SOFTWARE\Autodesk\3dsMax\20.0" "Installdir"
${If} $1 != ""
StrCpy $INSTDIR $1
${EndIf}
FunctionEnd
InstallDir "$INSTDIR"
Now on the selection page of the installation directory, the most recent version of 3ds max is installed from the computer.
It is possible to write somehow more shortly? After all, only the version number changes here.
You code does not make any sense, if it does not find a value it just tries to read it again. You don't need all those labels, just continue to the next version if it is not found:
setRegView 64
ReadRegStr $MAX_DIR HKLM "SOFTWARE\Autodesk\3dsMax\15.0\MAX-1:409" "Installdir"
StrCmp $MAX_DIR "" 0 FOUND_MOST_CURRENT
setRegView 64
ReadRegStr $MAX_DIR HKLM "SOFTWARE\Autodesk\3dsMax\16.0\MAX-1:409" "Installdir"
StrCmp $MAX_DIR "" 0 FOUND_MOST_CURRENT
...
If you really want to jump then you need to jump to the next item, not the same item all over again:
#MAX2013: ; This label is not used
setRegView 64
ReadRegStr $MAX_DIR HKLM "SOFTWARE\Autodesk\3dsMax\15.0\MAX-1:409" "Installdir"
StrCmp $MAX_DIR "" MAX2014 FOUND_MOST_CURRENT
MAX2014:
setRegView 64
ReadRegStr $MAX_DIR HKLM "SOFTWARE\Autodesk\3dsMax\16.0\MAX-1:409" "Installdir"
StrCmp $MAX_DIR "" MAX2015 FOUND_MOST_CURRENT
MAX2015:
...
If you actually want prioritize the most recent version then you should reverse the order, check for the newest first and jump to FOUND_MOST_CURRENT if found.