Archive: How to read random variable name?


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 :)


I would store a string/int and then on read do:

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

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...

/* write the -name- $LOCALAPPDATA to ini */
WriteIniStr "filename.ini" "Section" "Location" "$$LOCALAPPDATA"

/* read the -name- of variable to ini */
ReadIniStr $0 "filename.ini" "Section" "Location"
/* Select the actual value of the variable depending on the name */
${Select} "$0"
${Case} "$$LOCALAPPDATA"
StrCpy $0 "$LOCALAPPDATA"
${EndSelect}

:) Thank you!
I just thinking to do it that way :)