AutoHotkey Homepage AutoHotkey Community
Let's help each other out
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

INI Library - ultra fast in-memory data mining function set
Goto page 1, 2, 3  Next
 
Post new topic   Reply to topic    AutoHotkey Community Forum Index -> Scripts & Functions
View previous topic :: View next topic  
Author Message
Titan



Joined: 11 Aug 2004
Posts: 5438
Location: /b/

PostPosted: Sun Dec 02, 2007 2:19 am    Post subject: INI Library - ultra fast in-memory data mining function set Reply with quote

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
_________________



Last edited by Titan on Tue Dec 18, 2007 6:02 pm; edited 1 time in total
Back to top
View user's profile Send private message Send e-mail Visit poster's website
SKAN



Joined: 26 Dec 2005
Posts: 6824

PostPosted: Sun Dec 02, 2007 12:12 pm    Post subject: Reply with quote

This is great! I will try it and post again.
Many thanks. Smile
Back to top
View user's profile Send private message
Wouther



Joined: 01 May 2007
Posts: 83
Location: The Netherlands

PostPosted: Sun Dec 02, 2007 5:20 pm    Post subject: Reply with quote

This is ecactly what I needed! Perfect timing! Cool
_________________
Printing css/html-formatted text
Back to top
View user's profile Send private message
Rabiator



Joined: 17 Apr 2005
Posts: 281
Location: Sauerland

PostPosted: Sun Dec 02, 2007 8:33 pm    Post subject: Reply with quote

Apart from of the high usefulness of your functions - a pleasing and commendable documentation!
Thanks! Cool
__________________________________________
Created with BBCodeWriter 7.0 - the one and only Very Happy
Back to top
View user's profile Send private message
Wouther



Joined: 01 May 2007
Posts: 83
Location: The Netherlands

PostPosted: Sun Dec 02, 2007 8:36 pm    Post subject: Reply with quote

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! Confused )

Any idea?
_________________
Printing css/html-formatted text
Back to top
View user's profile Send private message
Titan



Joined: 11 Aug 2004
Posts: 5438
Location: /b/

PostPosted: Sun Dec 02, 2007 8:54 pm    Post subject: Reply with quote

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 Smile
_________________

Back to top
View user's profile Send private message Send e-mail Visit poster's website
pokercurious



Joined: 16 Dec 2007
Posts: 48

PostPosted: Sun Dec 16, 2007 1:13 pm    Post subject: Reply with quote

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.
Back to top
View user's profile Send private message
Titan



Joined: 11 Aug 2004
Posts: 5438
Location: /b/

PostPosted: Sun Dec 16, 2007 1:48 pm    Post subject: Reply with quote

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!
_________________

Back to top
View user's profile Send private message Send e-mail Visit poster's website
Titan



Joined: 11 Aug 2004
Posts: 5438
Location: /b/

PostPosted: Wed Dec 19, 2007 4:37 pm    Post subject: Reply with quote

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!
_________________

Back to top
View user's profile Send private message Send e-mail Visit poster's website
majkinetor



Joined: 24 May 2006
Posts: 3714
Location: Belgrade

PostPosted: Wed Dec 19, 2007 5:26 pm    Post subject: Reply with quote

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.
_________________
Back to top
View user's profile Send private message MSN Messenger
Titan



Joined: 11 Aug 2004
Posts: 5438
Location: /b/

PostPosted: Wed Dec 19, 2007 5:49 pm    Post subject: Reply with quote

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

Back to top
View user's profile Send private message Send e-mail Visit poster's website
majkinetor



Joined: 24 May 2006
Posts: 3714
Location: Belgrade

PostPosted: Wed Dec 19, 2007 6:26 pm    Post subject: Reply with quote

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.
_________________
Back to top
View user's profile Send private message MSN Messenger
Titan



Joined: 11 Aug 2004
Posts: 5438
Location: /b/

PostPosted: Wed Dec 19, 2007 6:38 pm    Post subject: Reply with quote

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

Back to top
View user's profile Send private message Send e-mail Visit poster's website
majkinetor



Joined: 24 May 2006
Posts: 3714
Location: Belgrade

PostPosted: Wed Dec 19, 2007 6:46 pm    Post subject: Reply with quote

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)
_________________
Back to top
View user's profile Send private message MSN Messenger
Titan



Joined: 11 Aug 2004
Posts: 5438
Location: /b/

PostPosted: Wed Dec 19, 2007 7:04 pm    Post subject: Reply with quote

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

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

Back to top
View user's profile Send private message Send e-mail Visit poster's website
Display posts from previous:   
Post new topic   Reply to topic    AutoHotkey Community Forum Index -> Scripts & Functions All times are GMT
Goto page 1, 2, 3  Next
Page 1 of 3

 
Jump to:  
You can post new topics in this forum
You can reply to topics in this forum


Powered by phpBB © 2001, 2005 phpBB Group