Archive: ${registry::KeyExists} not working


${registry::KeyExists} not working
Hi all...

I seem to get dumber every day...why wouldn't this work? The goal is to Quit if the file or one of the keys is found and to only install if not. The keys defined do both exist in the testing machine's registry.

!include "Registry.nsh"

;Check if our Cygwin directory is located on the local machine
IfFileExists "$INSTDIR\cygwin.bat" 0 DoInstall
MessageBox MB_ICONSTOP "The directory c:\cygwin does already exist. Please first remove any installation of cygwin and then restart this installer..."
Quit

;Check if the standard Cygwin Registry keys exist (x32)
${registry::KeyExists} "HKEY_LOCAL_MACHINE\SOFTWARE\Cygnus Solutions" $R0
StrCmp $R0 "0" DoInstall ByeReg
;Check if the standard Cygwin Registry keys exist (x64)
${registry::KeyExists} "HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Cygnus Solutions" $R0
StrCmp $R0 "0" DoInstall ByeReg

;This is the label to jump to if a registy key is found
ByeReg:
MessageBox MB_ICONSTOP "RegistryKeys for Cygwin exist on this machine. Please first remove any installation of cygwin and then restart this installer..."
Quit

;This is the label to jump to if Cygwin is not installed yet.
DoInstall:
[...]

I can't see any error...but e.g. I have no clue which kind of value $R0 does contain - it doesn't seem to be documented anywhere. At least it would be interesting if it is a string or boolean or integer...to know if I should use StrCmp or IntCmp.

Can anybody help me?

Regards,

Chris


It returns a string -- in NSIS they are all strings. You can use StrCmp or IntCmp when the docs say the return codes are 0 and -1.


Okay - strings. Thank you so far. But can you see a problem regarding my code rendering it useless?


Is $INSTDIR set when you want to look for the bat file? a messagebox would confirm that.

What fails? Does it detect when there is no cygwin installation, or does it not detect when there is an installation?

Try using the short aliases for the registry hives HKLM instead of HKEY_LOCAL_MACHINE. The docs aren't clear whether you can use either or both forms.

If those suggestions don't help, see if there is a key value to be read. On my computer there are values in "HKCU\Software\Cygnus Solutions\Cygwin\mounts v2" "cygdrive flags".


The "IfFileExists" part works perfectly - no error there. The only problem occurs when trying to check the registry keys...

H E C K ! ! !

...this shitty GOTO-Crap!!! Once again it shit on my head. Nobody with a brain should ever have implemented such a shit into anything!!! Himmelherrgottzack!!!

Sorry, all. That had to get out. My whole weekend was invested in the debugging of this crap. Right now I found it:

All the time I looked onto my code as if it was ca "CASE" statement. But of course it has to be shitty GOTOs.

So nothing of my "${registry::KeyExists}"-code is wrong, it works a suppose. But if the file does not exist, it jumps directly to the DoInstall: and simply skips all of the "${registry::KeyExists}"-code. The right code of course must look like this:

IfFileExists "$INSTDIR\cygwin.bat" 0 CheckReg
MessageBox MB_ICONSTOP "The directory c:\cygwin does already exist."
Quit

CheckReg:
${registry::KeyExists} "HKEY_LOCAL_MACHINE\SOFTWARE\Cygnus Solutions" $R0
StrCmp $R0 "0" ByeReg DoInstall
${registry::KeyExists} "HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Cygnus Solutions" $R0
StrCmp $R0 "0" ByeReg DoInstall

ByeReg:
MessageBox MB_ICONSTOP "RegistryKeys for Cygwin exist on this machine."
Quit

;This is the label to jump to if Cygwin is not installed yet.
DoInstall:

I simply can't jump from the first check to the end but must do all checks sequentially.

My fault, if you see me somewhere, just kick me (I'll wear a t-shirt expressing this).

Regards,

Chris


The logiclib header has SELECT, and SWITCH CASE statements and many other useful keywords. I don't write any scripts without it.


I'll definiteley have a look at it for the next version of any of my installers. Many thanks for the hint!