Jump to content

Sky Slate Blueberry Blackcurrant Watermelon Strawberry Orange Banana Apple Emerald Chocolate
Photo

[Library] oINI - INI Object


  • Please log in to reply
3 replies to this topic
A_Samurai
  • Members
  • 30 posts
  • Last active: Jan 22 2012 01:53 PM
  • Joined: 29 Aug 2011
Download

for more details: documentation

Notes: I know there are lots of INI libraries around here but I needed something more intuitive for myself. Bug reports, suggestions, and English teachers are welcome.

Example:
INIContents = 
(Ltrim
	[Section1]
	key_a=valueA
	key_b=valueB
	[Section2]
	key1=value_a
	[Section3]
	keyA=value1
	keyB=value2
	keyC=value3
)

;load the text data into an INI object
oINI := oINI_Load(INIContents) 

;turn the OnTheFly mode to false. If the path is not specified at load time, this mode is off by default.
if oINI.OnTheFly	
	oINI.OnTheFly(False)	;False is to turn it off. True is to turn it on.

;Edit the ini object.
oINI.Remove("Section1", "Section2")		;this removes the range of Section1 to Section2
oINI.Section4 := { key_1 : "value_1", key_2 : "value_2" }

;Check the contents
For section, sections in oINI
	For key, value in sections
		msgbox in For-loop: [%section%] %key% `, %value% 

;Before saving the contents, specify the path
INIPath := A_ScriptDir "\demo2.ini"
oINI.SetPath(INIPath)

;Save the contens
oINI.Save()		
Run, Notepad "%INIPath%"
	
ExitApp

English teachers are welcome.

Tuncay
  • Members
  • 1945 posts
  • Last active: Feb 08 2015 03:49 PM
  • Joined: 07 Nov 2006
I will have a look in your code. :) It is always nice to see new and different solutions.

1. Why do you use IniWrite and IniDelete commands on Save function? Whereas I can understand the IniDelete to delete whole sections, but then write to the file with for each key? I would just create a new string and write with FileAppend once in that case.

2. Small typo on line 132 (a comment): specifiled

3. I like your OnTheFly mode idea.

4. My parser (currently in alpha stage and not available) treats "[nbcvnbcv=test]" as a key, yours as a section.

5. Comments are lost.

No signature.


A_Samurai
  • Members
  • 30 posts
  • Last active: Jan 22 2012 01:53 PM
  • Joined: 29 Aug 2011
Updates: Fixed a bug not inserting a key-value pair when a regular assignment is performed with child objects(section objects).Thanks for the feedback.

1. Why do you use IniWrite and IniDelete commands on Save function?

It's for the overwriting option.

Whereas I can understand the IniDelete to delete whole sections, but then write to the file with for each key?

It's for the oINI_ErrorLevel property and the override option but since FileAppend seems to have the same ErrorLevel handling I guess, it's a good option to consider for further improvement.

4. My parser (currently in alpha stage and not available) treats "[nbcvnbcv=test]" as a key, yours as a section.

I don't worry about it too much.

Comments are lost.

Please make sure you specify the override option. cf. oINI.Save("", false)
English teachers are welcome.

A_Samurai
  • Members
  • 30 posts
  • Last active: Jan 22 2012 01:53 PM
  • Joined: 29 Aug 2011
v1.0.2 Updates:
[*:1gpwimgx]Fixed a bug loading commented sections and key-value pairs.[*:1gpwimgx]Added theExport() method. Currently it supports XML and CSV.