From a9bf6464213a7cf2e22d693c5e51a6fa882f6a75 Mon Sep 17 00:00:00 2001 From: rlauuzo <46294892+rlauuzo@users.noreply.github.com> Date: Sat, 20 Apr 2024 16:21:20 +0200 Subject: [PATCH] No more wasteful XML writes update only the XML file corresponding to the analyzed mode --- .../Plugin.cs | 48 ++++++++++++++++++- 1 file changed, 47 insertions(+), 1 deletion(-) diff --git a/ConfusedPolarBear.Plugin.IntroSkipper/Plugin.cs b/ConfusedPolarBear.Plugin.IntroSkipper/Plugin.cs index 142e171..a67c813 100644 --- a/ConfusedPolarBear.Plugin.IntroSkipper/Plugin.cs +++ b/ConfusedPolarBear.Plugin.IntroSkipper/Plugin.cs @@ -226,6 +226,52 @@ public class Plugin : BasePlugin, IHasWebPages } } + /// + /// Save timestamps to disk. + /// + /// Mode. + public void SaveTimestamps(AnalysisMode mode) + { + lock (_serializationLock) + { + var introList = new List(); + + // Serialize intros + if (mode == AnalysisMode.Introduction) + { + foreach (var intro in Instance!.Intros) + { + introList.Add(intro.Value); + } + + try + { + XmlSerializationHelper.SerializeToXml(introList, _introPath); + } + catch (Exception e) + { + _logger.LogError("SaveTimestamps intros {Message}", e.Message); + } + } + else if (mode == AnalysisMode.Credits) + { + foreach (var intro in Instance.Credits) + { + introList.Add(intro.Value); + } + + try + { + XmlSerializationHelper.SerializeToXml(introList, _creditsPath); + } + catch (Exception e) + { + _logger.LogError("SaveTimestamps credits {Message}", e.Message); + } + } + } + } + /// /// Restore previous analysis results from disk. /// @@ -346,7 +392,7 @@ public class Plugin : BasePlugin, IHasWebPages } } - Instance!.SaveTimestamps(); + Instance!.SaveTimestamps(mode); } }