You are here

BUGFIX: ReadINIStrWithDefault.nsh 1.1 (2009-05-12)

4 posts / 0 new
Last post
John T. Haller
John T. Haller's picture
Offline
Last seen: 2 hours 28 min ago
AdminDeveloperModeratorTranslator
Joined: 2005-11-28 22:21
BUGFIX: ReadINIStrWithDefault.nsh 1.1 (2009-05-12)

I've discovered a bug in the ReadINIStrWithDefault.nsh macro file I wrote that we use with many of our releases. Specifically $0 and $2 are accidentally swapped by the macro. I'm guessing that we haven't noticed it because most of the variables we use are defined and we only use the macro at the very beginning of our launchers before we make use of any of the other variables, but it could be affecting some launchers out there.

Here is the updated macro that fixes the issue:

; ReadINIStrWithDefault 1.1 (2009-05-12)
;
; Substitutes a default value if the INI is undefined
; Copyright 2008-2009 John T. Haller of PortableApps.com
; Released under the BSD
;
; Usage: ${ReadINIStrWithDefault} OUTPUT_VALUE INI_FILENAME SECTION_NAME ENTRY_NAME DEFAULT_VALUE
;
; History:
; 1.1 (2009-05-12): Fixed error with $0 and $2 being swapped

Function ReadINIStrWithDefault
	;Start with a clean slate
	ClearErrors
	
	;Get our parameters
	Exch $0 ;DEFAULT_VALUE
	Exch
	Exch $1 ;ENTRY_NAME
	Exch 2
	Exch $2 ;SECTION_NAME
	Exch  3
	Exch $3 ;INI_FILENAME
	Push $4 ;OUTPUT_VALUE
	
	;Read from the INI
	ReadINIStr $4 $3 $2 $1
	IfErrors 0 +3
		StrCpy $4 $0
		ClearErrors

	;Keep the variable for last
	StrCpy $0 $4
	
	;Clear the stack
	Pop $4
	Pop $3
	Exch 2
	Pop $2
	Pop $1
	
	;Reset the last variable and leave our result on the stack
	Exch $0
FunctionEnd

!macro ReadINIStrWithDefault OUTPUT_VALUE INI_FILENAME SECTION_NAME ENTRY_NAME DEFAULT_VALUE
  Push `${INI_FILENAME}`
  Push `${SECTION_NAME}`
  Push `${ENTRY_NAME}`
  Push `${DEFAULT_VALUE}`
  Call ReadINIStrWithDefault
  Pop `${OUTPUT_VALUE}`
!macroend

!define ReadINIStrWithDefault '!insertmacro "ReadINIStrWithDefault"'

Developers, please double check your launchers and ensure that this doesn't affect your current releases in any way. If it does, we'll do a revision (as I'm doing revisions on all apps for Win7 anyway). If it does not, we'll need to be sure to get the macro into the next release.

Bart.S
Offline
Last seen: 1 week 5 hours ago
Developer
Joined: 2008-07-23 07:56
Use in PortableApps.comInstallerCustom?

Is it possible to use this in custom installer code?
I've tried to add !include "ReadINIStrWithDefault.nsh" but that doesn't work.

John T. Haller
John T. Haller's picture
Offline
Last seen: 2 hours 28 min ago
AdminDeveloperModeratorTranslator
Joined: 2005-11-28 22:21
Use Standard

Just use the standard code for now and an IF to replace with a default if it's blank. That's what we do in all the other installer custom codes. Manually including an extra file in the installer isn't supported at present.

Sometimes, the impossible can become possible, if you're awesome!

Bart.S
Offline
Last seen: 1 week 5 hours ago
Developer
Joined: 2008-07-23 07:56
Ok

Thanks

Log in or register to post comments