From 83583ecb8e4aea48cb5b75d657dd38ae4b83933b Mon Sep 17 00:00:00 2001 From: CreepyCrafter24 <33260128+CreepyCrafter24@users.noreply.github.com> Date: Fri, 20 Dec 2019 16:24:55 +0100 Subject: [PATCH] Maybe improved updates --- README.md | 4 +++- UpTool2/Program.cs | 38 ++++++++++++++++++++++---------------- 2 files changed, 25 insertions(+), 17 deletions(-) diff --git a/README.md b/README.md index 52d731f..9ad6093 100644 --- a/README.md +++ b/README.md @@ -6,4 +6,6 @@ Downloading software from online repos since 2019 ![GitHub repo size](https://img.shields.io/github/repo-size/JFronny/UpTool2) ![GitHub All Releases](https://img.shields.io/github/downloads/JFronny/UpTool2/total) -![Discord](https://img.shields.io/discord/466965965658128384) \ No newline at end of file +![Discord](https://img.shields.io/discord/466965965658128384) + +Default Repo: https://gist.github.com/JFronny/f1ccbba3d8a2f5862592bb29fdb612c4 \ No newline at end of file diff --git a/UpTool2/Program.cs b/UpTool2/Program.cs index c7f9a8e..3711b73 100644 --- a/UpTool2/Program.cs +++ b/UpTool2/Program.cs @@ -119,7 +119,7 @@ namespace UpTool2 splash.BringToFront(); } - static void FixXML(string xml) + static void FixXML(string xml, bool throwOnError = false) { try { @@ -129,28 +129,34 @@ namespace UpTool2 { XDocument x = XDocument.Load(xml); XElement meta = x.Element("meta"); - if (XDocument.Load(xml).Element("meta").Element("UpdateSource") == null - || XDocument.Load(xml).Element("meta").Element("UpdateSource").Value == null - || XDocument.Load(xml).Element("meta").Element("UpdateSource").Value == "https://raw.githubusercontent.com/CreepyCrafter24/UpTool2/master/Meta.xml") - meta.Add(new XElement("UpdateSource", "https://raw.githubusercontent.com/JFronny/UpTool2/master/Meta.xml")); - if (XDocument.Load(xml).Element("meta").Element("Repos") == null - || XDocument.Load(xml).Element("meta").Element("Repos").Value == null - || XDocument.Load(xml).Element("meta").Element("Repos").Value == "https://github.com/CreepyCrafter24/UpTool2/releases/download/Repo/Repo.xml") - meta.Add(new XElement("Repos", new XElement("Repo", new XElement("Name", "UpTool2 official Repo"), new XElement("Link", "https://raw.githubusercontent.com/JFronny/UpTool2/master/Repo.xml")))); - else if (XDocument.Load(xml).Element("meta").Element("Repos").Elements("Repo").Count() == 0) + if (meta.Element("UpdateSource") == null) + meta.Add(new XElement("UpdateSource")); + if (new string[] { null, "https://raw.githubusercontent.com/CreepyCrafter24/UpTool2/master/Meta.xml", + "https://raw.githubusercontent.com/JFronny/UpTool2/master/Meta.xml" } + .Contains(meta.Element("UpdateSource").Value)) + meta.Element("UpdateSource").Value = "https://gist.githubusercontent.com/JFronny/f1ccbba3d8a2f5862592bb29fdb612c4/raw/Meta.xml"; + if (meta.Element("Repos") == null) + meta.Add(new XElement("Repos")); + if (meta.Element("Repos").Elements("Repo").Count() == 0) meta.Element("Repos").Add(new XElement("Repo", new XElement("Name", "UpTool2 official Repo"), new XElement("Link", "https://raw.githubusercontent.com/JFronny/UpTool2/master/Repo.xml"))); - else - meta.Element("Repos").Elements("Repo").Select(s => s.Element("Link")) - .Where(s => s.Value == "https://github.com/JFronny/UpTool2/releases/download/Repo/Repo.xml") - .ToList().ForEach(s => s.Value = "https://raw.githubusercontent.com/JFronny/UpTool2/master/Repo.xml"); - if (XDocument.Load(xml).Element("meta").Element("LocalRepo") == null) + meta.Element("Repos").Elements("Repo").Select(s => s.Element("Link")) + .Where(s => new string[] { null, "https://github.com/JFronny/UpTool2/releases/download/Repo/Repo.xml", + "https://raw.githubusercontent.com/JFronny/UpTool2/master/Repo.xml"}.Contains(s.Value)) + .ToList().ForEach(s => s.Value = "https://gist.githubusercontent.com/JFronny/f1ccbba3d8a2f5862592bb29fdb612c4/raw/Repo.xml"); + if (meta.Element("LocalRepo") == null) meta.Add(new XElement("LocalRepo")); x.Save(xml); } } catch (XmlException) { - new XElement("meta", new XElement("Repos", new XElement("Repo", new XElement("Name", "UpTool2 official Repo"), new XElement("Link", "https://raw.githubusercontent.com/JFronny/UpTool2/master/Repo.xml"))), new XElement("LocalRepo")).Save(xml); + if (throwOnError) + throw; + else + { + File.Delete(xml); + FixXML(xml); + } } }