getkey - content of a whole section?

Please check the FAQ (https://www.xyplorer.com/faq.php) before posting a question...
highend
Posts: 14940
Joined: 06 Feb 2011 00:33
Location: Win Server 2022 @100%

getkey - content of a whole section?

Post by highend »

I'm unsure if this worked in the past but iirc it was possible to get the full content of section via:

Code: Select all

$content = getkey(, "General", "<come .ini file>");
With:

Code: Select all

[General]
Reserved=0
Broken=1
Test=0
Where $content became:

Code: Select all

Reserved=0
Broken=1
Test=0
Am I wrong or can anybody confirm this?
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: getkey - content of a whole section?

Post by bdeshi »

BTW,these days, a list of keys are still returned, but without values, and separated by null, which terminates any text output prematurely.

Code: Select all

::$content = getkey(, "Settings", <xyini>); $keys = replace($content,chr(00),<crlf>); text $content; text hexdump($content); text $keys;
ed: the same is true for sections. If section parameter is empty, all existing sections are returned null-separated.
Icon Names | Onyx | Undocumented Commands | xypcre
[ this user is asleep ]

admin
Site Admin
Posts: 66256
Joined: 22 May 2004 16:48
Location: Win8.1, Win10, Win11, all @100%
Contact:

Re: getkey - content of a whole section?

Post by admin »

Correct. The behavior can be read up here (although not really detailed): https://msdn.microsoft.com/en-us/librar ... 85%29.aspx
(XY just wraps this function).

I also think this has been different in earlier Windows versions. Hm.

Kind of funny that again we have a case where NULLs are returned and the output is mostly eaten by the Windows edit box. I'm slowly getting softer with regard to auto-patching the output in such cases... :whistle:

admin
Site Admin
Posts: 66256
Joined: 22 May 2004 16:48
Location: Win8.1, Win10, Win11, all @100%
Contact:

Re: getkey - content of a whole section?

Post by admin »

I got a short coding attack and did this (next beta v14.80.0239):

Code: Select all

    ' 20150304: returns a list of all key=value pairs in Section, separated by Separator
    ' syntax: getkeyvaluelist(Section, [INIfile], [Separator=CRLF])
    ' example: text getkeyvaluelist("General");
Still waiting for the documenting attack. Till then it will be undocumented.

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

Re: getkey - content of a whole section?

Post by bdeshi »

What about a list of Sections?

ed. maybe rename it to getini():

Code: Select all

    getini()
    Returns a list of all keys in Section or a list of sections,separated by Separator.
    Optionally with values or child keys respectively.
    syntax: getini([Section], [INIfile], [Separator=CRLF], [return terseness flag])
    example:
    text getini("General");
    //returns all keys only in General section of <xyini>
    text getini("General",,,1);
    //returns the same but with values as key=value
    text getini(,,,);
    //returns all sections in <xyini>
    text getini(,,,1);
    //returns the same but with child keys as section<tab>keys<tab>keys
ed2. or maybe getsectionlist() :lol:
Icon Names | Onyx | Undocumented Commands | xypcre
[ this user is asleep ]

admin
Site Admin
Posts: 66256
Joined: 22 May 2004 16:48
Location: Win8.1, Win10, Win11, all @100%
Contact:

Re: getkey - content of a whole section?

Post by admin »

What about a list of Sections?
Good.

terseness?
Overkill.

getsectionlist()?
Yep, better.

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

Re: getkey - content of a whole section?

Post by TheQwerty »

I think you guys are just making this too complicated and complex...

GetKey can already do the list of sections.

Unless you mean doing:

Code: Select all

$kvPairs = getkeyvaluelist('General|Settings'); // Get all key=values in General & Settings sections
But there's no decent way of distinguishing keys from each section with this unless it also prefixes the sections to the key names. Frankly, none of this is difficult to achieve with a foreach loop so I don't see the point in making this a more complicated function.

It's not like the inspiration to document this thing will come any easier if there is more to explain. :P


I'd much prefer the time be spent on things we cannot easily accomplish - like reading and changing the in memory values that correspond to XY's INI file. Those things requiring saving the settings, modifying them, and then restarting XY are a major PITA. ;)

EDIT: Actually scratch that... I want NEED user functions!

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

Re: getkey - content of a whole section?

Post by bdeshi »

simplest solution: add a separator parameter to getkey()
Key values can be retrieved easily from keylist. No need for additional SCs.
Icon Names | Onyx | Undocumented Commands | xypcre
[ this user is asleep ]

admin
Site Admin
Posts: 66256
Joined: 22 May 2004 16:48
Location: Win8.1, Win10, Win11, all @100%
Contact:

Re: getkey - content of a whole section?

Post by admin »

Indeed, GetKey can do it. So I just leave it all as it is now.

No need for a can worms ATM.

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

Re: getkey - content of a whole section?

Post by bdeshi »

admin wrote:Indeed, GetKey can do it. So I just leave it all as it is now.
a separator? nice to skip an extra step of replace(getkey(),chr(00),<crlf>)
Icon Names | Onyx | Undocumented Commands | xypcre
[ this user is asleep ]

admin
Site Admin
Posts: 66256
Joined: 22 May 2004 16:48
Location: Win8.1, Win10, Win11, all @100%
Contact:

Re: getkey - content of a whole section?

Post by admin »

SammaySarkar wrote:
admin wrote:Indeed, GetKey can do it. So I just leave it all as it is now.
a separator? nice to skip an extra step of replace(getkey(),chr(00),<crlf>)
Ah, okay. In that case getSectionList() is the better name indeed.

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

Re: getkey - content of a whole section?

Post by bdeshi »

eh (sorry!), but actually in that case that extra replace() seems better and simpler than new SCs... :whistle:
Icon Names | Onyx | Undocumented Commands | xypcre
[ this user is asleep ]

admin
Site Admin
Posts: 66256
Joined: 22 May 2004 16:48
Location: Win8.1, Win10, Win11, all @100%
Contact:

Re: getkey - content of a whole section?

Post by admin »

You can go the replace way if you want. My coding attack is over, I feel better, there won't be any docs, so case closed I suppose. :)

admin
Site Admin
Posts: 66256
Joined: 22 May 2004 16:48
Location: Win8.1, Win10, Win11, all @100%
Contact:

Re: getkey - content of a whole section?

Post by admin »

2 examples (v14.80.0239) to finish this little excercise:

Code: Select all

text getsectionlist("General");
text getsectionlist();

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

Re: getkey - content of a whole section?

Post by bdeshi »

another Secret for future newbies to find, at any case. :wink:
At the risk of beating a dead horse: y'know, returning keys without values could've been a choice.... keys can have huge huge values.... : whistle :
Icon Names | Onyx | Undocumented Commands | xypcre
[ this user is asleep ]

Post Reply