Cuberite Forum
Cannot modify .ini file - Printable Version

+- Cuberite Forum (https://forum.cuberite.org)
+-- Forum: Plugins (https://forum.cuberite.org/forum-1.html)
+--- Forum: Plugin Discussion (https://forum.cuberite.org/forum-8.html)
+--- Thread: Cannot modify .ini file (/thread-2090.html)



Cannot modify .ini file - KaRoLak - 08-26-2015

Hi!
I wanted to have a .ini file that will controll my fraction-like plugin
but i cant add a new key to the ini file, while my code seems ok.
I can read a value from a key, but cannot add a key or value.
Actual code is:
Code:
local IniFile = cIniFile();
if (IniFile:ReadFile("fractionlist.ini")) then
    key= IniFile:AddKeyName("hi")
    IniFile:AddValue(IniFile:GetKeyName(key), "Value1", "32")
end



RE: Cannot modify .ini file - NiLSPACE - 08-26-2015

Hello and welcome to the forum Smile

You forgot to write the file back to the HDD.

It should look something like this when complete:
local IniFile = cIniFile()
if (IniFile:ReadFile("fractionlist.ini")) then
   IniFile:AddKeyName("hi")
   IniFile:AddValue("hi", "Value1", "32")
   IniFile:WriteFile("fractionlist.ini")
end

As you see you also don't have to use the key ID. You can just use the keyname directly.


RE: Cannot modify .ini file - xoft - 08-27-2015

Please do not to use .ini files for data storage:
- they are slow, and they get slower when more data is written to them
- they are not safe. If the server crashes while operating on the file, the file will be corrupt and data recovery is nearly impossible

Use the SQLite database instead. It's fast, it's safe and it is exactly meant for this kind of data. If you need an example of how to work with SQLite databases from a Cuberite plugin, have a look at some of these:
- Gallery plugin: https://github.com/cuberite/gallery (the entire gallery information is stored in a DB, see Storage_SQLite.lua for the access layer)
- Core plugin: https://github.com/mc-server/Core (the banlist and whitelist are using SQLite DBs)
- Aliases plugin: https://github.com/madmaxoft/Aliases (the aliases are stored in a SQLite DB)
- LastSeen plugin: https://github.com/madmaxoft/LastSeen (the last seen timestamp and player preferences are stored in a SQLite DB)