From 9974e840bbe6d82799d70fa6364b84ba84940796 Mon Sep 17 00:00:00 2001 From: Kilian von Pflugk Date: Sun, 26 May 2024 13:09:15 +0200 Subject: [PATCH] delete broken xml files There is no other way to recover from this state. If the cache still exists, rebuilding the files shouldn't take long. --- .../XmlSerializationHelper.cs | 37 ++++++++++++------- 1 file changed, 23 insertions(+), 14 deletions(-) diff --git a/ConfusedPolarBear.Plugin.IntroSkipper/XmlSerializationHelper.cs b/ConfusedPolarBear.Plugin.IntroSkipper/XmlSerializationHelper.cs index ee6d958..e0bcc72 100644 --- a/ConfusedPolarBear.Plugin.IntroSkipper/XmlSerializationHelper.cs +++ b/ConfusedPolarBear.Plugin.IntroSkipper/XmlSerializationHelper.cs @@ -53,22 +53,31 @@ namespace ConfusedPolarBear.Plugin.IntroSkipper { if (File.Exists(filePath)) { - // Load the XML document - XmlDocument xmlDoc = new XmlDocument(); - xmlDoc.Load(filePath); - - ArgumentNullException.ThrowIfNull(xmlDoc.DocumentElement); - - // check that the file has not already been migrated - if (xmlDoc.DocumentElement.HasAttribute("xmlns:xsi")) + try { - xmlDoc.DocumentElement.RemoveAttribute("xmlns:xsi"); - xmlDoc.DocumentElement.RemoveAttribute("xmlns:xsd"); - xmlDoc.DocumentElement.SetAttribute("xmlns", "http://schemas.datacontract.org/2004/07/ConfusedPolarBear.Plugin.IntroSkipper"); - xmlDoc.DocumentElement.SetAttribute("xmlns:i", "http://www.w3.org/2001/XMLSchema-instance"); + // Load the XML document + XmlDocument xmlDoc = new XmlDocument(); + xmlDoc.Load(filePath); - // Save the modified XML document - xmlDoc.Save(filePath); + ArgumentNullException.ThrowIfNull(xmlDoc.DocumentElement); + + // Check that the file has not already been migrated + if (xmlDoc.DocumentElement.HasAttribute("xmlns:xsi")) + { + xmlDoc.DocumentElement.RemoveAttribute("xmlns:xsi"); + xmlDoc.DocumentElement.RemoveAttribute("xmlns:xsd"); + xmlDoc.DocumentElement.SetAttribute("xmlns", "http://schemas.datacontract.org/2004/07/ConfusedPolarBear.Plugin.IntroSkipper"); + xmlDoc.DocumentElement.SetAttribute("xmlns:i", "http://www.w3.org/2001/XMLSchema-instance"); + + // Save the modified XML document + xmlDoc.Save(filePath); + } + } + catch (XmlException ex) + { + Console.WriteLine($"Error deserializing XML: {ex.Message}"); + File.Delete(filePath); + Console.WriteLine($"Deleting {filePath}"); } } }