Proposing a cIniFile change
#1
I'd like to propose a change to the way cIniFile handles its SetValue() calls.

Currently, if any of the SetValue() family of functions is called, the value is searched for and if it exists, a *new* value is added (resulting in duplicate value being stored in the file). This can be fixed by setting the "create" parameter to false, but then the value is not created if it doesn't exist at all.

I'd say the semantics that is the most useful is "set if it exists, create if it doesn't", which are not available in the current code. I can't really see any use for duplicate values in the file, since the code is unable to load them back later (only the first match is always reported).

I'm therefore proposing to change the SetValue() method to ignore the "create" parameter if the value already exists, and always overwrite the value.

Are there any objections?

Note that this function is available at plugin-interface level, too, so plugins will be affected as well.
Reply
Thanks given by:
#2
Objection!

I'll write out why later :p
Reply
Thanks given by:
#3
Well hurry up, then, this behavior is messing up my rev 439 "fix" for saving the world seed, and it's driving me nuts that everytime I run MCServer it messes up the world.ini file.Tongue
Reply
Thanks given by:
#4
Well if you fix that you'll break many other things!

I hacked some sort of arrays functionality in the ini files, that's how you add plugins
Code:
[Plugins]
Plugin=MyPlugin
Plugin=SomeOtherPlugin
Plugin=DontKnowThisPlugin

To work around the issue of adding the same thing multiple times, you need to erase the old version first.

Of course this is kinda crappy, and it should be fixed in a proper way. I do want the 'array' functionality though.
Reply
Thanks given by:
#5
I'd say this is convoluted. We need to jump through hoops for the expected behavior.

How about this subtle change:
- GetValue() reads the first value of the specified name
- SetValue() overwrites the first value of the specified name; creates if not found
- EnumValues() reads all the values of the specified name
- AddValue() adds a possibly duplicate name=value pair

This would make all intentions in the code clear - you'd know if the code expects to work with duplicates or not. Also all of this could be exported to plugins and this API is much cleaner, imho.
Reply
Thanks given by:
#6
SureTongue
Reply
Thanks given by:
#7
Is the plugin list the only place that uses duplicates, or is there anywhere else I need to watch out?
Reply
Thanks given by:
#8
I think some ( of my) plugins use it, but don't worry about that
Reply
Thanks given by:
#9
I have another change proposal:
GetValueSet() will work the same as GetValue(), but it will write the default value to the Ini file if it's not already there. This way we can read the parameters and ensure that they are being present in the file for the user to change, should they want to.
Reply
Thanks given by:
#10
GetValueSet() was too good a thing not to implement it, so now it's implemented. It's even exported to Lua Smile
Reply
Thanks given by:




Users browsing this thread: 5 Guest(s)