Youda008 / DoomRunner

Preset-oriented graphical launcher of various ported Doom engines (an alternative to ZDL)
GNU General Public License v3.0
204 stars 13 forks source link

[Feature] Settings backup #95

Closed proydoha closed 11 months ago

proydoha commented 1 year ago

When power outage happens there is a surprisingly high chance of losing an options.json file. Happened to me 4 times in last 6 months.

If possible it would be great if DoomRunner would automatically produce couple of backups that will be automatically loaded if main options.json is lost/unreadable/unparseable.

Youda008 commented 1 year ago

Now this is a complete mystery to me.

The current file saving mechanism is designed to prevent exatly this case. How it works now is it

  1. renames the existing file to .old,
  2. creates a new file with the original name
  3. writes the new state to the new file
  4. only if the writing was successful, deletes the old file

All of this happens once per 60 seconds and on all modern computers it shouldn't take more than few milliseconds.

In other words, the chance that you hit that small millisecond window in a minute is extremely small and even if you do, there should always be a readable backup named options.json.old. If it doesn't, i have no idea what the hell is happening there.

Other programs also don't store backup files of their configs, there must be something else going on. May i ask what's your operating system and drive?

proydoha commented 1 year ago

Windows 10, some Toshiba HDD. DT01ACA200 says device manager.

Can something go wrong in save/loading logic? For example maybe it reads malformed options.json, discards it and recreates options.json while ignoring options.old.json?

Youda008 commented 1 year ago

Maybe, but you would get a warning message at the next start saying that the file is corrupted. Anyway, when this happens next time, please look into the DoomRunner's folder before you start it, and send me the files that were there after the crash. In the meantime, i will write code that will look for that .old backup and automatically load that instead, if the original file cannot be read.

Youda008 commented 1 year ago

I released a version with yet another slightly reworked file saving mechanism. Please keep trying and report back if it happens again.

Youda008 commented 11 months ago

I have reduced the frequency of writing to file, by making it write the content only when something has changed. Hopefully that will solve your issue.