From 721de97cc1d69cf9bf0cf64adcd1204e243786f6 Mon Sep 17 00:00:00 2001 From: Kilian von Pflugk Date: Sun, 20 Oct 2024 00:03:59 +0200 Subject: [PATCH] migrate old plugin config --- IntroSkipper/Plugin.cs | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/IntroSkipper/Plugin.cs b/IntroSkipper/Plugin.cs index c258b0b..f58e388 100644 --- a/IntroSkipper/Plugin.cs +++ b/IntroSkipper/Plugin.cs @@ -4,6 +4,8 @@ using System.Collections.Generic; using System.IO; using System.Linq; using System.Text.RegularExpressions; +using System.Xml; +using System.Xml.Serialization; using IntroSkipper.Configuration; using IntroSkipper.Data; using IntroSkipper.Helper; @@ -89,6 +91,36 @@ public class Plugin : BasePlugin, IHasWebPages MigrateRepoUrl(serverConfiguration); + var oldConfigFile = Path.Join(applicationPaths.PluginConfigurationsPath, "ConfusedPolarBear.Plugin.IntroSkipper.xml"); + + if (File.Exists(oldConfigFile)) + { + try + { + XmlSerializer serializer = new XmlSerializer(typeof(PluginConfiguration)); + using (FileStream fileStream = new FileStream(oldConfigFile, FileMode.Open)) + { + var settings = new XmlReaderSettings + { + DtdProcessing = DtdProcessing.Prohibit, // Disable DTD processing + XmlResolver = null // Disable the XmlResolver + }; + + using (var reader = XmlReader.Create(fileStream, settings)) + { + var oldConfig = serializer.Deserialize(reader) as PluginConfiguration; + Instance.UpdateConfiguration(oldConfig); + File.Delete(oldConfigFile); + } + } + } + catch (Exception ex) + { + // Handle exceptions, such as file not found, deserialization errors, etc. + _logger.LogWarning("Something stupid happend: {Exception}", ex); + } + } + // TODO: remove when https://github.com/jellyfin/jellyfin-meta/discussions/30 is complete try {