70 lines
3.2 KiB
C#
70 lines
3.2 KiB
C#
using System.IO;
|
|
using System.Linq;
|
|
using System.Xml.Linq;
|
|
using UpToolLib.DataStructures;
|
|
|
|
namespace UpToolLib.v1.Tool
|
|
{
|
|
public class XmlTool
|
|
{
|
|
private readonly IExternalFunctionality _platform;
|
|
private readonly PathTool _pathTool;
|
|
|
|
internal XmlTool(IExternalFunctionality platform, PathTool pathTool)
|
|
{
|
|
_platform = platform;
|
|
_pathTool = pathTool;
|
|
}
|
|
|
|
public void FixXml()
|
|
{
|
|
if (!Directory.Exists(_pathTool.AppsPath))
|
|
Directory.CreateDirectory(_pathTool.AppsPath);
|
|
if (!File.Exists(_pathTool.InfoXml) || XDocument.Load(_pathTool.InfoXml).Element("meta") == null)
|
|
new XElement("meta").Save(_pathTool.InfoXml);
|
|
XDocument x = XDocument.Load(_pathTool.InfoXml);
|
|
XElement meta = x.Element("meta");
|
|
if (meta.Element("UpdateSource") == null)
|
|
meta.Add(new XElement("UpdateSource"));
|
|
if (new[]
|
|
{
|
|
"",
|
|
"https://raw.githubusercontent.com/CreepyCrafter24/UpTool2/master/Meta.xml",
|
|
"https://raw.githubusercontent.com/JFronny/UpTool2/master/Meta.xml",
|
|
"https://gist.githubusercontent.com/JFronny/f1ccbba3d8a2f5862592bb29fdb612c4/raw/Meta.xml",
|
|
"https://github.com/JFronny/UpTool2/releases/latest/download/meta.xml",
|
|
"https://gitlab.com/JFronny/UpTool2/-/jobs/artifacts/master/raw/meta.xml?job=uptool"
|
|
}
|
|
.Contains(meta.Element("UpdateSource").Value))
|
|
meta.Element("UpdateSource").Value =
|
|
"https://gitlab.com/uptool/UpTool2/-/jobs/artifacts/master/raw/meta.xml?job=uptool";
|
|
if (meta.Element("Repos") == null)
|
|
meta.Add(new XElement("Repos"));
|
|
if (meta.Element("Repos").Elements("Repo").Count() == 0)
|
|
{
|
|
if (_platform.YesNoDialog(
|
|
"No active repository was detected. Add the default repo?", false))
|
|
{
|
|
meta.Element("Repos").Add(new XElement("Repo", new XElement("Name", "UpTool2 official Repo"),
|
|
new XElement("Link",
|
|
"https://gitlab.com/uptool/UpTool2/-/snippets/1988600/raw/master/Repo.xml")));
|
|
}
|
|
}
|
|
meta.Element("Repos").Elements("Repo").Select(s => s.Element("Link"))
|
|
.Where(s => new[]
|
|
{
|
|
null, "https://github.com/JFronny/UpTool2/releases/download/Repo/Repo.xml",
|
|
"https://raw.githubusercontent.com/JFronny/UpTool2/master/Repo.xml",
|
|
"https://gist.githubusercontent.com/JFronny/f1ccbba3d8a2f5862592bb29fdb612c4/raw/Repo.xml",
|
|
"https://gitlab.com/JFronny/UpTool2/snippets/1988600/raw"
|
|
}.Contains(s.Value))
|
|
.ToList().ForEach(s =>
|
|
s.Value =
|
|
"https://gitlab.com/uptool/UpTool2/-/snippets/1988600/raw/master/Repo.xml");
|
|
if (meta.Element("LocalRepo") == null)
|
|
meta.Add(new XElement("LocalRepo"));
|
|
x.Save(_pathTool.InfoXml);
|
|
}
|
|
}
|
|
}
|