patch
This commit is contained in:
@@ -4,7 +4,6 @@ using System.IO;
|
|||||||
using System.Text.Json;
|
using System.Text.Json;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Collections.ObjectModel;
|
|
||||||
using System.Threading;
|
using System.Threading;
|
||||||
|
|
||||||
namespace PluginManager
|
namespace PluginManager
|
||||||
|
|||||||
@@ -1,17 +0,0 @@
|
|||||||
using PluginManager.Online.Helpers;
|
|
||||||
|
|
||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Text;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
|
|
||||||
namespace PluginManager.Interfaces
|
|
||||||
{
|
|
||||||
public interface AppExtension
|
|
||||||
{
|
|
||||||
public string Name { get; }
|
|
||||||
public VersionString Version { get; }
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,20 +1,21 @@
|
|||||||
using System;
|
using Discord.WebSocket;
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Diagnostics;
|
|
||||||
using System.IO;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Net.Http;
|
|
||||||
using System.Reflection;
|
|
||||||
using System.Threading;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
|
|
||||||
using Discord.WebSocket;
|
|
||||||
|
|
||||||
using PluginManager.Interfaces;
|
using PluginManager.Interfaces;
|
||||||
using PluginManager.Loaders;
|
using PluginManager.Loaders;
|
||||||
using PluginManager.Online;
|
using PluginManager.Online;
|
||||||
using PluginManager.Online.Helpers;
|
using PluginManager.Online.Helpers;
|
||||||
using PluginManager.Others;
|
using PluginManager.Others;
|
||||||
|
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Diagnostics;
|
||||||
|
using System.IO;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Net.Http;
|
||||||
|
using System.Reflection;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
|
||||||
namespace PluginManager.Items;
|
namespace PluginManager.Items;
|
||||||
|
|
||||||
public class ConsoleCommandsHandler
|
public class ConsoleCommandsHandler
|
||||||
@@ -129,6 +130,7 @@ public class ConsoleCommandsHandler
|
|||||||
|
|
||||||
AddCommand("dwplug", "download plugin", "dwplug [name]", async args =>
|
AddCommand("dwplug", "download plugin", "dwplug [name]", async args =>
|
||||||
{
|
{
|
||||||
|
|
||||||
isDownloading = true;
|
isDownloading = true;
|
||||||
if (args.Length == 1)
|
if (args.Length == 1)
|
||||||
{
|
{
|
||||||
@@ -222,7 +224,7 @@ public class ConsoleCommandsHandler
|
|||||||
|
|
||||||
Console.WriteLine();
|
Console.WriteLine();
|
||||||
}
|
}
|
||||||
VersionString? ver = await VersionString.GetVersionOfPackageFromWeb(name);
|
VersionString? ver = await Online.ServerCom.GetVersionOfPackageFromWeb(name);
|
||||||
if (ver is null) throw new Exception("Incorrect version");
|
if (ver is null) throw new Exception("Incorrect version");
|
||||||
Config.SetPluginVersion(name, $"{ver.PackageVersionID}.{ver.PackageMainVersion}.{ver.PackageCheckVersion}");
|
Config.SetPluginVersion(name, $"{ver.PackageVersionID}.{ver.PackageMainVersion}.{ver.PackageCheckVersion}");
|
||||||
|
|
||||||
@@ -297,29 +299,38 @@ public class ConsoleCommandsHandler
|
|||||||
AddCommand("import", "Load an external command", "import [pluginName]", async (args) =>
|
AddCommand("import", "Load an external command", "import [pluginName]", async (args) =>
|
||||||
{
|
{
|
||||||
if (args.Length <= 1) return;
|
if (args.Length <= 1) return;
|
||||||
string pName = Functions.MergeStrings(args, 1);
|
try
|
||||||
HttpClient client = new HttpClient();
|
|
||||||
string url = (await manager.GetPluginLinkByName(pName))[1];
|
|
||||||
Stream s = await client.GetStreamAsync(url);
|
|
||||||
MemoryStream str = new MemoryStream();
|
|
||||||
await s.CopyToAsync(str);
|
|
||||||
var asmb = Assembly.Load(str.ToArray());
|
|
||||||
|
|
||||||
var types = asmb.GetTypes();
|
|
||||||
foreach (var type in types)
|
|
||||||
{
|
{
|
||||||
if (type.IsClass && typeof(DBEvent).IsAssignableFrom(type))
|
string pName = Functions.MergeStrings(args, 1);
|
||||||
|
HttpClient client = new HttpClient();
|
||||||
|
string url = (await manager.GetPluginLinkByName(pName))[1];
|
||||||
|
if (url is null) throw new Exception($"Invalid plugin name {pName}.");
|
||||||
|
Stream s = await client.GetStreamAsync(url);
|
||||||
|
MemoryStream str = new MemoryStream();
|
||||||
|
await s.CopyToAsync(str);
|
||||||
|
var asmb = Assembly.Load(str.ToArray());
|
||||||
|
|
||||||
|
var types = asmb.GetTypes();
|
||||||
|
foreach (var type in types)
|
||||||
{
|
{
|
||||||
DBEvent instance = (DBEvent)Activator.CreateInstance(type);
|
if (type.IsClass && typeof(DBEvent).IsAssignableFrom(type))
|
||||||
instance.Start(this.client);
|
{
|
||||||
Console.WriteLine($"Loaded external {type.FullName}!");
|
DBEvent instance = (DBEvent)Activator.CreateInstance(type);
|
||||||
}
|
instance.Start(this.client);
|
||||||
else if (type.IsClass && typeof(DBCommand).IsAssignableFrom(type))
|
Console.WriteLine($"[EVENT] Loaded external {type.FullName}!");
|
||||||
{
|
}
|
||||||
Console.WriteLine("Only events can be loaded from external sources !");
|
else if (type.IsClass && typeof(DBCommand).IsAssignableFrom(type))
|
||||||
return;
|
{
|
||||||
|
DBCommand instance = (DBCommand)Activator.CreateInstance(type);
|
||||||
|
Console.WriteLine($"[CMD] Instance: {type.FullName} loaded !");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
Console.WriteLine(ex.Message);
|
||||||
|
}
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
AddCommand("remplug", "Remove a plugin", "remplug [plugName]", async args =>
|
AddCommand("remplug", "Remove a plugin", "remplug [plugName]", async args =>
|
||||||
|
|||||||
@@ -69,7 +69,7 @@ public class PluginLoader
|
|||||||
{
|
{
|
||||||
string name = new FileInfo(file).Name.Split('.')[0];
|
string name = new FileInfo(file).Name.Split('.')[0];
|
||||||
if (!Config.PluginVersionsContainsKey(name))
|
if (!Config.PluginVersionsContainsKey(name))
|
||||||
Config.SetPluginVersion(name, (await VersionString.GetVersionOfPackageFromWeb(name))?.PackageVersionID + ".0.0");
|
Config.SetPluginVersion(name, (await Online.ServerCom.GetVersionOfPackageFromWeb(name))?.PackageVersionID + ".0.0");
|
||||||
|
|
||||||
if (await PluginUpdater.CheckForUpdates(name))
|
if (await PluginUpdater.CheckForUpdates(name))
|
||||||
await PluginUpdater.Download(name);
|
await PluginUpdater.Download(name);
|
||||||
@@ -84,7 +84,7 @@ public class PluginLoader
|
|||||||
{
|
{
|
||||||
string name = new FileInfo(file).Name.Split('.')[0];
|
string name = new FileInfo(file).Name.Split('.')[0];
|
||||||
if (!Config.PluginVersionsContainsKey(name))
|
if (!Config.PluginVersionsContainsKey(name))
|
||||||
Config.SetPluginVersion(name, (await VersionString.GetVersionOfPackageFromWeb(name))?.PackageVersionID + ".0.0");
|
Config.SetPluginVersion(name, (await Online.ServerCom.GetVersionOfPackageFromWeb(name))?.PackageVersionID + ".0.0");
|
||||||
|
|
||||||
if (await PluginUpdater.CheckForUpdates(name))
|
if (await PluginUpdater.CheckForUpdates(name))
|
||||||
await PluginUpdater.Download(name);
|
await PluginUpdater.Download(name);
|
||||||
|
|||||||
@@ -69,23 +69,5 @@ namespace PluginManager.Online.Helpers
|
|||||||
return $"{PackageVersionID}.{PackageMainVersion}.{PackageCheckVersion}";
|
return $"{PackageVersionID}.{PackageMainVersion}.{PackageCheckVersion}";
|
||||||
}
|
}
|
||||||
|
|
||||||
public static VersionString? GetVersionOfPackage(string pakName)
|
|
||||||
{
|
|
||||||
if (!Config.PluginVersionsContainsKey(pakName))
|
|
||||||
return null;
|
|
||||||
return new VersionString(Config.GetPluginVersion(pakName));
|
|
||||||
}
|
|
||||||
|
|
||||||
public static async Task<VersionString?> GetVersionOfPackageFromWeb(string pakName)
|
|
||||||
{
|
|
||||||
string url = "https://raw.githubusercontent.com/Wizzy69/installer/discord-bot-files/Versions";
|
|
||||||
List<string> data = await ServerCom.ReadTextFromURL(url);
|
|
||||||
string? version = (from item in data
|
|
||||||
where !item.StartsWith("#") && item.StartsWith(pakName)
|
|
||||||
select item.Split(',')[1]).FirstOrDefault();
|
|
||||||
if (version == default || version == null) return null;
|
|
||||||
return new VersionString(version);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -57,7 +57,7 @@ public class PluginsManager
|
|||||||
display[0] = content[0];
|
display[0] = content[0];
|
||||||
display[1] = content[1];
|
display[1] = content[1];
|
||||||
display[2] = content[2];
|
display[2] = content[2];
|
||||||
display[3] = (await VersionString.GetVersionOfPackageFromWeb(content[0]) ?? new VersionString("0.0.0")).ToShortString();
|
display[3] = (await Online.ServerCom.GetVersionOfPackageFromWeb(content[0]) ?? new VersionString("0.0.0")).ToShortString();
|
||||||
if (Config.PluginConfig.Contains(content[0]) || Config.PluginConfig.Contains(content[0]))
|
if (Config.PluginConfig.Contains(content[0]) || Config.PluginConfig.Contains(content[0]))
|
||||||
display[4] = "✓";
|
display[4] = "✓";
|
||||||
else
|
else
|
||||||
@@ -72,7 +72,7 @@ public class PluginsManager
|
|||||||
display[0] = content[0];
|
display[0] = content[0];
|
||||||
display[1] = content[1];
|
display[1] = content[1];
|
||||||
display[2] = content[2];
|
display[2] = content[2];
|
||||||
display[3] = (await VersionString.GetVersionOfPackageFromWeb(content[0]) ?? new VersionString("0.0.0")).ToShortString();
|
display[3] = (await Online.ServerCom.GetVersionOfPackageFromWeb(content[0]) ?? new VersionString("0.0.0")).ToShortString();
|
||||||
if (Config.PluginConfig.Contains(content[0]) || Config.PluginConfig.Contains(content[0]))
|
if (Config.PluginConfig.Contains(content[0]) || Config.PluginConfig.Contains(content[0]))
|
||||||
display[4] = "✓";
|
display[4] = "✓";
|
||||||
else
|
else
|
||||||
|
|||||||
@@ -85,5 +85,23 @@ namespace PluginManager.Online
|
|||||||
await DownloadFileAsync(URL, location, progress);
|
await DownloadFileAsync(URL, location, progress);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static VersionString? GetVersionOfPackage(string pakName)
|
||||||
|
{
|
||||||
|
if (!Config.PluginVersionsContainsKey(pakName))
|
||||||
|
return null;
|
||||||
|
return new VersionString(Config.GetPluginVersion(pakName));
|
||||||
|
}
|
||||||
|
|
||||||
|
public static async Task<VersionString?> GetVersionOfPackageFromWeb(string pakName)
|
||||||
|
{
|
||||||
|
string url = "https://raw.githubusercontent.com/Wizzy69/installer/discord-bot-files/Versions";
|
||||||
|
List<string> data = await ServerCom.ReadTextFromURL(url);
|
||||||
|
string? version = (from item in data
|
||||||
|
where !item.StartsWith("#") && item.StartsWith(pakName)
|
||||||
|
select item.Split(',')[1]).FirstOrDefault();
|
||||||
|
if (version == default || version == null) return null;
|
||||||
|
return new VersionString(version);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -14,8 +14,8 @@ namespace PluginManager.Online.Updates
|
|||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
var webV = await VersionString.GetVersionOfPackageFromWeb(pakName);
|
var webV = await Online.ServerCom.GetVersionOfPackageFromWeb(pakName);
|
||||||
var local = VersionString.GetVersionOfPackage(pakName);
|
var local = Online.ServerCom.GetVersionOfPackage(pakName);
|
||||||
|
|
||||||
if (local is null) return true;
|
if (local is null) return true;
|
||||||
if (webV is null) return false;
|
if (webV is null) return false;
|
||||||
@@ -33,7 +33,7 @@ namespace PluginManager.Online.Updates
|
|||||||
{
|
{
|
||||||
string url = "https://raw.githubusercontent.com/Wizzy69/installer/discord-bot-files/Versions";
|
string url = "https://raw.githubusercontent.com/Wizzy69/installer/discord-bot-files/Versions";
|
||||||
List<string> info = await ServerCom.ReadTextFromURL(url);
|
List<string> info = await ServerCom.ReadTextFromURL(url);
|
||||||
VersionString? version = await VersionString.GetVersionOfPackageFromWeb(pakName);
|
VersionString? version = await Online.ServerCom.GetVersionOfPackageFromWeb(pakName);
|
||||||
|
|
||||||
if (version is null) return Update.Empty;
|
if (version is null) return Update.Empty;
|
||||||
Update update = new Update(pakName, string.Join('\n', info), version);
|
Update update = new Update(pakName, string.Join('\n', info), version);
|
||||||
@@ -42,7 +42,7 @@ namespace PluginManager.Online.Updates
|
|||||||
|
|
||||||
public static async Task Download(string pakName)
|
public static async Task Download(string pakName)
|
||||||
{
|
{
|
||||||
Console_Utilities.WriteColorText("An update was found for &g" + pakName + "&c. Version: &r" + (await VersionString.GetVersionOfPackageFromWeb(pakName))?.ToShortString() + "&c. Current Version: &y" + VersionString.GetVersionOfPackage(pakName)?.ToShortString());
|
Console_Utilities.WriteColorText("An update was found for &g" + pakName + "&c. Version: &r" + (await Online.ServerCom.GetVersionOfPackageFromWeb(pakName))?.ToShortString() + "&c. Current Version: &y" + Online.ServerCom.GetVersionOfPackage(pakName)?.ToShortString());
|
||||||
await ConsoleCommandsHandler.ExecuteCommad("dwplug " + pakName);
|
await ConsoleCommandsHandler.ExecuteCommad("dwplug " + pakName);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user