B4A Library [lib] CIniFile v.1.0 released

Hi guys!

this is my library for Ini files read... would you like handle your app config with Ini file simply? Or are you a old Windows Ini files nostalgic guy simply? well... this library is for you! :sign0060:

below you can find documentation:

B4X:
'Initializes the object and loads the specified Ini file
Public Sub Initialize(Dir As String, Filename As String)

'Loads the Ini file. It can be the same as specified in Initialize or another
Public Sub Load(Dir As String, Filename As String)

'Logs the entire internal data structure
Public Sub Debug

'Returns a string value from Ini file at specified Section and Key
'If value not found, returns NotFoundReturnValue
Public Sub Get(Section As String, Key As String, NotFoundReturnValue As String) As String

'Returns a List object from Ini file at specified Section and Key
'Value of Key in Ini file must be a standard list in format KeyName = { 1, 2, 3 }
'If value not found, returns Null
Public Sub GetList(Section As String, Key As String) As List

'Returns a string value indexed by Index from Ini file at specified Section and Key
'Value of Key in Ini file must be a standard list in format KeyName = { 1, 2, 3 }
'List can be a mixed list like KeyName = { , 1, two, 3.0, false }
'Index is zero based and must be in 0 > Index > List.Size - 1 range. Index out of range returns NotFoundReturnValue
'If value not found, returns NotFoundReturnValue
Public Sub GetIndex(Section As String, Key As String, Index As Int, NotFoundReturnValue As String) As String

'Returns a boolean value from Ini file at specified Section and Key
'Returns False to any value other than "True" string (case unsensitive)
'If value not found, returns False
Public Sub GetBoolean(Section As String, Key As String) As Boolean

'Returns a boolean value indexed by Index from Ini file at specified Section and Key
'Value of Key in Ini file must be a standard list in format KeyName = { 1, 2, 3 }
'List can be a mixed list like KeyName = { , 1, two, 3.0, false }
'Index is zero based and must be in 0 > Index > List.Size - 1 range. Index out of range returns False
'If value not found, returns False
Public Sub GetIndexBoolean(Section As String, Key As String, Index As Int) As Boolean

'Returns a int value from Ini file at specified Section and Key
'If value not found, returns NotFoundReturnValue
Public Sub GetInt(Section As String, Key As String, NotFoundReturnValue As Int) As Int

'Returns a int value indexed by Index from Ini file at specified Section and Key
'Value of Key in Ini file must be a standard list in format KeyName = { 1, 2, 3 }
'List can be a mixed list like KeyName = { , 1, two, 3.0, false }
'Index is zero based and must be in 0 > Index > List.Size - 1 range. Index out of range returns NotFoundReturnValue
'If value not found, returns NotFoundReturnValue
Public Sub GetIndexInt(Section As String, Key As String, Index As Int, NotFoundReturnValue As Int) As Int

'Returns a double value from Ini file at specified Section and Key
'If value not found, returns NotFoundReturnValue
Public Sub GetDouble(Section As String, Key As String, NotFoundReturnValue As Double) As Double

'Returns a double value indexed by Index from Ini file at specified Section and Key
'Value of Key in Ini file must be a standard list in format KeyName = { 1, 2, 3 }
'List can be a mixed list like KeyName = { , 1, two, 3.0, false }
'Index is zero based and must be in 0 > Index > List.Size - 1 range. Index out of range returns NotFoundReturnValue
'If value not found, returns NotFoundReturnValue
Public Sub GetIndexDouble(Section As String, Key As String, Index As Int, NotFoundReturnValue As Double) As Double

'Returns a float value from Ini file at specified Section and Key
'If value not found, returns NotFoundReturnValue
Public Sub GetFloat(Section As String, Key As String, NotFoundReturnValue As Float) As Float

'Returns a float value indexed by Index from Ini file at specified Section and Key
'Value of Key in Ini file must be a standard list in format KeyName = { 1, 2, 3 }
'List can be a mixed list like KeyName = { , 1, two, 3.0, false }
'Index is zero based and must be in 0 > Index > List.Size - 1 range. Index out of range returns NotFoundReturnValue
'If value not found, returns NotFoundReturnValue
Public Sub GetIndexFloat(Section As String, Key As String, Index As Int, NotFoundReturnValue As Float) As Float

'Checks if Value is contained in list object from Ini file at specified Section and Key
'Returns the index of value in list if found, else returns -1
Public Sub IsIn(Section As String, Key As String, Value As String) As Int

any criticism, advice or suggestion is welcome!

(any donation is welcome too!) :sign0161: :)

happy coding!
 

Attachments

  • CIniFile.zip
    8.4 KB · Views: 592

agraham

Expert
Licensed User
Longtime User
Well, you did ask :)

I guess that this is a Basic4android class compiled as a library - which begs the question why not just publish it as the source code so users can compile it to a library if they require or just incorporate it directly in their project and maybe modify it if required?

Also I think a lot of your explicit typing Subs are superfluous as Basic4android will do type coercion from strings to whatever is the required type during assignment so you can return everything as a string.
 

bluedude

Well-Known Member
Licensed User
Longtime User
Ini files, why?

Not sure why we need this if we have stuff like keyvalue store etc. Anyway, from a nostalgic point of view I guess it is fine :)
 

fiaful

Member
Licensed User
Longtime User
yes... old ini files :)

First of all, thanks for the answers ...

@ agraham
the library is actually compiled with basic4android ... I have not released the source code simply because I'm not open source fan... I'm a old-school programmer and I think, like many, that the open source killed software market ... This is my point of view of course ... however I have seen that many libraries can be downloaded from this site do not include the source also :)

for subs repeated ... you're right, basic4android converts everything automatically ... and probably Get, GetList and GetIndex cover all needs ... but it seemed nice, if only for readability, add the typed functions.

@ bluedude
uhm ... I just did not know the existence of keyvalue store :)
although I do not know if other methods allow read / modify the configuration file in humane manner... as well as allow the ini file instead ... :)

we can say that it is one more tool, isn't it? :)
 

agraham

Expert
Licensed User
Longtime User
however I have seen that many libraries can be downloaded from this site do not include the source also :)
Mainly because most libraries are written in Java and compiled in the Eclipse IDE. Usually if you request the source you will be given it, even for official libraries. Compiled Java doesn't hide much anyway. I knew your library was a compiled Basi4android Class and not an externally compiled library by looking at the decompiled source with the JD-GUI Java Decompiler.
 

JohnJCES

New Member
Licensed User
Longtime User
Being an old Delphi programmer, but very new to Basic 4 Android, I found this library of interest. One thing noted is, how do you write to the INI file? All the functions above show get, not write. Again, I'm new here and just not seeing it or must be missing something.
 

fiaful

Member
Licensed User
Longtime User
Being an old Delphi programmer, but very new to Basic 4 Android, I found this library of interest. One thing noted is, how do you write to the INI file? All the functions above show get, not write. Again, I'm new here and just not seeing it or must be missing something.

Hi john... this lib is designed for read only ini files... (you have to prepare your config file out-of-the-box then copy it and read it in your app)... if you want write ini file you have to provide your way... (at this time)
 
Top