Archive: ReadRegStr - Section choice?


ReadRegStr - Section choice?
I need to make my installer do 1 of 2 things:

1.: Either do an automated check and set the InstallDir to that or
2.: Have the user choose 1 of 2 install options and it then need to check if the choice is valid.

My script is now at the 2.nd choice, but I'd much rather like it if it was the 1.st option my install used. My code is right now like this:


DirText \
"If HL / CS directory is not found, please choose the right directory :"

InstallDirRegKey HKLM Software\xes InstallDir

Function .onInit
ReadRegStr $0 HKCU "Software\Valve\Half-Life\" "InstallPath"
;ReadRegStr $0 HKCU "Software\Valve\Counter-Strike"
FunctionEnd

InstallDir \cstrike

SubSection /e "Choose MOD or Retail Counter-strike"

Section "Retail"
ReadRegStr $INSTDIR HKCU "Software\Valve\Counter-Strike" InstallPath
SectionEnd
Section "MOD"
ReadRegStr $INSTDIR HKCU "Software\Valve\Half-Life" InstallPath
SectionEnd

SubSectionEnd

..but this really doesn't work, as you might be able to see. Any help would be greatly appriciated. (Sorry for spelling errors)


You can check if the read values are correct or not by doing:

ReadRegStr $INSTDIR HKCU "Software\Valve\Counter-Strike" InstallPath
StrCmp $INSTDIR "" 0 +3
ReadRegStr $INSTDIR HKCU "Software\Valve\Half-Life" InstallPath
StrCmp $INSTDIR "" +2
IfFileExists "$INSTDIR\*.*" 0 +2
MessageBox MB_OK|MB_ICONEXCLAMATION "You do not have Half-Life installed!$\r$\nSetup will not continue!"
Abort


-Stu

To only allow one component being selected from a group of 2, have a look at Examples\one-section.nsi.

-Stu


So I don't need InstallDir at all, right? Is the code you made a "choose" or "automated" code? It needs to be in a section or function right?


So this code would requier the user to choose a directory and it would check the path.. can't it just read the regstr at load or start of installer so the user don't have to do anything other then choose to install it?


InstallDir will set the directory on the Directory page, unless it is changed in a function before the user reaches the Directory page.

My code can indeed be used in the .onInit function, then it will set the InstallDir depending on what the registry keys retreaved were.

I have made changes so that if both registry values are blank, then it will use the defined InstallDir from compile-time.


Function .onInit
Push $INSTDIR ;save compile-time value
ReadRegStr $INSTDIR HKCU "Software\Valve\Counter-Strike" InstallPath
StrCmp $INSTDIR "" 0 +3
ReadRegStr $INSTDIR HKCU "Software\Valve\Half-Life" InstallPath
StrCmp $INSTDIR "" +2
IfFileExists "$INSTDIR\*.*" noreturn
Pop $INSTDIR ;return compile-time value
noreturn:
FunctionEnd


-Stu

Yes now it works! Thank you so very much =D You'v made my day for sure! Thanks again.

Just for the fun of it, what is the difrence of:
StrCmp $INSTDIR "" 0 +3
and
StrCmp $INSTDIR "" +2
?
What I don't uderstand is the 0. What does it do and why is there no 0 in the 2.nd line?

If the InstallDir is Counter-Strike it will not find the path. Only the Half-Life str works :|


You need to look at the NSIS Documentation on relative and label jumps.
Also look up StrCmp.

+3 means jump 3 commands from the current command.
0 means continue from current command to next command.
0 would be the same as using +1.
-2 would jump backwards 2 commands.

A label is used for the last bit to jump over the Pop $INSTDIR, because relative jumps do not work on Pop, or a number of other commands.

Well, looking at the ReadRegStr's you are using HKCU (Current User) and I think you should use HKLM (Local Machine)

Also, if you have the Software\Valve\Counter-Strike registry root there, but the value is incorrect (the dir specified does not exist), then it will use the Half-Life value instead (and if that does not exist, then the compile-time InstallDir value will be used instead).

-Stu


It's a better idea to use this function just to push the user towards using the right install directory.
So, displaying the directory page no matter what is a good idea...

-Stu


Well in my RegDB I have:
HKEY_CURRENT_USER\Software\Valve\_Half-Life "InstallPath" D:\Half-Life
and
HKEY_CURRENT_USER\Software\Valve\Counter-Strike "InstallPath" D:\Counter-Strike
If I rename the HL key to _Half-Life, so only the CS key is valid, the installer does not find it.



Function .onInit
Push $INSTDIR ;save compile-time value
ReadRegStr $INSTDIR HKCU "Software\Valve\Counter-Strike" InstallPath
MessageBox MB_OK >$INSTDIR<
StrCmp $INSTDIR "" 0 +3
ReadRegStr $INSTDIR HKCU "Software\Valve\Half-Life" InstallPath
MessageBox MB_OK >$INSTDIR<
StrCmp $INSTDIR "" +2
IfFileExists "$INSTDIR\*.*" noreturn
Pop $INSTDIR ;return compile-time value
noreturn:
FunctionEnd


Try this, notice I've added messagebox's in which will display the installpath values.

-Stu

Does the actual path D:\counter-strike exist on your hard drive?

-Stu


Originally posted by Afrow UK
Well, looking at the ReadRegStr's you are using HKCU (Current User) and I think you should use HKLM (Local Machine)

Also, if you have the Software\Valve\Counter-Strike registry root there, but the value is incorrect (the dir specified does not exist), then it will use the Half-Life value instead (and if that does not exist, then the compile-time InstallDir value will be used instead).

-Stu
As you can see I have the right key's and I don't think valve will listen to me, asking them to put there install info at HKLM insted of HKCU ;P

LoL I made it folder at the Key link and now it works fine.. just shows how much I know ;P


Btw, what is in the installer, mod or map? :)

I used to play Half-Life, CS, DoD before my PC got reformatted.
Now I play and make maps for D-Day: Normandy (Quake2)

-Stu


It's a cs script ala nextwish but a lot more complex, if I may say so my self :)
You can tjek out www.x-systems.dk tomorrow to dl it and see what's the fuss is about.