Old 18th May 2007, 14:36   #1
DrDan
Member
 
Join Date: Apr 2007
Location: London, UK
Posts: 58
How many IfErrors do I really need?

I have a sequence of registry entry writes like this:

PHP Code:
WriteRegStr HKLM "Software\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\MyProduct" "MyProduct v 1.0" "MyCompany's Product"
WriteRegStr HKLM "Software\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\MyProduct" "UninstallString" "$INSTDIR\${UNINSTALLER_NAME}"
WriteRegStr HKLM "Software\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\MyProduct" "DisplayName" "MyProduct v1.0"
WriteRegDWORD HKLM "Software\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\MyProduct" "NoModify" 0x1
WriteRegDWORD HKLM 
"Software\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\MyProduct" "NoRepair" 0x1 
I need to be able to log everything that goes wrong. So, my question is: should I have a ClearErrors call before each one and an IfErrors call after each one? Is this the only way to handle errors? What is the best way to deal with so many goto labels?

Any advice is appreciated.

Thanks.
DrDan is offline   Reply With Quote
Old 18th May 2007, 15:12   #2
{_trueparuex^}
Senior Member
 
{_trueparuex^}'s Avatar
 
Join Date: Dec 2005
Location: Glow
Posts: 285
The error flag resets only if ClearErrors or IfErrors is called. You should add ClearErrors before the first WriteRegStr just to be sure. You can add IfErrors after each WriteReg if you really want to, but you can also add just one after all of the WriteRegs.

PHP Code:
ClearErrors
WriteRegStr HKLM 
"Software\Microsoft\Windows\CurrentVersion\Uninstall\MyProduct" "MyProduct v 1.0" "MyCompany's Product"
WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\MyProduct" "UninstallString" "$INSTDIR\${UNINSTALLER_NAME}"
WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\MyProduct" "DisplayName" "MyProduct v1.0"
WriteRegDWORD HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\MyProduct" "NoModify" 0x1
WriteRegDWORD HKLM 
"Software\Microsoft\Windows\CurrentVersion\Uninstall\MyProduct" "NoRepair" 0x1
IfErrors 0 
+2
  DetailPrint 
"Writing Uninstall registry keys failed!" 

The guy with the ridiculous username. Thou shall call him PaR instead.
Visit My Website
{_trueparuex^} is offline   Reply With Quote
Old 18th May 2007, 15:22   #3
Comperio
Major Dude
 
Comperio's Avatar
 
Join Date: Jan 2005
Location: Oregon Coast
Posts: 737
Anytime you call IfErrors, the system clears the error flag. It's probably good to clear errors at the beginning, but not necessary afterward if you are using IfErrors.

If you need to log specifics for each registry write, then you'll need to call IfErrors each time. But if you want to just log one error for the entire block, then call IfErrors once at the end.

And if you need to call after each time, the easiest way would be to wrap the call into its own macro. Something like this (using logiclib):
code:

!define WriteReg "${WriteReg}"

!macro WriteReg type hive key value
${Switch} ${type}
Case 'str'
WriteRegStr '${hive}' '${key}' '${value}'
${Break}
Case 'dword'
WriteRegDword '${hive}' '${key}' '${value}'
${Break}
${EndSwitch}
${If} ${Errors}
; put code here if errors...
${Else}
; put any non-error code here, if any
${EndIf}
!macroend



Then, your calls would look like this:
code:

${WriteReg} "str" HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\MyProduct" "MyProduct v 1.0" "MyCompany's Product"
${WriteReg} "str" HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\MyProduct" "UninstallString" "$INSTDIR\${UNINSTALLER_NAME}"
${WriteReg} "str" HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\MyProduct" "DisplayName" "MyProduct v1.0"
${WriteReg} "dword" HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\MyProduct" "NoModify" 0x1
${WriteReg} "dword" HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\MyProduct" "NoRepair" 0x1

Comperio 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