Old 2nd September 2008, 14:52   #1
chuckwood
Junior Member
 
Join Date: Sep 2008
Posts: 2
How to assign properly to $R0 ?

Sorry if my question sounds stupid but I am relatively a newbie and I can't explain something strange going on in my code.

Remember the original PageReinstall in the makensis.nsi example?

PHP Code:
Function PageReinstall

  ReadRegStr $R0 HKLM 
"${D_INSTALLKEY}" ""

  
${If} $R0 == ""
    
Abort
  
${EndIf}

  
ReadRegDWORD $R0 HKLM "${D_INSTALLKEY}" "VersionMajor"
  
ReadRegDWORD $R1 HKLM "${D_INSTALLKEY}" "VersionMinor"
  
ReadRegDWORD $R2 HKLM "${D_INSTALLKEY}" "VersionRevision"
  
ReadRegDWORD $R3 HKLM "${D_INSTALLKEY}" "VersionBuild"
  
StrCpy $R0 $R0.$R1.$R2.$R3

  
${VersionCompare} ${VER_MAJOR}.${VER_MINOR}.${VER_REVISION}.${VER_BUILD$R0 $R0
    
${If} $R0 == 0
    StrCpy $R1 
"${D_PRODUCT} ${VERSION} is already installed. Select the operation you want to perform and click Next to continue."
    
StrCpy $R2 "Add/Reinstall components"
    
StrCpy $R3 "Uninstall ${D_PRODUCT}"
    
!insertmacro MUI_HEADER_TEXT "Already Installed" "Choose the maintenance option to perform."
    
StrCpy $R0 "2"
  
${ElseIf} $R0 == 1
    StrCpy $R1 
"An older version of ${D_PRODUCT} is installed on your system. It's recommended that you uninstall the current version before installing. Select the operation you want to perform and click Next to continue."
    
StrCpy $R2 "Uninstall before installing"
    
StrCpy $R3 "Do not uninstall"
    
!insertmacro MUI_HEADER_TEXT "Already Installed" "Choose how you want to install ${D_PRODUCT}."
    
StrCpy $R0 "1"
  
${ElseIf} $R0 == 2
  
... 
Well, when I implemented my first release, I neglected to to implement the version numbers in the registry. So now when I release a new installer with better code, I want it to be able to detect its presence and call it. Fortunately, both the older version and the new one have the uninstaller information in the same place in the registry ($D_UNINSTALLKEY).

So I modified the above to:

PHP Code:
Function PageReinstall

  ReadRegStr $R0 HKLM 
"${D_INSTALLKEY}" ""

  
${If} $R0 == ""
    
Abort
  
${EndIf}

  
ReadRegDWORD $R0 HKLM "${D_INSTALLKEY}" "VersionMajor"
  
ReadRegDWORD $R1 HKLM "${D_INSTALLKEY}" "VersionMinor"
  
ReadRegDWORD $R2 HKLM "${D_INSTALLKEY}" "VersionRevision"
  
ReadRegDWORD $R3 HKLM "${D_INSTALLKEY}" "VersionBuild"
  
StrCpy $R0 $R0.$R1.$R2.$R3

    
;; identify older versions that did not register their version number in registry
  ClearErrors
  ReadRegStr $IsOldVerInstalled HKLM 
"${D_UNINSTALLKEY}" "UninstallString"
  
IfErrors +2 0
    StrCpy $R0 1.0.0.0

  
${VersionCompare} ${VER_MAJOR}.${VER_MINOR}.${VER_REVISION}.${VER_BUILD$R0 $R0
    
${If} $R0 == 0
    StrCpy $R1 
"${D_PRODUCT} ${VERSION} is already installed. Select the operation you want to perform and click Next to continue."
    
StrCpy $R2 "Add/Reinstall components"
    
StrCpy $R3 "Uninstall ${D_PRODUCT}"
    
!insertmacro MUI_HEADER_TEXT "Already Installed" "Choose the maintenance option to perform."
    
StrCpy $R0 "2"
  
${ElseIf} $R0 == 1
    StrCpy $R1 
"An older version of ${D_PRODUCT} is installed on your system. It's recommended that you uninstall the current version before installing. Select the operation you want to perform and click Next to continue."
    
StrCpy $R2 "Uninstall before installing"
    
StrCpy $R3 "Do not uninstall"
    
!insertmacro MUI_HEADER_TEXT "Already Installed" "Choose how you want to install ${D_PRODUCT}."
    
StrCpy $R0 "1"
  
${ElseIf} $R0 == 2
  
... 
But for some reason it never executes the $R0 == 1 part ("An older version, etc.").

What's wrong in my code?

I also tried
PHP Code:
StrCpy $R0 "1.0.0.0" 
instead of
PHP Code:
StrCpy $R0 1.0.0.0 
but that didn't help.

What's wrong in my code?
chuckwood is offline   Reply With Quote
Old 3rd September 2008, 16:59   #2
Afrow UK
Moderator
 
Afrow UK's Avatar
 
Join Date: Nov 2002
Location: Surrey, England
Posts: 8,434
You are setting $R0 to 1.0.0.0 if the uninstall registry is present. Is that what you want to do?

Stu
Afrow UK is offline   Reply With Quote
Old 3rd September 2008, 22:18   #3
chuckwood
Junior Member
 
Join Date: Sep 2008
Posts: 2
Quote:
Originally posted by Afrow UK
You are setting $R0 to 1.0.0.0 if the uninstall registry is present. Is that what you want to do?
Yes, but I finally found the bug. The bug was in the beginning of the function:
PHP Code:
Function PageReinstall

  ReadRegStr $R0 HKLM 
"${D_INSTALLKEY}" ""

  
${If} $R0 == ""
    
Abort
  
${EndIf} 
NSIS never had a chance to reach the point of setting $R0 to 1.0.0.0 because reading ${D_INSTALLKEY} from the old version always yielded $R0 == "".

Now all is well.

Thanks!
chuckwood is offline   Reply With Quote
Reply
Go Back   Winamp & Shoutcast Forums > Developer Center > NSIS Discussion

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump