timvisee / lazymc

💤 Put your Minecraft server to rest when idle.
GNU General Public License v3.0
573 stars 15 forks source link

rewriting old config instead of overwriting it #14

Open ventoryprod opened 2 years ago

ventoryprod commented 2 years ago

Hi, Updates come out relatively often, and these updates introduce config changes, which is why the old config is completely overwritten.

Of course, updates and changes are not so big that you would make it possible to automatically update configs when changing version instead of overwriting, you can completely refuse my offer, but personally it makes me a little tired to enter the old settings every time when updating.

timvisee commented 2 years ago

Such feature would be awesome.

I'm not sure how to implement that though. The current system for handling the TOML file (through toml) does support rewriting the file, but it would remove all added comments.

ventoryprod commented 2 years ago

Such feature would be awesome.

I'm not sure how to implement that though. The current system for handling the TOML file (through toml) does support rewriting the file, but it would remove all added comments.

I do not know how this can be implemented, but if I suddenly come up with something, I will write it here.

ventoryprod commented 2 years ago

Nah, I still have no clue how that can be done. It can definitely be implemented, but I don't know how for now.

megabyte6 commented 2 years ago

I haven't looked at the toml crate yet so I'm not sure how it works. I am not well versed in rust so take what I say with a grain of salt.

I was wondering if it would be possible to look at the current lazymc.toml file and filter out anything that isn't commented. Then find the names of the values on the left of the "=" and use those values to search for in the same value in the new lazymc.toml file. From that point, you could replace everything on the right side of the "=" with the value in the old lazymc.toml file.

And for the searching, go line by line and ignore the first character and see if the following characters match what your search is. If you keep the names the same across different versions of lazymc, then everything will work out. But even if you use different names for variables, you could just add the remaining items (the items that were searched but weren't found) in the old lazymc.toml file at the bottom of the new lazymc.toml file.

If this program ignores the values that aren't used, then this will work. I know this isn't a very elegant solution but it should work. But again, I do not know how the toml crate works or lazymc so take my ideas with a grain of salt.

obj-obj commented 1 year ago

Maybe we could use https://lib.rs/crates/toml_edit?