This repository has been archived on 2022-08-05. You can view files and clone it, but cannot push or open issues or pull requests.
UpTool2/UpTool2/SourcesForm.cs

51 lines
1.8 KiB
C#
Raw Normal View History

2019-10-21 15:18:08 +02:00
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Xml.Linq;
namespace UpTool2
{
public partial class SettingsForms : Form
{
string dir => Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + @"\UpTool2";
string xml => dir + @"\info.xml";
XDocument doc;
XElement meta;
XElement repos;
public SettingsForms()
{
InitializeComponent();
doc = XDocument.Load(xml);
meta = doc.Element("meta");
if (meta.Element("Repos") == null)
meta.Add(new XElement("Repos"));
if (meta.Element("Repos").Elements("Repo").Count() == 0)
2019-12-11 16:00:14 +01:00
meta.Element("Repos").Add(new XElement("Repo", new XElement("Name", "UpTool2 official Repo"), new XElement("Link", "https://github.com/JFronny/UpTool2/releases/download/Repo/Repo.xml")));
2019-10-21 15:18:08 +02:00
repos = meta.Element("Repos");
foreach (XElement repo in repos.Elements("Repo"))
{
sourceGrid.Rows.Add(repo.Element("Name").Value, repo.Element("Link").Value);
}
}
private void SettingsForms_FormClosing(object sender, FormClosingEventArgs e)
{
repos.RemoveNodes();
for (int y = 0; y < sourceGrid.Rows.Count; y++)
{
if (y + 1 < sourceGrid.Rows.Count)
{
repos.Add(new XElement("Repo", new XElement("Name", (string)sourceGrid.Rows[y].Cells[0].Value), new XElement("Link", (string)sourceGrid.Rows[y].Cells[1].Value)));
}
}
doc.Save(xml);
}
}
}