Blish-HUD icon indicating copy to clipboard operation
Blish-HUD copied to clipboard

Losing settings periodically

Open sheklesworth opened this issue 1 year ago • 2 comments

Once/week or so I'm losing my settings in Blish-HUD. Everything. API keys, module configuration, etc.. Based on this log entry, I'm guessing that the previous settings file did not save correctly, or was not done before Blish-HUD exited.

18:12:22.3016 | INFO  | Blish_HUD.Program | Launched from "C:\Games\Guild Wars 2\Blish.HUD" with args "".
18:12:22.3111 | WARN  | Blish_HUD.Program | Blish HUD is already running!
18:12:23.3276 | WARN  | Blish_HUD.SettingsService | Failed to load settings due to an unexpected exception while attempting to read them. A new settings file will be generated.
Newtonsoft.Json.JsonReaderException: Unexpected end of content while loading JObject. Path 'Entries[4].Value.Entries[0].Value['bh.community.pathing'].Settings.Entries[0].Value.Entries', line 131, position 12.
   at Newtonsoft.Json.Linq.JContainer.ReadTokenFrom(JsonReader reader, JsonLoadSettings options)
   at Newtonsoft.Json.Linq.JObject.Load(JsonReader reader, JsonLoadSettings settings)
   at Blish_HUD.Settings.SettingCollection.SettingCollectionConverter.ReadJson(JsonReader reader, Type objectType, SettingCollection existingValue, Boolean hasExistingValue, JsonSerializer serializer) in D:\a\Blish-HUD\Blish-HUD\Blish HUD\GameServices\Settings\SettingCollection.cs:line 60
   at Newtonsoft.Json.JsonConverter`1.ReadJson(JsonReader reader, Type objectType, Object existingValue, JsonSerializer serializer)
   at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.DeserializeConvertable(JsonConverter converter, JsonReader reader, Type objectType, Object existingValue)
   at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.Deserialize(JsonReader reader, Type objectType, Boolean checkAdditionalContent)
   at Newtonsoft.Json.JsonSerializer.DeserializeInternal(JsonReader reader, Type objectType)
   at Newtonsoft.Json.JsonConvert.DeserializeObject(String value, Type type, JsonSerializerSettings settings)
   at Newtonsoft.Json.JsonConvert.DeserializeObject[T](String value, JsonSerializerSettings settings)
   at Blish_HUD.SettingsService.LoadSettings(Boolean alreadyFailed) in D:\a\Blish-HUD\Blish-HUD\Blish HUD\GameServices\SettingsService.cs:line 60

I have a guess for what might be happening: I use Gw2Launcher and tell it to terminate Blish-HUD when I exit GW2. Normally, it's fine, but occasionally, I'm assuming it gets killed before it can finish writing the settings.

It would probably be useful to have Blish-HUD save a backup of the existing settings.json before writing a new version, and attempt to recover from a backup if the current version is corrupted.

Edit: Looking at PerformSave, it appears there already is a temp file being created, but it's moved over the top of settings.json before backing up the existing settings first. I think renaming settings.json to a backup file first would probably take care of the issue.

sheklesworth avatar Jul 25 '22 02:07 sheklesworth

You are correct about the cause of the issue. This is why we ask you to configure Blish HUD to close itself in our multibox guide: https://blishhud.com/docs/user/multibox-support#3-configure-blish-hud-to-close-itself

Regarding the code you just reviewed, that code isn't in 0.11.7 (the current release) and is in fact the solution to this issue. It will be available in the next release. The file isn't moved over until it is fully written so there's no chance of a partial write getting placed on top of the existing settings file, so no need to rename the existing settings first.

dlamkins avatar Jul 25 '22 05:07 dlamkins

Thanks for the info. If you want it, I also created a branch off dev that creates a settings backup file on save, and attempts to use it if the main settings file cannot be loaded for some reason. I tried to create a PR, but I didn't have permissions.

sheklesworth avatar Jul 25 '22 06:07 sheklesworth

@sheklesworth Did you create a fork?

BillChirico avatar Sep 01 '22 16:09 BillChirico

I left a note about this here for now: https://github.com/blish-hud/Blish-HUD/discussions/733

I think I'm happy with our current implementation coming in the next release, so I'll go ahead and close. 👍

dlamkins avatar Sep 01 '22 20:09 dlamkins