From 12587e222fc4a82ff4e1efea1cf206e76c22c26c Mon Sep 17 00:00:00 2001 From: Serge <5920850+seerge@users.noreply.github.com> Date: Thu, 15 Aug 2024 11:03:54 +0200 Subject: [PATCH] Backup config reading https://github.com/seerge/g-helper/issues/2978 --- app/AppConfig.cs | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/app/AppConfig.cs b/app/AppConfig.cs index fcd9f167..265ab0cd 100644 --- a/app/AppConfig.cs +++ b/app/AppConfig.cs @@ -41,10 +41,19 @@ public static class AppConfig { config = JsonSerializer.Deserialize>(text); } - catch + catch (Exception ex) { - Logger.WriteLine("Broken config: " + text); - Init(); + Logger.WriteLine($"Broken config: {ex.Message} {text}"); + try + { + text = File.ReadAllText(configFile + ".bak"); + config = JsonSerializer.Deserialize>(text); + } + catch (Exception exb) + { + Logger.WriteLine($"Broken backup config: {exb.Message} {text}"); + Init(); + } } } else