Go Back   Winamp Forums > Developer Center > NSIS Discussion

Reply
Thread Tools Search this Thread Display Modes
Old 5th November 2010, 15:35   #1
bostko
Junior Member
 
Join Date: Oct 2010
Posts: 17
How to read random variable name?

I want to save target installation directory in ini file.
So the installation directory could be $LOCALAPPDATA or $APPDATA etc.
But how could I store variable name I want to use and then use it.
It needs to be some way like that
http://bg2.php.net/manual/en/languag...s.variable.php

I hope you will understand my question
bostko is offline   Reply With Quote
Old 5th November 2010, 15:53   #2
Afrow UK
Moderator
 
Afrow UK's Avatar
 
Join Date: Nov 2002
Location: Birmingham, England
Posts: 8,216
I would store a string/int and then on read do:
code:
ReadINIStr $R0 ...
${If} $R0 == $$LOCALAPPDATA
StrCpy $INSTDIR $LOCALAPPDATA
${ElseIf} $R0 == $$APPDATA
StrCpy $INSTDIR $APPDATA
...

If you need to store a sub folder path/name then I'd use another INI key/value pair for it. The other option is to evaluate $$APPDATA (etc) from a read value using StrReplace (or WordFunc equiv) but IMO that is a bit messy/ugly.

Edit: But why would you want to store the variable names? Why not just store the value of $INSTDIR. Otherwise, if on uninstall, say $APPDATA has changed then your evaluated $INSTDIR will not be valid.

Stu

Need an installer? http://www.afrowsoft.co.uk
Afrow UK is offline   Reply With Quote
Old 5th November 2010, 15:55   #3
Animaether
Major Dude
 
Join Date: Jun 2001
Posts: 1,173
Usually you would store the full path in the ini file or the environment variable ( http://www.wilsonmar.com/1envvars.htm - see also: REG_EXPAND_SZ ) for the applicable part of the path. Storing NSIS variable names work as well, I suppose, but you can't read them out directly.

You'd have to use something like...
PHP Code:
/* write the -name- $LOCALAPPDATA to ini */
WriteIniStr "filename.ini" "Section" "Location" "$$LOCALAPPDATA"

/* read the -name- of variable to ini */
ReadIniStr $"filename.ini" "Section" "Location"
/* Select the actual value of the variable depending on the name */
${Select"$0"
${Case} "$$LOCALAPPDATA"
    
StrCpy $"$LOCALAPPDATA"
${EndSelect
Animaether is offline   Reply With Quote
Old 5th November 2010, 16:16   #4
bostko
Junior Member
 
Join Date: Oct 2010
Posts: 17
Thank you!
I just thinking to do it that way
bostko is offline   Reply With Quote
Reply
Go Back   Winamp 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