TBMM/GCMM/MainModder.cs
NorbiPeti c709304daf Split into multiple files
Using a single partial class because why not
2020-06-16 19:22:29 +02:00

61 lines
2.1 KiB
C#

using GCMM.Properties;
using Newtonsoft.Json.Linq;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace GCMM
{
partial class MainForm
{
public void GetInstalledMods()
{
foreach (var mod in Directory.GetFiles(Settings.Default.GamePath + @"\Plugins", "*.dll"))
{
try
{
var an = AssemblyName.GetAssemblyName(mod);
if (an.Name == "0Harmony") continue;
var item = new ListViewItem(new[] { an.Name, "", an.Version.ToString(), File.GetLastWriteTime(mod).ToString() }, modlist.Groups["installed"]);
item.Name = an.Name;
modlist.Items.Add(item);
}
catch (BadImageFormatException)
{ //Not a .NET assembly
}
}
}
public async void GetAvailableMods()
{
string reposURL = "/api/v1/repos/search?sort=updated&order=desc";
using (var client = GetClient())
{
var obj = JObject.Parse(await client.DownloadStringTaskAsync(reposURL));
if (!(bool)obj["ok"]) return;
foreach (var repo in obj["data"])
{
string name = repo["name"].ToString();
if (modlist.Items.ContainsKey(name))
{
var item = modlist.Items[name];
var si = item.SubItems;
si[1] = new ListViewItem.ListViewSubItem(item, repo["owner"]["username"].ToString());
}
else
{
var item = new ListViewItem(new[] { name, repo["owner"]["username"].ToString(), "", ((DateTime)repo["updated_at"]).ToString() }, modlist.Groups["available"]);
item.Name = name;
modlist.Items.Add(item);
}
}
}
}
}
}