Cuberite Forum
Proposing a cIniFile change - Printable Version

+- Cuberite Forum (https://forum.cuberite.org)
+-- Forum: Cuberite (https://forum.cuberite.org/forum-4.html)
+--- Forum: Development (https://forum.cuberite.org/forum-13.html)
+--- Thread: Proposing a cIniFile change (/thread-427.html)

Pages: 1 2


Proposing a cIniFile change - xoft - 04-21-2012

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.


RE: Proposing a cIniFile change - FakeTruth - 04-21-2012

Objection!

I'll write out why later :p


RE: Proposing a cIniFile change - xoft - 04-21-2012

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


RE: Proposing a cIniFile change - FakeTruth - 04-21-2012

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.


RE: Proposing a cIniFile change - xoft - 04-22-2012

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.


RE: Proposing a cIniFile change - FakeTruth - 04-23-2012

SureTongue


RE: Proposing a cIniFile change - xoft - 04-23-2012

Is the plugin list the only place that uses duplicates, or is there anywhere else I need to watch out?


RE: Proposing a cIniFile change - FakeTruth - 04-23-2012

I think some ( of my) plugins use it, but don't worry about that


RE: Proposing a cIniFile change - xoft - 06-10-2012

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.


RE: Proposing a cIniFile change - xoft - 06-10-2012

GetValueSet() was too good a thing not to implement it, so now it's implemented. It's even exported to Lua Smile