Forgero - [Fabric]

Forgero - [Fabric]

85k Downloads

Automatic updating of config if an outdated config schema is detected

Steveplays28 opened this issue ยท 4 comments

commented

Ideally this system wouldn't overwrite an existing config. Sounds very doable to me.

Implementation details

Load config using ForgeroConfigurationLoader.load() as normal, but add a step that checks if the mod version has changed compared to the config's mod version (would be a separate field in the config that shouldn't be touched, add a comment if possible). This step would then save the config using the loaded config again.
The fields missing in the config file would be automatically set to the default, since ForgeroConfigurationLoader.save() just writes the fields in ForgeroConfiguration to the config file, technically overwriting the entire config but keeping the (potentially changed) values it's already loaded.

commented

Yeah, that's almost exactly what I proposed

commented

Yup, it works like a charm. You're making it too easy here

commented

I believe this can be done by simply saving the config after loading it. It's a little redundant to save it every time it is loaded, but it makes sure everything is up to date and valid

commented

Haha, glad to hear.