Page 1 of 1
Auto-Updating Config Files (Bukkit - YML)
Posted: Mon May 14, 2012 2:10 pm
by offluffy
So this isn't so much something I can't do, but wondering if there's a better way to do it. The only way I've been able to auto-update config files is by creating temp variables for every option in the config, overwriting the old config, then replacing the old variables into the new config and setting the rest to default values. This seems a little complicated because I have to keep going back to the function that updates the config and altering it to accommodate new variables, which I think in doing so may cause the console to spit out errors trying to find variables that aren't in certain version of the file. I also tried a semi-automatic way of doing it, by extracting the entire config into a ConfigurationSection, overwriting the config with the new one, then setting the ConfigurationSection back, but this didn't work much at all, albeit I can't recall exactly why not. Is there a better way to have the plugin update the config file yet preserve variables that are already set? May also need to do this with more than just the config since I have another file that was completely restructured to merge 2 or 3 files together. Thanks in advance!
Re: Auto-Updating Config Files (Bukkit - YML)
Posted: Mon May 14, 2012 7:00 pm
by jacek
Are we talking about updating across plugin version changes ? If so I think it's generally accepted that people just manually delete their config file and have to edit it again. Realistically how often do you need to change the format of the file ?
Re: Auto-Updating Config Files (Bukkit - YML)
Posted: Mon May 14, 2012 10:53 pm
by offluffy
Well, considering this plugin is still fairly new and I keep coming up with new features, I end up restructuring files or adding options to the config, and since the config has options with lists of stuff, and I thought it'd be convenient to have the plugin do the updating automatically. Especially when it comes to the bans file. I would rather have the plugin migrate the lists to the new structuring automatically because I know if it doesn't I'll get spammed on the dev page about how the plugin messed up because people are generally too lazy to read the instructions XD
Re: Auto-Updating Config Files (Bukkit - YML)
Posted: Mon May 14, 2012 11:37 pm
by jacek
Well there is not really a way around it as far as I can tell. You do just have to take the old values and put them with the new keys.
I normally have a finalised config file before release though so it might be worth trying to come up a with a format that can easily be extended if needed.
Re: Auto-Updating Config Files (Bukkit - YML)
Posted: Tue May 15, 2012 1:20 am
by offluffy
Ahhh, alrighty, thanks anyways! XD I'm very persistent >.> I'll prolly keep trying various methods.
Re: Auto-Updating Config Files (Bukkit - YML)
Posted: Tue May 15, 2012 10:18 pm
by jacek
If you come up with a neat way let me know