diff --git a/BUILDS/net6.0/PluginManager.dll b/BUILDS/net6.0/PluginManager.dll index b035aeb..030162f 100644 Binary files a/BUILDS/net6.0/PluginManager.dll and b/BUILDS/net6.0/PluginManager.dll differ diff --git a/BUILDS/net6.0/Plugins/Commands/CMD_LevelingSystem.dll b/BUILDS/net6.0/Plugins/Commands/CMD_LevelingSystem.dll index 665a62d..711b0d5 100644 Binary files a/BUILDS/net6.0/Plugins/Commands/CMD_LevelingSystem.dll and b/BUILDS/net6.0/Plugins/Commands/CMD_LevelingSystem.dll differ diff --git a/BUILDS/net6.0/Plugins/Commands/CMD_Utils.dll b/BUILDS/net6.0/Plugins/Commands/CMD_Utils.dll index d30bcd7..d0b729a 100644 Binary files a/BUILDS/net6.0/Plugins/Commands/CMD_Utils.dll and b/BUILDS/net6.0/Plugins/Commands/CMD_Utils.dll differ diff --git a/BUILDS/net6.0/Plugins/Commands/Music Commands.dll b/BUILDS/net6.0/Plugins/Commands/Music Commands.dll index 509f1db..2341731 100644 Binary files a/BUILDS/net6.0/Plugins/Commands/Music Commands.dll and b/BUILDS/net6.0/Plugins/Commands/Music Commands.dll differ diff --git a/BUILDS/net6.0/Plugins/Commands/Roles.dll b/BUILDS/net6.0/Plugins/Commands/Roles.dll new file mode 100644 index 0000000..d278f8c Binary files /dev/null and b/BUILDS/net6.0/Plugins/Commands/Roles.dll differ diff --git a/BUILDS/net6.0/Plugins/Events/EVE_LevelingSystem.dll b/BUILDS/net6.0/Plugins/Events/EVE_LevelingSystem.dll index 0a08495..8d1dbfc 100644 Binary files a/BUILDS/net6.0/Plugins/Events/EVE_LevelingSystem.dll and b/BUILDS/net6.0/Plugins/Events/EVE_LevelingSystem.dll differ diff --git a/DiscordBot/Program.cs b/DiscordBot/Program.cs index 7a72639..cc19549 100644 --- a/DiscordBot/Program.cs +++ b/DiscordBot/Program.cs @@ -7,8 +7,11 @@ using System.Reflection; using System.Runtime.Loader; using System.Threading; using System.Threading.Tasks; + using Discord.WebSocket; + using DiscordBot.Discord.Core; + using PluginManager; using PluginManager.Interfaces; using PluginManager.Items; @@ -29,6 +32,7 @@ public class Program [Obsolete] public static void Main(string[] args) { + Directory.CreateDirectory("./Data/Resources"); Directory.CreateDirectory("./Data/Plugins/Commands"); Directory.CreateDirectory("./Data/Plugins/Events"); @@ -42,7 +46,7 @@ public class Program Console.WriteLine("Please enter the server ID: "); Console_Utilities.WriteColorText("You can find it in the Server Settings at &r\"Widget\"&c section"); Console.WriteLine("Example: 1234567890123456789"); - + Console.WriteLine("This is not required, but is recommended. If you refuse to provide the ID, just press enter.\nThe server id is required to make easier for the bot to interact with the server.\nRemember: this bot is for one server ONLY."); Console.Write("User Input > "); ConsoleKeyInfo key = Console.ReadKey(); @@ -57,15 +61,15 @@ public class Program continue; } - + Config.AddValueToVariables("ServerID", SID, false); - + } break; } while (true); } - + if (!Config.ContainsKey("token") || Config.GetValue("token") == null || Config.GetValue("token")?.Length != 70) { Console.WriteLine("Please insert your token"); @@ -121,12 +125,12 @@ public class Program Console.ForegroundColor = ConsoleColor.White; #if DEBUG - Console_Utilities.WriteColorText("&rSethBot (&yDEBUG&r) &c> ", false); + //Console_Utilities.WriteColorText("&rSethBot (&yDEBUG&r) &c> ", false); var cmd = Console.ReadLine(); if (!consoleCommandsHandler.HandleCommand(cmd!, false) && cmd.Length > 0) Console.WriteLine("Failed to run command " + cmd); #else - Console_Utilities.WriteColorText("&rSethBot &c> ", false); + //Console_Utilities.WriteColorText("&rSethBot &c> ", false); var cmd = Console.ReadLine(); if (!consoleCommandsHandler.HandleCommand(cmd!) && cmd.Length > 0) Console.WriteLine("Failed to run command " + cmd); @@ -189,7 +193,7 @@ public class Program /// Directory path private static Task ClearFolder(string d) { - var files = Directory.GetFiles(d); + var files = Directory.GetFiles(d); var fileNumb = files.Length; for (var i = 0; i < fileNumb; i++) { @@ -210,7 +214,7 @@ public class Program if (len == 3 && args[0] == "/download") { - var url = args[1]; + var url = args[1]; var location = args[2]; await ServerCom.DownloadFileAsync(url, location); @@ -231,7 +235,7 @@ public class Program if (len == 0 || (args[0] != "--exec" && args[0] != "--execute")) { - var b = await StartNoGUI(); + var b = await StartNoGUI(); Thread mainThread = new Thread(() => NoGUI(b)); mainThread.Start(); diff --git a/DiscordBotConsoleLauncher/DiscordBotConsoleLauncher.csproj b/DiscordBotConsoleLauncher/DiscordBotConsoleLauncher.csproj new file mode 100644 index 0000000..396c1aa --- /dev/null +++ b/DiscordBotConsoleLauncher/DiscordBotConsoleLauncher.csproj @@ -0,0 +1,14 @@ + + + + Exe + net6.0 + enable + enable + + + + + + + diff --git a/DiscordBotConsoleLauncher/Program.cs b/DiscordBotConsoleLauncher/Program.cs new file mode 100644 index 0000000..47b010d --- /dev/null +++ b/DiscordBotConsoleLauncher/Program.cs @@ -0,0 +1,21 @@ +using PluginManager.Online.Updates; + +try +{ + bool requireUpdate = await PluginUpdater.CheckForUpdates("DiscordBotConsoleLauncher"); + if (requireUpdate) + { + var update = await PluginUpdater.DownloadUpdateInfo("DiscordBotConsoleLauncher"); + if (update == Update.Empty) + return; + + Console.WriteLine("Found an update: "); + Console.WriteLine(update.ToString()); + } +} +catch (Exception ex) +{ + Console.WriteLine("An exception was thrown. "); + Console.WriteLine(ex.Message); + Environment.Exit(-2); +} \ No newline at end of file diff --git a/PluginManager/Config.cs b/PluginManager/Config.cs index 644b085..1e135ab 100644 --- a/PluginManager/Config.cs +++ b/PluginManager/Config.cs @@ -12,7 +12,9 @@ namespace PluginManager internal class AppConfig { public Dictionary? ApplicationVariables { get; init; } - public List? ProtectedKeyWords { get; init; } + public List? ProtectedKeyWords { get; init; } + + public Dictionary PluginVersions { get; init; } } public static class Config @@ -29,27 +31,27 @@ namespace PluginManager private static void LoadCommands() { - string cmd_path = "./Data/Plugins/Commands/"; - string[] files = Directory.GetFiles(cmd_path, $"*.{Loaders.PluginLoader.pluginCMDExtension}", SearchOption.AllDirectories); + string cmd_path = "./Data/Plugins/Commands/"; + string[] files = Directory.GetFiles(cmd_path, $"*.{Loaders.PluginLoader.pluginCMDExtension}", SearchOption.AllDirectories); foreach (var file in files) if (!file.Contains("PluginManager", StringComparison.InvariantCultureIgnoreCase)) { string PluginName = new FileInfo(file).Name; - string name = PluginName.Substring(0, PluginName.Length - 1 - PluginManager.Loaders.PluginLoader.pluginCMDExtension.Length); + string name = PluginName.Substring(0, PluginName.Length - 1 - PluginManager.Loaders.PluginLoader.pluginCMDExtension.Length); InstalledPlugins.Add(new(name, PluginType.Command)); } } private static void LoadEvents() { - string eve_path = "./Data/Plugins/Events/"; - string[] files = Directory.GetFiles(eve_path, $"*.{Loaders.PluginLoader.pluginEVEExtension}", SearchOption.AllDirectories); + string eve_path = "./Data/Plugins/Events/"; + string[] files = Directory.GetFiles(eve_path, $"*.{Loaders.PluginLoader.pluginEVEExtension}", SearchOption.AllDirectories); foreach (var file in files) if (!file.Contains("PluginManager", StringComparison.InvariantCultureIgnoreCase)) if (!file.Contains("PluginManager", StringComparison.InvariantCultureIgnoreCase)) { string PluginName = new FileInfo(file).Name; - string name = PluginName.Substring(0, PluginName.Length - 1 - PluginManager.Loaders.PluginLoader.pluginEVEExtension.Length); + string name = PluginName.Substring(0, PluginName.Length - 1 - PluginManager.Loaders.PluginLoader.pluginEVEExtension.Length); InstalledPlugins.Add(new(name, PluginType.Event)); } } @@ -77,6 +79,19 @@ namespace PluginManager private static AppConfig? appConfig { get; set; } + public static string GetPluginVersion(string pluginName) => appConfig.PluginVersions[pluginName]; + public static void SetPluginVersion(string pluginName, string newVersion) + { + if (appConfig.PluginVersions.ContainsKey(pluginName)) + appConfig.PluginVersions[pluginName] = newVersion; + else appConfig.PluginVersions.Add(pluginName, newVersion); + + SaveConfig(); + } + + public static void RemovePluginVersion(string pluginName) => appConfig.PluginVersions.Remove(pluginName); + public static bool PluginVersionsContainsKey(string pluginName) => appConfig.PluginVersions.ContainsKey(pluginName); + public static void AddValueToVariables(string key, T value, bool isProtected) { if (value == null) @@ -183,11 +198,11 @@ namespace PluginManager Functions.WriteLogFile($"Loaded {appConfig.ApplicationVariables!.Keys.Count} application variables.\nLoaded {appConfig.ProtectedKeyWords!.Count} readonly variables."); } else - appConfig = new() { ApplicationVariables = new Dictionary(), ProtectedKeyWords = new List() }; + appConfig = new() { ApplicationVariables = new Dictionary(), ProtectedKeyWords = new List(), PluginVersions = new Dictionary() }; } public static bool ContainsValue(T value) => appConfig!.ApplicationVariables!.ContainsValue(value!); - public static bool ContainsKey(string key) => appConfig!.ApplicationVariables!.ContainsKey(key); + public static bool ContainsKey(string key) => appConfig!.ApplicationVariables!.ContainsKey(key); public static ReadOnlyDictionary GetAllVariables() => new(appConfig!.ApplicationVariables!); } diff --git a/PluginManager/Items/ConsoleCommandsHandler.cs b/PluginManager/Items/ConsoleCommandsHandler.cs index bf08bae..d549ed8 100644 --- a/PluginManager/Items/ConsoleCommandsHandler.cs +++ b/PluginManager/Items/ConsoleCommandsHandler.cs @@ -4,18 +4,26 @@ using System.IO; using System.Linq; using System.Threading; using System.Threading.Tasks; + using Discord.WebSocket; + using PluginManager.Loaders; using PluginManager.Online; +using PluginManager.Online.Helpers; +using PluginManager.Online.Updates; using PluginManager.Others; namespace PluginManager.Items; public class ConsoleCommandsHandler { - private static readonly PluginsManager manager = new("https://raw.githubusercontent.com/Wizzy69/installer/discord-bot-files/Plugins.txt"); + private static readonly PluginsManager manager = new("https://raw.githubusercontent.com/Wizzy69/installer/discord-bot-files/Plugins.txt"); private static readonly List commandList = new(); - private readonly DiscordSocketClient? client; + private readonly DiscordSocketClient? client; + + + private static bool isDownloading = false; + private static bool pluginsLoaded = false; public ConsoleCommandsHandler(DiscordSocketClient client) { @@ -26,7 +34,7 @@ public class ConsoleCommandsHandler private void InitializeBasicCommands() { - var pluginsLoaded = false; + commandList.Clear(); AddCommand("help", "Show help", "help ", args => @@ -101,8 +109,10 @@ public class ConsoleCommandsHandler AddCommand("dwplug", "download plugin", "dwplug [name]", async args => { + isDownloading = true; if (args.Length == 1) { + isDownloading = false; Console.WriteLine("Please specify plugin name"); return; } @@ -116,10 +126,11 @@ public class ConsoleCommandsHandler { if (name == "") { + isDownloading = false; Console_Utilities.WriteColorText("Name is invalid"); return; } - + isDownloading = false; Console_Utilities.WriteColorText($"Failed to find plugin &b{name} &c!" + " Use &glistplugs &ccommand to display all available plugins !"); return; } @@ -160,9 +171,9 @@ public class ConsoleCommandsHandler if (split[0].EndsWith(".zip") || split[0].EndsWith(".pak") || split[0].EndsWith(".pkg")) { Console.WriteLine($"Extracting {split[1]}"); - var proc = 0f; + var proc = 0f; var isExtracting = true; - var bar = new Console_Utilities.ProgressBar { Max = 100f, Color = ConsoleColor.Green }; + var bar = new Console_Utilities.ProgressBar { Max = 100f, Color = ConsoleColor.Green }; IProgress extractProgress = new Progress(value => { proc = value; }); new Thread(new Task(() => @@ -189,6 +200,12 @@ public class ConsoleCommandsHandler Console.WriteLine(); } + VersionString? ver = await VersionString.GetVersionOfPackageFromWeb(name); + if (ver is null) throw new Exception("Incorrect version"); + Config.SetPluginVersion(name, $"{ver.PackageID}.{ver.PackageMainVersion}.{ver.PackageCheckVersion}"); + // Console.WriteLine(); + + isDownloading = false; } ); @@ -209,8 +226,8 @@ public class ConsoleCommandsHandler { if (args.Length < 4) return; - var key = args[1]; - var value = args[2]; + var key = args[1]; + var value = args[2]; var isReadOnly = args[3].Equals("true", StringComparison.CurrentCultureIgnoreCase); try @@ -276,6 +293,20 @@ public class ConsoleCommandsHandler return commandList.FirstOrDefault(t => t.CommandName == command); } + internal static async Task ExecuteCommad(string command) + { + var args = command.Split(' '); + foreach (var item in commandList.ToList()) + if (item.CommandName == args[0]) + { + item.Action.Invoke(args); + Console.WriteLine(); + + while (isDownloading) await Task.Delay(1000); + + } + } + public bool HandleCommand(string command, bool removeCommandExecution = true) { var args = command.Split(' '); @@ -292,6 +323,7 @@ public class ConsoleCommandsHandler Console.WriteLine(); item.Action(args); + return true; } diff --git a/PluginManager/Loaders/Loader.cs b/PluginManager/Loaders/Loader.cs index 82aac6f..d5e10da 100644 --- a/PluginManager/Loaders/Loader.cs +++ b/PluginManager/Loaders/Loader.cs @@ -3,29 +3,32 @@ using System.Collections.Generic; using System.IO; using System.Linq; using System.Reflection; +using System.Threading.Tasks; + +using PluginManager.Online.Updates; using PluginManager.Others; namespace PluginManager.Loaders; internal class LoaderArgs : EventArgs { - internal string? PluginName { get; init; } - internal string? TypeName { get; init; } - internal bool IsLoaded { get; init; } - internal Exception? Exception { get; init; } - internal object? Plugin { get; init; } + internal string? PluginName { get; init; } + internal string? TypeName { get; init; } + internal bool IsLoaded { get; init; } + internal Exception? Exception { get; init; } + internal object? Plugin { get; init; } } internal class Loader { internal Loader(string path, string extension) { - this.path = path; + this.path = path; this.extension = extension; } - private string path { get; } + private string path { get; } private string extension { get; } @@ -49,16 +52,17 @@ internal class Loader var files = Directory.GetFiles(path, $"*.{extension}", SearchOption.AllDirectories); foreach (var file in files) { + Assembly.LoadFrom(file); if (FileLoaded != null) { var args = new LoaderArgs { - Exception = null, - TypeName = nameof(T), - IsLoaded = false, - PluginName = file, - Plugin = null + Exception = null, + TypeName = nameof(T), + IsLoaded = false, + PluginName = new FileInfo(file).Name.Split('.')[0], + Plugin = null }; FileLoaded.Invoke(args); } @@ -83,13 +87,13 @@ internal class Loader if (PluginLoaded != null) PluginLoaded.Invoke(new LoaderArgs - { - Exception = null, - IsLoaded = true, - PluginName = type.FullName, - TypeName = nameof(T), - Plugin = plugin - } + { + Exception = null, + IsLoaded = true, + PluginName = type.FullName, + TypeName = nameof(T), + Plugin = plugin + } ); } catch (Exception ex) diff --git a/PluginManager/Loaders/PluginLoader.cs b/PluginManager/Loaders/PluginLoader.cs index c506eaf..f35daf1 100644 --- a/PluginManager/Loaders/PluginLoader.cs +++ b/PluginManager/Loaders/PluginLoader.cs @@ -1,7 +1,14 @@ using System; using System.Collections.Generic; +using System.IO; +using System.Runtime.CompilerServices; +using System.Threading; +using System.Threading.Tasks; + using Discord.WebSocket; + using PluginManager.Interfaces; +using PluginManager.Online.Updates; using PluginManager.Others; namespace PluginManager.Loaders; @@ -15,8 +22,8 @@ public class PluginLoader private const string pluginCMDFolder = @"./Data/Plugins/Commands/"; private const string pluginEVEFolder = @"./Data/Plugins/Events/"; - internal const string pluginCMDExtension = "dll"; - internal const string pluginEVEExtension = "dll"; + internal const string pluginCMDExtension = "dll"; + internal const string pluginEVEExtension = "dll"; private readonly DiscordSocketClient _client; /// @@ -52,35 +59,58 @@ public class PluginLoader /// /// The main mathod that is called to load all events /// - public void LoadPlugins() + public async void LoadPlugins() { + + foreach (var file in Directory.GetFiles("./Data/Plugins", "*.dll", SearchOption.AllDirectories)) + { + await Task.Run(async () => + { + string name = new FileInfo(file).Name.Split('.')[0]; + if (!Config.PluginVersionsContainsKey(name)) + Config.SetPluginVersion(name, "0.0.0"); + + if (await PluginUpdater.CheckForUpdates(name)) + await PluginUpdater.Download(name); + }); + + } + Commands = new List(); - Events = new List(); + Events = new List(); Functions.WriteLogFile("Starting plugin loader ... Client: " + _client.CurrentUser.Username); Console.WriteLine("Loading plugins"); var commandsLoader = new Loader(pluginCMDFolder, pluginCMDExtension); - var eventsLoader = new Loader(pluginEVEFolder, pluginEVEExtension); + var eventsLoader = new Loader(pluginEVEFolder, pluginEVEExtension); - commandsLoader.FileLoaded += OnCommandFileLoaded; + commandsLoader.FileLoaded += OnCommandFileLoaded; commandsLoader.PluginLoaded += OnCommandLoaded; - eventsLoader.FileLoaded += EventFileLoaded; + eventsLoader.FileLoaded += EventFileLoaded; eventsLoader.PluginLoaded += OnEventLoaded; Commands = commandsLoader.Load(); - Events = eventsLoader.Load(); + Events = eventsLoader.Load(); + + // Console.WriteLine("Press Enter to enable console commands"); } private void EventFileLoaded(LoaderArgs e) { - if (e.IsLoaded) Functions.WriteLogFile($"[EVENT] Event from file [{e.PluginName}] has been successfully created !"); + if (!e.IsLoaded) + { + Functions.WriteLogFile($"[EVENT] Event from file [{e.PluginName}] has been successfully created !"); + } } private void OnCommandFileLoaded(LoaderArgs e) { - if (e.IsLoaded) Functions.WriteLogFile($"[CMD] Command from file [{e.PluginName}] has been successfully loaded !"); + if (!e.IsLoaded) + { + Functions.WriteLogFile($"[CMD] Command from file [{e.PluginName}] has been successfully loaded !"); + } } private void OnEventLoaded(LoaderArgs e) diff --git a/PluginManager/Online/Helpers/VersionString.cs b/PluginManager/Online/Helpers/VersionString.cs new file mode 100644 index 0000000..2a081b3 --- /dev/null +++ b/PluginManager/Online/Helpers/VersionString.cs @@ -0,0 +1,77 @@ +using PluginManager.Others; + +using System; +using System.Collections.Generic; +using System.Threading.Tasks; +using System.Linq; + +namespace PluginManager.Online.Helpers +{ + public class VersionString + { + public int PackageID; + public int PackageMainVersion; + public int PackageCheckVersion; + + public VersionString(string version) + { + string[] data = version.Split('.'); + try + { + PackageID = int.Parse(data[0]); + PackageMainVersion = int.Parse(data[1]); + PackageCheckVersion = int.Parse(data[2]); + } + catch (Exception ex) + { + throw new Exception("Failed to write Version", ex); + } + } + + public static bool operator >(VersionString s1, VersionString s2) + { + if (s1.PackageID != s2.PackageID) throw new Exception("Can not compare two different paks"); + if (s1.PackageMainVersion > s2.PackageMainVersion) return true; + if (s1.PackageMainVersion == s2.PackageMainVersion && s1.PackageCheckVersion > s2.PackageCheckVersion) return true; + + return false; + } + + public static bool operator <(VersionString s1, VersionString s2) => !(s1 > s2) && s1 != s2; + + public static bool operator ==(VersionString s1, VersionString s2) + { + if (s1.PackageID == s2.PackageID && s1.PackageMainVersion == s2.PackageMainVersion && s1.PackageCheckVersion == s2.PackageCheckVersion) return true; + return false; + } + + public static bool operator !=(VersionString s1, VersionString s2) => !(s1 == s2); + + public static bool operator <=(VersionString s1, VersionString s2) => (s1 < s2 || s1 == s2); + public static bool operator >=(VersionString s1, VersionString s2) => (s1 > s2 || s1 == s2); + + public override string ToString() + { + return "{PackageID: " + PackageID + ", PackageVersion: " + PackageMainVersion + ", PackageCheckVersion: " + PackageCheckVersion + "}"; + } + + public static VersionString? GetVersionOfPackage(string pakName) + { + if (!Config.PluginVersionsContainsKey(pakName)) + return null; + return new VersionString(Config.GetPluginVersion(pakName)); + } + + public static async Task GetVersionOfPackageFromWeb(string pakName) + { + string url = "https://raw.githubusercontent.com/Wizzy69/installer/discord-bot-files/Versions"; + List 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); + } + + } +} diff --git a/PluginManager/Online/Updates/PluginUpdater.cs b/PluginManager/Online/Updates/PluginUpdater.cs new file mode 100644 index 0000000..eb53ae3 --- /dev/null +++ b/PluginManager/Online/Updates/PluginUpdater.cs @@ -0,0 +1,50 @@ +using PluginManager.Items; +using PluginManager.Online.Helpers; + +using System; +using System.Collections.Generic; +using System.Threading.Tasks; + +namespace PluginManager.Online.Updates +{ + public class PluginUpdater + { + public static async Task CheckForUpdates(string pakName) + { + try + { + var webV = await VersionString.GetVersionOfPackageFromWeb(pakName); + var local = VersionString.GetVersionOfPackage(pakName); + + if (local is null) return true; + if (webV is null) return false; + + if (webV == local) return false; + if (webV > local) return true; + } + catch (Exception ex) { Console.WriteLine(ex.Message); } + + + return false; + } + + public static async Task DownloadUpdateInfo(string pakName) + { + string url = "https://raw.githubusercontent.com/Wizzy69/installer/discord-bot-files/Versions"; + List info = await ServerCom.ReadTextFromURL(url); + VersionString? version = await VersionString.GetVersionOfPackageFromWeb(pakName); + + if (version is null) return Update.Empty; + Update update = new Update(pakName, string.Join('\n', info), version); + return update; + } + + public static async Task Download(string pakName) + { + Console.WriteLine("An update was found for " + pakName); + await ConsoleCommandsHandler.ExecuteCommad("dwplug " + pakName); + } + + + } +} diff --git a/PluginManager/Online/Updates/Update.cs b/PluginManager/Online/Updates/Update.cs new file mode 100644 index 0000000..39eaed4 --- /dev/null +++ b/PluginManager/Online/Updates/Update.cs @@ -0,0 +1,36 @@ +using PluginManager.Online.Helpers; + +namespace PluginManager.Online.Updates +{ + public class Update + { + public static Update Empty = new Update(null, null, null); + public string pakName; + public string UpdateMessage; + + public VersionString newVersion; + + private bool isEmpty; + + public Update(string pakName, string updateMessage, VersionString newVersion) + { + this.pakName = pakName; + UpdateMessage = updateMessage; + this.newVersion = newVersion; + + if (pakName is null && updateMessage is null && newVersion is null) + isEmpty = true; + + } + + public override string ToString() + { + if (isEmpty) + throw new System.Exception("The update is EMPTY. Can not print information about an empty update !"); + return $"Package Name: {this.pakName}\n" + + $"Update Message: {UpdateMessage}\n" + + $"Version: {newVersion.ToString()}"; + } + + } +} diff --git a/PluginManager/Others/Functions.cs b/PluginManager/Others/Functions.cs index 35d29c5..61a88dd 100644 --- a/PluginManager/Others/Functions.cs +++ b/PluginManager/Others/Functions.cs @@ -68,7 +68,7 @@ namespace PluginManager.Others public static void WriteLogFile(string LogMessage) { string logsPath = logFolder + $"{DateTime.Today.ToShortDateString().Replace("/", "-").Replace("\\", "-")} Log.txt"; - if (!Directory.Exists(logFolder)) Directory.CreateDirectory(logFolder); + Directory.CreateDirectory(logFolder); File.AppendAllText(logsPath, LogMessage + " \n"); } @@ -79,7 +79,7 @@ namespace PluginManager.Others public static void WriteErrFile(string ErrMessage) { string errPath = errFolder + $"{DateTime.Today.ToShortDateString().Replace("/", "-").Replace("\\", "-")} Error.txt"; - if (!Directory.Exists(errFolder)) Directory.CreateDirectory(errFolder); + Directory.CreateDirectory(errFolder); File.AppendAllText(errPath, ErrMessage + " \n"); } diff --git a/SethDiscordBot.sln b/SethDiscordBot.sln index 9fa99c8..13ea9af 100644 --- a/SethDiscordBot.sln +++ b/SethDiscordBot.sln @@ -21,7 +21,7 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "EVE_LevelingSystem", "EVE_L EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "CMD_LevelingSystem", "CMD_LevelingSystem\CMD_LevelingSystem.csproj", "{1A4E49FF-9A0A-4C54-AF35-CFFBA64353D9}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Roles", "Roles\Roles.csproj", "{954F2AA9-6624-4554-946D-0F17B84487C3}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Roles", "Roles\Roles.csproj", "{954F2AA9-6624-4554-946D-0F17B84487C3}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution