AutoHotkey Community

It is currently May 26th, 2012, 1:21 am

All times are UTC [ DST ]




Post new topic This topic is locked, you cannot edit posts or make further replies.  [ 51 posts ]  Go to page 1, 2, 3, 4  Next
Author Message
PostPosted: December 2nd, 2007, 2:19 am 
Offline
User avatar

Joined: August 11th, 2004, 1:47 am
Posts: 5347
Location: UK
Functions include:
  • Deleting, merging (with or without overwriting) and renaming sections
  • Moving/copying keys between sections
  • Finding keys with regex filters
  • Saving back to file whilst preserving formatting (i.e. retaining positions of existing keys, sections, etc.)

Best of all the script is performance enhanced with only string functions used for parsing content (no regex!), unlike all the other similar scripts you can find on the forum.

Download with documentation

_________________
GitHubScriptsIronAHK Contact by email not private message.


Last edited by polyethene on December 18th, 2007, 6:02 pm, edited 1 time in total.

Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: December 2nd, 2007, 12:12 pm 
Offline
User avatar

Joined: December 26th, 2005, 4:40 pm
Posts: 8775
This is great! I will try it and post again.
Many thanks. :)


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: December 2nd, 2007, 5:20 pm 
Offline

Joined: May 1st, 2007, 8:36 pm
Posts: 83
Location: The Netherlands
This is ecactly what I needed! Perfect timing! 8)

_________________
Printing css/html-formatted text


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: December 2nd, 2007, 8:33 pm 
Offline

Joined: April 17th, 2005, 7:47 pm
Posts: 289
Location: Sauerland
Apart from of the high usefulness of your functions - a pleasing and commendable documentation!
Thanks! 8)
__________________________________________
Created with BBCodeWriter 7.0 - the one and only :D


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: December 2nd, 2007, 8:36 pm 
Offline

Joined: May 1st, 2007, 8:36 pm
Posts: 83
Location: The Netherlands
Am I doing something wrong or is there a bug?

My ini-file is named core.ini and looks like this:
Code:
[Variables]
OtherDir = W:\some_directory
StartDir = W:\the_correct_startdir


I use the following code:
Code:
CS_Text(welcome) ;Display some info (version, etc.)
load_ini := ini_Load(ini, "core.ini")
if load_ini!=1
   CS_Text("Warning: could not load ini-file 'core.ini'")
else
{
   ;Read the ini-file
   StartDir := ini_Read(ini, "Variables", "StartDir", A_ScriptDir)
}

MsgBox, % StartDir

;CS_Text("<" . StartDir . ">")

The CS_ function is a function that will display the text in a control (not important now).
The messagebox will say "W:\the_correct_startdir", so that's correct.
But if the ini-file looks like this:
Code:
[Variables]
OtherDir = W:\some_directory

