Problems with Setkey [and Getkey() ]

Please check the FAQ (http://www.xyplorer.com/faq.php) before posting a question...

Problems with Setkey [and Getkey() ]

Postby PeterH » 12 Feb 2012 23:07

I have "User button 1" in toolbar, named "Copy to Other Pane", with command #804.
(In real it's more complicated - but I've reduced it to this.)

This leads in XYplorer.ini in section [CustomButtons] to the key=value
1=""Copy to Other Pane||0" #804;"
Note the 2 leading double-quotes, and the single double-quotes in the middle and at the end!
(No - it's not from me: XY created that...)

Now I try to re-create this key/value in a new installation with the Setkey command - but I can do what I want: I can't get it to set the correct combination of quotes! Things I've tried:
Code: Select all
   Setkey ""Copy to Other Pane||0" #804;", 1, "Custombuttons";
   Setkey '""Copy to Other Pane||0" #804;"', 1, "Custombuttons";
   Setkey """""Copy to Other Pane||0"" #804;""", 1, "Custombuttons";
   Setkey "Copy to Other Pane||0" #804;", 1, "Custombuttons;
   Setkey """Copy to Other Pane||0"" #804;", 1, "Custombuttons";

...and others.
The first is formally wrong.
Formally + in contents I'd expect the 2nd (correct double-quotes quoted in single quotes) and 3rd (whole string double-quoted, and all quotes inside doubled) version to be correct, while the 4th should (and does) lack the outer quotes.

Hoping to get a hint I tried Getkey - but it returned the value wrong: without the outer quotes :cry: :
"Copy to Other Pane||0" #804;

In the moment I'm out of ideas :oops:
Can someone help?
W7(x64) SP1 German
( +WXP SP3 )
PeterH
 
Posts: 1740
Joined: 21 Nov 2005 20:39
Location: Germany

Re: Problems with Setkey [and Getkey() ]

Postby PeterH » 12 Feb 2012 23:21

... 2 more tries:
Code: Select all
   $v = '""Copy to Other Pane||0" #804;"';
   Setkey $v, 1, "Custombuttons";
--- and ---
   $v = '"Copy to Other Pane||0" #804;';
   Setkey $v, 1, "Custombuttons";


The first version should be correct, but it adds a pair of double-quotes. :x
If it would do the same for the 2nd try it would be right. So it doesn't :cry: :evil: :cry:
W7(x64) SP1 German
( +WXP SP3 )
PeterH
 
Posts: 1740
Joined: 21 Nov 2005 20:39
Location: Germany

Re: Problems with Setkey [and Getkey() ]

Postby PeterH » 15 Feb 2012 13:50

I've got it!!!!
...though I think it's more a circumvention than a solution, and I think somewhere there's a bug in.

I found a thread from Muroph from 1.9.2009, "getkey and quotes". (I did contribute, too.)
Till this morning I always thought from side of the ini-file. (I just want to clone a value seen in the file by using the setkey command!) Now i learned (again) to respect quoting from setkey-command to the file, be it in XY or even be it in Windows. (The opposite of "GetPrivateProfileString"? Don't know how XY writes the key, and Windows might change here, too.)
The Conclusion of today: if the ini says
key=""abc" def"
the value in XY should be
"abc" def
but testing with this lead to
key="abc" def
in the file. Wrong!
Quoting this string lead to double-adding quotes in the file:
key="""abc" def""
No no no!

The circumvention: I added a space character to the end of the string!
And suddenly someone (XY or Windows?) added just one pair of quotes around the string - and the ini-file contained what it should, plus that one space character, which shouldn't make a problem here...

To verify: run the following script
1st group: text without trailing " ", unquoted and quoted
2nd group: text with trailing " ", unquoted and quoted
and at the end the contents of the created ini-file is shown.

Code: Select all
   $file = "%temp%\XYtest.ini";  // name of .ini file to test with

   Delete 0, 0, $file;           // to clean all entries (no Recycler, no Question)
// - - - - - - - - - - - - - - - - - - - - - - - - -
   $t1   = '"Copy/Move to Other Pane||0" #804;   #803;';        // THE value I (NO space at end!)

   SetKey       $t1 , test1, test1, $file;
   SetKey Quote($t1), test2, test1, $file;
   
   $t11  = GetKey(    test1, test1, $file);
   $t12  = GetKey(    test2, test1, $file);
// - - - - - - - - - - - - - - - - - - - - - - - - -
   $t2   = '"Copy/Move to Other Pane||0" #804;   #803; ';       // THE value II: added trailing space

   SetKey       $t2 , test1, test2, $file;
   SetKey Quote($t2), test2, test2, $file;
   
   $t21  = GetKey(    test1, test2, $file);
   $t22  = GetKey(    test2, test2, $file);
// - - - - - - - - - - - - - - - - - - - - - - - - -
   $file = ReadFile($file);
   
   Text     "$t1<crlf 2>$t11<crlf>$t12"
   ."<crlf 3>$t2<crlf 2>$t21<crlf>$t22"
   ."<crlf 3>$file";

Now what's the error???
- either XYs "guessing", when setkey should add quotes
- or windows on writing that key, maybe doing it "somehow unexpected" in this case
- or the value in XY-ini, created by XY, that maybe should not be quoted
- or still something else???

At least it seams to be impossible to clone a (special) setting made by XY in it's ini-file, by the XY-command setkey - but just that's the reason for setkey?!

Only the "trick" with the appended " " leads to a maybe acceptable result. (I didn't test that till now...)


edit verified: the trailing " " makes no problem in my usage case
Code: Select all
   setkey '"Copy/Move to Other Pane" Load "CM2OtherPane.xys"; ', 1, "CustomButtons";
W7(x64) SP1 German
( +WXP SP3 )
PeterH
 
Posts: 1740
Joined: 21 Nov 2005 20:39
Location: Germany

Re: Problems with Setkey [and Getkey() ]

Postby admin » 22 Feb 2012 11:30

If you can define the problem in 3 lines I will look at it. ;)
admin
Site Admin
 
Posts: 32903
Joined: 22 May 2004 15:48
Location: Cologne

Re: Problems with Setkey [and Getkey() ]

Postby PeterH » 22 Feb 2012 15:54

admin wrote:If you can define the problem in 3 lines I will look at it. ;)

3? Let's see. Looking at the beginning of the thread:

Creation of a CustomButton lead to a line in the xyplorer.ini:
1=""Copy to Other Pane||0" #804;[tab]#803;"
([tab] - here and in the following - stands for a tab character. No problem with that.)

I want to create exact this line with SetKey, but find it's impossible, in means of quoting!

That were 2 or 3 lines? That's it!

If you want a bit more, my findings: reading above line with GetKey returns the value without the outer quotes. "As if" I had filled a variable:
$val = '"Copy to Other Pane||0" #804;[tab]#803;'; //makes sense!

Writing this with
SetKey $val, 5, $sect;
writes the line without the original outer quotes. Wrong:
5="Copy to Other Pane||0" #804;[tab]#803;

Writing this with
SetKey Quote($val), 6, $sect;
also writes the line wrong, with an extra set of outer quotes:
6="""Copy to Other Pane||0" #804;[tab]#803;""

I've tested some other strange combinations, but as said before: I found no way to write the key exactly as XY had done it by writing the value for the CustomButton to xyplorer.ini!

But I happened to find a circumvention: if I modify the value of the string like
$val = '"Copy to Other Pane||0" #804;[tab]#803; '; //modified!!!
(note the added ' ' in front of the trailing single-quote) and write this - then a single set of double quotes is added, i.e. this modified string can be written as expected.
(This added ' ' works OK in this usage case - but it should also be possible without it!)
W7(x64) SP1 German
( +WXP SP3 )
PeterH
 
Posts: 1740
Joined: 21 Nov 2005 20:39
Location: Germany

Re: Problems with Setkey [and Getkey() ]

Postby admin » 23 Feb 2012 15:10

Confirmed, but it is not necessary to quote this value. GetKey will work fine w/out quotes.
admin
Site Admin
 
Posts: 32903
Joined: 22 May 2004 15:48
Location: Cologne

Re: Problems with Setkey [and Getkey() ]

Postby PeterH » 24 Feb 2012 14:24

admin wrote:Confirmed, but it is not necessary to quote this value. GetKey will work fine w/out quotes.
Did you change this text, or did I dream last night?
OK, it was quite late: maybe I misinterpreted it after just having read before:
v10.80.0313 - 2012-02-23 15:36
+ SC setkey enhanced: Added optional parameter flags.
Syntax: setkey value, key, section, [INIfile], [flags]
flags: 1: Write the value in quotes.
Examples:
// Year=2012
setkey "2012", "Year", "Vacation", "<curpath>\holiday.ini";
// Year="2012"
setkey "2012", "Year", "Vacation", "<curpath>\holiday.ini", 1;
...


The problem: almost whatever you do this way will be problematic...

- from view of the change: it helps technically - but how can I know when to explicitly quote? (Here it's just dependent from a possibly trailing space character!)
OK: for this usage case I know it now.

- from "GetKey will work fine w/out quotes.": the problem is, that this doesn't really help! What must be met isn't what Getkey returns, but what XY when interpreting the XYplorer.ini (on startup) will understand, in this and any other future cases.
OK-1: for this usage case I know it now.
OK-2: if you tell that XY internally will interpret the ini-file exactly as the command Getkey does - then we are on a better side! Then I just can Setkey, what Getkey gets - and everything is almost fine!

Maybe it would even be best, if XY when writing XYplorer.ini (by Save Settings etc.) would write exactly the same as Setkey does? Then there would just be no more reason for misunderstanding / misinterpreting...

You see my main problem? As long as XY (on SaveSettings) writing to the .ini writes something different than Setkey (by default) does, I can not expect that XY when interpreting the .ini understands the same as Getkey shows...
W7(x64) SP1 German
( +WXP SP3 )
PeterH
 
Posts: 1740
Joined: 21 Nov 2005 20:39
Location: Germany

Re: Problems with Setkey [and Getkey() ]

Postby admin » 24 Feb 2012 14:52

Too many words.

Is there a bug? If yes, post code.
admin
Site Admin
 
Posts: 32903
Joined: 22 May 2004 15:48
Location: Cologne

Re: Problems with Setkey [and Getkey() ]

Postby PeterH » 24 Feb 2012 16:46

admin wrote:Too many words.

Is there a bug? If yes, post code.

Code: Select all
   $key1 = Getkey(1, "Custombuttons");
   Setkey $key1, 1, "Custombuttons";
changes the value of this key.

Code: Select all
   $key2 = Getkey(2, "Custombuttons");
   Setkey $key2, 2, "Custombuttons", , 1;
changes the value of another key.

Both keys initially created by XY.

The difference between these 2 cannot be foreseen at scripting time.

IMO reason is not getkey/setkey, but the value "generated" by XY in 1st case: differs from how setkey works - seems to be invalid.
W7(x64) SP1 German
( +WXP SP3 )
PeterH
 
Posts: 1740
Joined: 21 Nov 2005 20:39
Location: Germany

Re: Problems with Setkey [and Getkey() ]

Postby admin » 24 Feb 2012 16:56

When you quote values on SetKey you are on the safe side. GetKey will always unquote (strip the outer double quotes) a quoted value, and trim spaces off unquoted values.

Quoting values is necessary when they are quoted or when they have leading or trailing spaces.
admin
Site Admin
 
Posts: 32903
Joined: 22 May 2004 15:48
Location: Cologne

Re: Problems with Setkey [and Getkey() ]

Postby PeterH » 24 Feb 2012 17:23

My problem is XY itself reading the changed key on restart: will it react same as Getkey when reading the changed value?
(In between the time I assume yes?)

But if XY on SaveSettings, in [CustomButtons] for values *without* trailing blancs, (that seams normal case,) would *not* add quotes around the whole string, i.e. same as setkey, the problem would not arise.
W7(x64) SP1 German
( +WXP SP3 )
PeterH
 
Posts: 1740
Joined: 21 Nov 2005 20:39
Location: Germany

Re: Problems with Setkey [and Getkey() ]

Postby admin » 24 Feb 2012 17:26

Yes.

Performance.
admin
Site Admin
 
Posts: 32903
Joined: 22 May 2004 15:48
Location: Cologne

Re: Problems with Setkey [and Getkey() ]

Postby admin » 24 Feb 2012 18:24

admin wrote:Quoting values is necessary when they are quoted or when they have leading or trailing spaces.
BTW, XY's SetKey knows this, of course, and auto-quotes values when necessary.
admin
Site Admin
 
Posts: 32903
Joined: 22 May 2004 15:48
Location: Cologne

Re: Problems with Setkey [and Getkey() ]

Postby PeterH » 24 Feb 2012 22:01

admin wrote:
admin wrote:Quoting values is necessary when they are quoted or when they have leading or trailing spaces.
BTW, XY's SetKey knows this, of course, and auto-quotes values when necessary.

The problem seems to be in this case, that XY on saving the XYplorer.ini un-neccessary quoted values?
(As said before: when writing to the section [CustomButtons].)
Values, that until before v10.80.0313 even could not be quoted at all by SetKey.
W7(x64) SP1 German
( +WXP SP3 )
PeterH
 
Posts: 1740
Joined: 21 Nov 2005 20:39
Location: Germany

Re: Problems with Setkey [and Getkey() ]

Postby admin » 25 Feb 2012 09:55

Yes, I spare the test for performance reasons. There is no problem at all with that.
admin
Site Admin
 
Posts: 32903
Joined: 22 May 2004 15:48
Location: Cologne

Next

Return to Tips & Tricks, Questions & Answers



Who is online

Users browsing this forum: No registered users and 1 guest