Confused, can't read INI value correctly

Please check the FAQ (https://www.xyplorer.com/faq.php) before posting a question...
Post Reply
bdeshi
Posts: 4256
Joined: 12 Mar 2014 17:27
Location: Asteroid B-612
Contact:

Confused, can't read INI value correctly

Post by bdeshi »

INI:

Code: Select all

[vars]
path=<xyscripts>\xyskins
script:

Code: Select all

...
 $path=getkey(path,vars, "path\to\file.ini");
 new("$path\res\some.file", file);
Doesn't work. (neither with any other SC in fact) Why?

If I use the actual value within the script as : $path="<xyscripts>\xyskins" then it works. But again doesn't work if the ini value is quoted (path='<xyscripts>\xyskins' path="<xyscripts>\xyskins")
Please help.
Last edited by bdeshi on 16 Jun 2014 09:14, edited 2 times in total.
Icon Names | Onyx | Undocumented Commands | xypcre
[ this user is asleep ]

binocular222
Posts: 1424
Joined: 04 Nov 2008 05:35
Location: Win11, Win10, 100% Scaling

Re: Confused, can't read INI value correctly

Post by binocular222 »

You forgot the quote

Code: Select all

$path=getkey("path","vars", "path\to\file.ini");
I'm a casual coder using AHK language. All of my xys scripts:
http://www.xyplorer.com/xyfc/viewtopic. ... 243#p82488

bdeshi
Posts: 4256
Joined: 12 Mar 2014 17:27
Location: Asteroid B-612
Contact:

Re: Confused, can't read INI value correctly

Post by bdeshi »

Nope, it's the same with quotes in getkey... :(
Icon Names | Onyx | Undocumented Commands | xypcre
[ this user is asleep ]

highend
Posts: 15012
Joined: 06 Feb 2011 00:33
Location: Win Server 2022 @100%

Re: Confused, can't read INI value correctly

Post by highend »

Doesn't work means: The <xyscripts> variable isn't resolved?

I've had similiar issues with windows environment variables yesterday and I've had to use eval() to do that...
In fact my paths weren't resolved if they contained more than just the environment variable, I even had to
do this...

Code: Select all

            $envVarList = regexmatches($item, "%[^%]+%", "|");
            foreach($envVar, $envVarList, "|") {
                $item = replace($item, $envVar, eval($envVar));
Can't remember that I had the same issues in the past so maybe a regression?
One of my scripts helped you out? Please donate via Paypal

Filehero
Posts: 2734
Joined: 27 Feb 2012 18:50
Location: Windows 11@100%

Re: Confused, can't read INI value correctly

Post by Filehero »

SammaySarkar wrote:Nope, it's the same with quotes in getkey... :(
Single or double quotes? Have you tested bino's line exactly as it was quoted?

I am asking because
SammaySarkar wrote:...But again doesn't work if the ini value is quoted (path='<xyscripts>\xyskins')
doesn't work as you obviously expect since single quotes are defined to prevent XY vars to be evaluated.

Try this

Code: Select all

$path_1="<xyscripts>\xyskins";
 $path_2='<xyscripts>\xyskins';
 msg($path_1<br>$path_2);
/e: slightly too late - but it's a different flavor.

Cheers,
Filehero

bdeshi
Posts: 4256
Joined: 12 Mar 2014 17:27
Location: Asteroid B-612
Contact:

Re: Confused, can't read INI value correctly

Post by bdeshi »

@Filehero, that was a posting typo, I used "s in script.
@highend, yes, <xyscripts> isn't resolved. I also tried eval() but it gave an "overflow 0/0" error.
Icon Names | Onyx | Undocumented Commands | xypcre
[ this user is asleep ]

highend
Posts: 15012
Joined: 06 Feb 2011 00:33
Location: Win Server 2022 @100%

Re: Confused, can't read INI value correctly

Post by highend »

Code: Select all

I also tried eval() but it gave an "overflow 0/0" error.
Because you've had more than the variable itself in the .ini file for "path" (the "\xyskins" part)

I guess it's a bug.

Until Don fixes it you could use:

Code: Select all

    $path = getkey("path","vars", "<xyscripts>\file.ini");
    $envVarList = regexmatches($path, "<[^>]+>", "|");
    foreach($envVar, $envVarList, "|") {
        $path = replace($path, $envVar, eval($envVar));
    }
    text $path;
One of my scripts helped you out? Please donate via Paypal

bdeshi
Posts: 4256
Joined: 12 Mar 2014 17:27
Location: Asteroid B-612
Contact:

Re: Confused, can't read INI value correctly

Post by bdeshi »

Sure looks like a bug.
Thanks for the alt fix. But I only have a few fixed variables, so replacelist should be faster than foreach+regex, right?

Code: Select all

$path = replacelist($path, '<xyscripts>|<xydata>…', "<xyscripts>|<xydata>…");
Icon Names | Onyx | Undocumented Commands | xypcre
[ this user is asleep ]

highend
Posts: 15012
Joined: 06 Feb 2011 00:33
Location: Win Server 2022 @100%

Re: Confused, can't read INI value correctly

Post by highend »

But I only have a few fixed variables, so replacelist should be faster than foreach+regex, right?
Absolutely. In my case I didn't want to populate a list with > 20 environment variables manually :)

Don't forget to add the separator "|" to your replacelist() command^^
One of my scripts helped you out? Please donate via Paypal

bdeshi
Posts: 4256
Joined: 12 Mar 2014 17:27
Location: Asteroid B-612
Contact:

Re: Confused, can't read INI value correctly

Post by bdeshi »

Right, thanks again!
Icon Names | Onyx | Undocumented Commands | xypcre
[ this user is asleep ]

TheQwerty
Posts: 4373
Joined: 03 Aug 2007 22:30

Re: Confused, can't read INI value correctly

Post by TheQwerty »

This is where the reprocess parameter of set comes in handy (and it also works with environment variables):

Code: Select all

set $path, getkey('path','vars', 'path\to\file.ini'), 'r';
 new("$path\res\some.file", file);

bdeshi
Posts: 4256
Joined: 12 Mar 2014 17:27
Location: Asteroid B-612
Contact:

Re: Confused, can't read INI value correctly

Post by bdeshi »

Yes, I'd tried this too while trying to solve:

Code: Select all

 $path = getkey("path", "vars", "path\to\file,ini");
 new("$path\res\some.file", file);
But in this case, the $path variable's value turns into the full path of <xyscripts>\Xyskins. I needed to keep it in the short form (for portability).
with "r": $path="C:\path\to\xyplorer\xydata\scripts\xyskins"
need to keep: $path="<xyscripts>\xyskins" and expand <xyscripts> ONLY where $path is used.
I'm going to either use highend's solution or just hardcode the path.
Icon Names | Onyx | Undocumented Commands | xypcre
[ this user is asleep ]

TheQwerty
Posts: 4373
Joined: 03 Aug 2007 22:30

Re: Confused, can't read INI value correctly

Post by TheQwerty »

Then only use a reprocessing set right before using $path or combine it with a reversed ResolvePath to keep it relative to <xyscripts>.

Post Reply