From 71fd96126b6d85704a21c434a7906b539e832ceb Mon Sep 17 00:00:00 2001 From: JungleDruid <3953982+JungleDruid@users.noreply.github.com> Date: Tue, 27 Feb 2024 11:59:58 +0800 Subject: [PATCH] Add detailed error logging --- BG3LocalizationMerger.csproj | 2 +- Dialog.cs | 4 +- HandleExtractor.cs | 205 +++++++++++++++++-------- MainWindow.xaml | 2 +- MainWindow.xaml.cs | 49 +++++- PackageManager.cs | 178 +++++++++++++-------- Resources/Strings/Strings.Designer.cs | 9 ++ Resources/Strings/Strings.resx | 3 + Resources/Strings/Strings.zh-Hant.resx | 3 + 9 files changed, 318 insertions(+), 137 deletions(-) diff --git a/BG3LocalizationMerger.csproj b/BG3LocalizationMerger.csproj index 6de1476..e1f7f28 100644 --- a/BG3LocalizationMerger.csproj +++ b/BG3LocalizationMerger.csproj @@ -8,7 +8,7 @@ true x64 en - $(VersionPrefix)1.0.4 + $(VersionPrefix)1.1.0 False diff --git a/Dialog.cs b/Dialog.cs index e7a231a..4494d10 100644 --- a/Dialog.cs +++ b/Dialog.cs @@ -113,8 +113,8 @@ ref childrenCount } } - Children = childrenCount == 0 ? Array.Empty() : children[..childrenCount]; - Texts = textsCount == 0 ? Array.Empty() : texts[..textsCount]; + Children = childrenCount == 0 ? [] : children[..childrenCount]; + Texts = textsCount == 0 ? [] : texts[..textsCount]; Debug.Assert(!string.IsNullOrWhiteSpace(Id)); shared.Return(children); shared.Return(texts); diff --git a/HandleExtractor.cs b/HandleExtractor.cs index 63a83a2..e381f5f 100644 --- a/HandleExtractor.cs +++ b/HandleExtractor.cs @@ -1,4 +1,5 @@ -using System.Collections.Generic; +using System; +using System.Collections.Generic; using System.IO; using System.Linq; using System.Text.RegularExpressions; @@ -48,95 +49,175 @@ internal static partial class HandleExtractor )] private static partial Regex TooltipFilter(); - public static IEnumerable ExtractCharacterHandles(string path) + public static IEnumerable? ExtractCharacterHandles(string path) { - var text = ReadText(path); - if (!TemplateCharacterFilter().IsMatch(text)) - return Enumerable.Empty(); - return ExtractHandles(text, CharacterHandles()); + try + { + var text = ReadText(path); + if (!TemplateCharacterFilter().IsMatch(text)) + return Enumerable.Empty(); + return ExtractHandles(text, CharacterHandles()); + } + catch (Exception e) + { + MainWindow.LogFileError(path, e); + return null; + } } - public static IEnumerable ExtractWaypointHandles(string path) + public static IEnumerable? ExtractWaypointHandles(string path) { - return ExtractGenericHandles(path); + try + { + return ExtractGenericHandles(path); + } + catch (Exception e) + { + MainWindow.LogFileError(path, e); + return null; + } } - public static IEnumerable ExtractQuestMarkerHandles(string path) + public static IEnumerable? ExtractQuestMarkerHandles(string path) { - return ExtractGenericHandles(path); + try + { + return ExtractGenericHandles(path); + } + catch (Exception e) + { + MainWindow.LogFileError(path, e); + return null; + } } - public static IEnumerable ExtractBookHandles(string path) + public static IEnumerable? ExtractBookHandles(string path) { - return ExtractGenericHandles(path); + try + { + return ExtractGenericHandles(path); + } + catch (Exception e) + { + MainWindow.LogFileError(path, e); + return null; + } } - public static (IEnumerable, IEnumerable) ExtractQuestHandles(string path) + public static (IEnumerable, IEnumerable)? ExtractQuestHandles(string path) { - string text = ReadText(path); - MatchCollection matches = QuestHandle().Matches(text); - var group = matches.GroupBy(x => x.Groups["Type"].Value); - return ( - group - .FirstOrDefault(x => x.Key == "QuestTitle") - ?.SelectMany(x => x.Groups.Values.Skip(1)) - .Select(x => x.Value) ?? Enumerable.Empty(), - group - .Where(x => x.Key.EndsWith("Description")) - .SelectMany(x => x) - ?.SelectMany(x => x.Groups.Values.Skip(1)) - .Select(x => x.Value) ?? Enumerable.Empty() - ); + try + { + string text = ReadText(path); + MatchCollection matches = QuestHandle().Matches(text); + var group = matches.GroupBy(x => x.Groups["Type"].Value); + return ( + group + .FirstOrDefault(x => x.Key == "QuestTitle") + ?.SelectMany(x => x.Groups.Values.Skip(1)) + .Select(x => x.Value) ?? Enumerable.Empty(), + group + .Where(x => x.Key.EndsWith("Description")) + .SelectMany(x => x) + ?.SelectMany(x => x.Groups.Values.Skip(1)) + .Select(x => x.Value) ?? Enumerable.Empty() + ); + } + catch (Exception e) + { + MainWindow.LogFileError(path, e); + return null; + } } - public static (IEnumerable, IEnumerable) ExtractStatusHandles(string path) + public static (IEnumerable, IEnumerable)? ExtractStatusHandles(string path) { - string text = ReadText(path); - MatchCollection matches = StatusHandle().Matches(text); - var group = matches.GroupBy(x => x.Groups["Type"].Value); - return ( - group - .FirstOrDefault(x => x.Key == "DisplayName") - ?.SelectMany(x => x.Groups.Values.Skip(1)) - .Select(x => x.Value) ?? Enumerable.Empty(), - group - .Where(x => x.Key.EndsWith("Description")) - .SelectMany(x => x) - ?.SelectMany(x => x.Groups.Values.Skip(1)) - .Select(x => x.Value) ?? Enumerable.Empty() - ); + try + { + string text = ReadText(path); + MatchCollection matches = StatusHandle().Matches(text); + var group = matches.GroupBy(x => x.Groups["Type"].Value); + return ( + group + .FirstOrDefault(x => x.Key == "DisplayName") + ?.SelectMany(x => x.Groups.Values.Skip(1)) + .Select(x => x.Value) ?? Enumerable.Empty(), + group + .Where(x => x.Key.EndsWith("Description")) + .SelectMany(x => x) + ?.SelectMany(x => x.Groups.Values.Skip(1)) + .Select(x => x.Value) ?? Enumerable.Empty() + ); + } + catch (Exception e) + { + MainWindow.LogFileError(path, e); + return null; + } } - public static IEnumerable ExtractItemGroup(string path) + public static IEnumerable? ExtractItemGroup(string path) { - string text = ReadText(path); - if (!TemplateItemFilter().IsMatch(text)) - return Enumerable.Empty(); - MatchCollection matches = TemplateHandles().Matches(text); - return matches - .SelectMany(x => x.Groups.Values.Skip(1)) - .Where(x => !string.IsNullOrEmpty(x.Value)); + try + { + string text = ReadText(path); + if (!TemplateItemFilter().IsMatch(text)) + return Enumerable.Empty(); + MatchCollection matches = TemplateHandles().Matches(text); + return matches + .SelectMany(x => x.Groups.Values.Skip(1)) + .Where(x => !string.IsNullOrEmpty(x.Value)); + } + catch (Exception e) + { + MainWindow.LogFileError(path, e); + return null; + } } - public static IEnumerable ExtractTooltipHandles(string path) + public static IEnumerable? ExtractTooltipHandles(string path) { - string text = ReadText(path); - MatchCollection matches = GenericHandle().Matches(text); - return matches - .Where(x => TooltipFilter().IsMatch(x.Groups[0].Value)) - .SelectMany(x => x.Groups.Values.Skip(1)) - .Select(x => x.Value) - .Where(x => !string.IsNullOrEmpty(x)); + try + { + string text = ReadText(path); + MatchCollection matches = GenericHandle().Matches(text); + return matches + .Where(x => TooltipFilter().IsMatch(x.Groups[0].Value)) + .SelectMany(x => x.Groups.Values.Skip(1)) + .Select(x => x.Value) + .Where(x => !string.IsNullOrEmpty(x)); + } + catch (Exception e) + { + MainWindow.LogFileError(path, e); + return null; + } } - public static IEnumerable ExtractHintHandles(string path) + public static IEnumerable? ExtractHintHandles(string path) { - return ExtractGenericHandles(path); + try + { + return ExtractGenericHandles(path); + } + catch (Exception e) + { + MainWindow.LogFileError(path, e); + return null; + } } - public static IEnumerable ExtractGenericHandles(string path) + public static IEnumerable? ExtractGenericHandles(string path) { - return ExtractHandles(ReadText(path), GenericHandle()); + try + { + return ExtractHandles(ReadText(path), GenericHandle()); + } + catch (Exception e) + { + MainWindow.LogFileError(path, e); + return null; + } } private static string ReadText(string path) diff --git a/MainWindow.xaml b/MainWindow.xaml index 67209a0..ed929de 100644 --- a/MainWindow.xaml +++ b/MainWindow.xaml @@ -43,7 +43,7 @@ - +