(so when StartDir doesn't exist) it should use the scripts working dir, shouldn't it? Or am I doing something wrong with the default value in the function?It now returns "r=W:\some_directory", which is the other value from the ini-file. It looks like it returns the first # characters, because when I change the value in the ini-file it will return that. (with half of the key! :? )

Any idea?

_________________
Printing css/html-formatted text


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: December 2nd, 2007, 8:54 pm 
Offline
User avatar

Joined: August 11th, 2004, 1:47 am
Posts: 5347
Location: UK
I found a bug in the default value handling in ini_Read. Bascailly I forgot to account for ErrorLevel as I had done in the Delete/Write functions. This has been fixed in v1.02 thanks.
Rabiator you can make similar web pages for your scripts with XN-Docs. I'm pleased you like it :)

_________________
GitHubScriptsIronAHK Contact by email not private message.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: December 16th, 2007, 1:13 pm 
Offline

Joined: December 16th, 2007, 12:55 pm
Posts: 48
ini_Write doesn't seem to want to create a new key:value pair if the key doesn't already exist.

testing.ahk
Code:
#Include ini.ahk
x := ini_Load(var, "testing.ini")
ini_Write(var, "Section1", "key4", "value4")
ini_Save(var, "testing.ini")


testing.ini (before):
Code:
[Section1]
key1 = value1
key2 = value2
key3 = value3


testing.ini (after running testing.ahk):
Code:
[Section1]
key1 = value1
key2 = value2
key3 = value3
key4 =


Out of curiosity, and looking for a quick workaround, I tried editing testing.ahk thusly, running the same ini_Write command twice, trying to force the value in with the second one:
Code:
#Include ini.ahk
x := ini_Load(var, "testing.ini")
ini_Write(var, "Section1", "key4", "value4")
ini_Write(var, "Section1", "key4", "value4")
ini_Save(var, "testing.ini")


It works, but not quite as expected:
Code:
[Section1]
key1 = value1
key2 = value2
key3 = value3
key4 = value4
key1 = value1
key2 = value2
key3 = value3
key4 = value4


I tried again, using this, which finally worked like I wanted:
Code:
#Include ini.ahk
x := ini_Load(var, "testing.ini")
ini_Write(var, "Section1", "key4")              ;write an empty value to the key first
ini_Write(var, "Section1", "key4", "value4")    ;then dump the value in
ini_Save(var, "testing.ini")


That works like it should, but seems a little clumsy.
Edit: that works "sometimes" like it should, and sometimes does the weird doubling thing documented above.

That said, these functions are definitely going to make some scripts I'm working on much easier.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: December 16th, 2007, 1:48 pm 
Offline
User avatar

Joined: August 11th, 2004, 1:47 am
Posts: 5347
Location: UK
I had a typo in my code, 'k' should have been 'l' in one of the variable names. This has been fixed in update 1.04 thanks!

_________________
GitHubScriptsIronAHK Contact by email not private message.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: December 19th, 2007, 4:37 pm 
Offline
User avatar

Joined: August 11th, 2004, 1:47 am
Posts: 5347
Location: UK
Version 1.06 includes two new functions - ini_FindSectionsRE() to get a list of section names matching a regex and ini_ToXML() to convert the INI to XML. Here's an example of what ToXML can do with the default settings:

Code:
[sec1]
key1 = abc
second.key = def

[another_sec]
emptykey =
nonemptykey=12325

Becomes...
Code:
<?xml version="1.0" encoding="iso-8859-1"?>
<ini>
  <sec1>
    <key1>abc</key1>
    <second.key>def</second.key>
  </sec1>
  <another_sec>
    <emptykey />
    <nonemptykey>12325</nonemptykey>
  </another_sec>
</ini>


I have also tweaked the way the parser works for a slight performance improvement and changed the parameter order of ini_FindKeysRE() to match the other key functions. Big thanks to the 100+ people that have downloaded this!

_________________
GitHubScriptsIronAHK Contact by email not private message.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: December 19th, 2007, 5:26 pm 
Offline

Joined: May 24th, 2006, 2:49 pm
Posts: 4511
Location: Belgrade
You have some bugs in the code...


For instance, take this real life ini (wincmd.ini)

Code:
ThumbsCustomFieldsEnabled=1
ThumbsCustomField=[=images.Width] x [=images.Height]


Your function returns:
Code:
Enabled=[=images.Width] x [=images.Height]


using code:
Code:
SetBatchLines, -1
ii := "wincmd.ini"
ss := "Configuration"
kk := "ThumbsCustomField"

ini_Load(h, ii) ;
msgbox % ini_Read(h, ss, kk)


Second, it would be nice to change the name of your module as there is already one I created with the same name, as you know, long before you did.

Thx.

_________________
Image


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: December 19th, 2007, 5:49 pm 
Offline
User avatar

Joined: August 11th, 2004, 1:47 am
Posts: 5347
Location: UK
majkinetor wrote:
Second, it would be nice to change the name of your module as there is already one I created with the same name, as you know, long before you did.
I changed from "INI Functions" to "INI Library" with this release, what do you think it should be called?

Thanks for the bug report, looks like some of the shortcut techniques I use fail to work with poorly named structures due to overlapping etc. Fixed in 1.06r1.

_________________
GitHubScriptsIronAHK Contact by email not private message.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: December 19th, 2007, 6:26 pm 
Offline

Joined: May 24th, 2006, 2:49 pm
Posts: 4511
Location: Belgrade
Quote:
I changed from "INI Functions" to "INI Library" with this release, what do you think it should be called?

I wasn't talk about that, but about prefix. User can't have both your and mine module in stdlib for instance, yet it might want that since they totaly differ in approach and functionality. Also, by looking third party code you generaly are not sure what is what. For instance tini_ would sufice although i don't suggest anything.

_________________
Image


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: December 19th, 2007, 6:38 pm 
Offline
User avatar

Joined: August 11th, 2004, 1:47 am
Posts: 5347
Location: UK
majkinetor wrote:
User can't have both your and mine module in stdlib for instance, yet it might want that since they totaly differ in approach and functionality.
Actually they are quite similar - I wrote this script to replace yours in my personal stdlib when you decided not to follow my requests for certain additional features and advice on optimization. Plus other users such as Superfraggle, Rajat and toralf have also written very similar scripts, how do you propose we resolve these conflicts? I believe users can decide which one they prefer and use delete the rest, or manually #Include.

_________________
GitHubScriptsIronAHK Contact by email not private message.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: December 19th, 2007, 6:46 pm 
Offline

Joined: May 24th, 2006, 2:49 pm
Posts: 4511
Location: Belgrade
Quote:
Actually they are quite similar

Actually, they are not which is why I ...
Titan wrote:
decided not to follow my requests for certain additional features


Quote:
... and advice on optimization

Its as fast as yours in my benchmarks (the reason why i detected bug)

_________________
Image


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: December 19th, 2007, 7:04 pm 
Offline
User avatar

Joined: August 11th, 2004, 1:47 am
Posts: 5347
Location: UK
majkinetor wrote:
Its as fast as yours in my benchmarks
According to my tests yours is 35% slower on average, and since you use file functions at every call your methods are susceptible to disk caching issues and memory leaks (remember what Laszlo told you ;)).

Having just glanced at your api which I hadn't done previously, I noticed that you made many modifications since the last time I really used your script. For example, you have overloads for deleting keys, one by name and another using regex; mine requires you to find the definite name(s) with ini_FindKeyRE then remove them as usual with ini_Delete. Maybe this is a good thing, those who are used to a structured and procedural way of accessing data would use my library whereas the casual user may find yours a little easier to learn.

_________________
GitHubScriptsIronAHK Contact by email not private message.


Report this post
Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic This topic is locked, you cannot edit posts or make further replies.  [ 51 posts ]  Go to page 1, 2, 3, 4  Next

All times are UTC [ DST ]


Who is online

Users browsing this forum: No registered users and 41 guests


You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Powered by phpBB® Forum Software © phpBB Group