From f4ec60064cf9f4d59c8f270adfac1386c6a548ec Mon Sep 17 00:00:00 2001 From: Metious <71298690+Metious@users.noreply.github.com> Date: Tue, 14 Nov 2023 21:05:47 +0330 Subject: [PATCH] fix: Safety measures for localization registration (#496) Added safety checks for localization registration --- Nautilus/Handlers/LanguageHandler.cs | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/Nautilus/Handlers/LanguageHandler.cs b/Nautilus/Handlers/LanguageHandler.cs index 2f8fc85d..ef75ff58 100644 --- a/Nautilus/Handlers/LanguageHandler.cs +++ b/Nautilus/Handlers/LanguageHandler.cs @@ -45,7 +45,22 @@ public static void RegisterLocalizationFolder(string languageFolderName = "Local foreach (var file in Directory.GetFiles(path)) { - var content = JsonConvert.DeserializeObject>(File.ReadAllText(file)); + if (Path.GetExtension(file) != ".json") + { + continue; + } + + // I hate this + Dictionary content = null; + try + { + content = JsonConvert.DeserializeObject>(File.ReadAllText(file)); + } + catch (Exception e) + { + InternalLogger.Error($"Exception caught while trying to deserialize localization file at path: '{file}'. Exception: {e}"); + } + if (content is null) { InternalLogger.Warn($"Localization file '{file}' is empty, skipping registration.");