diff --git a/DiscordBot.dll b/DiscordBot.dll
new file mode 100644
index 0000000..88b751e
Binary files /dev/null and b/DiscordBot.dll differ
diff --git a/DiscordBot/Program.cs b/DiscordBot/Program.cs
index 31aada5..0d76686 100644
--- a/DiscordBot/Program.cs
+++ b/DiscordBot/Program.cs
@@ -193,6 +193,15 @@ namespace DiscordBot
}
+ if (name == "DBUI")
+ {
+ Console.WriteLine("Reload with GUI ?[y/n]");
+ if (Console.ReadKey().Key == ConsoleKey.Y)
+ {
+ Process.Start("./DiscordBotGUI.exe");
+ Environment.Exit(0);
+ }
+ }
}
Console.WriteLine();
break;
diff --git a/DiscordBotGUI/App.axaml b/DiscordBotGUI/App.axaml
index 7cd2be3..7d4aeba 100644
--- a/DiscordBotGUI/App.axaml
+++ b/DiscordBotGUI/App.axaml
@@ -1,7 +1,7 @@
-
-
-
+
+
+
diff --git a/DiscordBotGUI/App.axaml.cs b/DiscordBotGUI/App.axaml.cs
index 7738aa0..8850f62 100644
--- a/DiscordBotGUI/App.axaml.cs
+++ b/DiscordBotGUI/App.axaml.cs
@@ -15,7 +15,10 @@ namespace DiscordBotGUI
{
if (ApplicationLifetime is IClassicDesktopStyleApplicationLifetime desktop)
{
- desktop.MainWindow = new MainWindow();
+
+
+ desktop.MainWindow = new AppUpdater() { Width = 250, Height = 50 };
+
}
base.OnFrameworkInitializationCompleted();
diff --git a/DiscordBotGUI/AppUpdater.axaml b/DiscordBotGUI/AppUpdater.axaml
new file mode 100644
index 0000000..9400060
--- /dev/null
+++ b/DiscordBotGUI/AppUpdater.axaml
@@ -0,0 +1,13 @@
+
+
+
+
+
+
+
diff --git a/DiscordBotGUI/AppUpdater.axaml.cs b/DiscordBotGUI/AppUpdater.axaml.cs
new file mode 100644
index 0000000..3edf0c5
--- /dev/null
+++ b/DiscordBotGUI/AppUpdater.axaml.cs
@@ -0,0 +1,119 @@
+using Avalonia;
+using Avalonia.Controls;
+using Avalonia.Markup.Xaml;
+
+using PluginManager.Online;
+using PluginManager.Others;
+using System.Threading.Tasks;
+using System;
+using System.IO;
+
+namespace DiscordBotGUI
+{
+ public partial class AppUpdater : Window
+ {
+ public AppUpdater()
+ {
+ InitializeComponent();
+ if (!File.Exists("./Version.txt"))
+ {
+ textBox1.Text = "Checking ...";
+ File.WriteAllText("./Version.txt", "DiscordBotVersion=0");
+ DownloadDiscordBotClientNoGUIAsDLL();
+ }
+
+ Updates();
+
+ }
+
+ private async void DownloadDiscordBotClientNoGUIAsDLL()
+ {
+
+ //await Task.Delay(5000);
+ string url_bot_dll = "https://sethdiscordbot.000webhostapp.com/Storage/Discord%20Bot/Updates/DiscordBot.dll";
+ IProgress progress = new Progress((percent) =>
+ {
+ textBox1.Text = "Downloading DiscordBot.dll ... " + percent.ToString() + "%";
+ this.progressBar1.Value = percent * 100;
+ });
+
+ this.progressBar1.IsIndeterminate = false;
+ await ServerCom.DownloadFileAsync(url_bot_dll, "./DiscordBot.dll", progress);
+ new MainWindow().Show();
+ Close();
+ }
+
+ private async void Updates()
+ {
+ if (!await CheckForUpdates())
+ {
+ await Task.Delay(5000);
+ textBox1.Text = "There is no update found !";
+ await Task.Delay(2000);
+ new MainWindow().Show();
+ this.Close();
+ return;
+ }
+
+ string file = await DownloadNewUpdate();
+ if (file == null)
+ {
+ textBox1.Text = "There was an error while downloading the update !";
+ await Task.Delay(5000);
+ new MainWindow().Show();
+ this.Close();
+ return;
+ }
+
+ IProgress progress = new Progress((percent) =>
+ {
+ this.progressBar1.Value = percent;
+ });
+ await Functions.ExtractArchive(file, "./", progress);
+
+
+ textBox1.Text = "Update downloaded successfully !";
+ await Task.Delay(2000);
+ new MainWindow().Show();
+ this.Close();
+
+ }
+
+ private async Task DownloadNewUpdate()
+ {
+ string urlNewUpdateZip = (await ServerCom.ReadTextFromFile("https://sethdiscordbot.000webhostapp.com/Storage/Discord%20Bot/Updates/Version"))[1];
+
+ IProgress progress = new Progress((percent) =>
+ {
+ this.progressBar1.Value = percent;
+ });
+
+ this.progressBar1.IsIndeterminate = false;
+ string FileName = $"{urlNewUpdateZip.Split('/')[urlNewUpdateZip.Split('/').Length - 1]}.zip";
+ await ServerCom.DownloadFileAsync(urlNewUpdateZip, FileName, progress);
+
+ return FileName;
+ }
+
+ private async Task CheckForUpdates()
+ {
+ try
+ {
+
+ string current_version = Functions.readCodeFromFile("Version.txt", "DiscordBotVersion", '=') ?? "0";
+ string latest_version = (await ServerCom.ReadTextFromFile("https://sethdiscordbot.000webhostapp.com/Storage/Discord%20Bot/Updates/Version"))[0];
+ if (current_version != latest_version)
+ {
+ return true;
+ }
+
+ return false;
+ }
+ catch (Exception ex)
+ {
+ //File.WriteAllText("./Debug.txt", "Error while checking for updates !\n" + ex.ToString());
+ return false;
+ }
+ }
+ }
+}
diff --git a/DiscordBotGUI/MainWindow.axaml.cs b/DiscordBotGUI/MainWindow.axaml.cs
index 1b05cc5..1e29828 100644
--- a/DiscordBotGUI/MainWindow.axaml.cs
+++ b/DiscordBotGUI/MainWindow.axaml.cs
@@ -17,10 +17,14 @@ namespace DiscordBotGUI
InitializeComponent();
LoadElements();
+
+
}
private void LoadElements()
{
+
+
textBox3.Watermark = "Insert start arguments";
button1.Click += async (sender, e) =>
{
@@ -74,6 +78,8 @@ namespace DiscordBotGUI
textBox2.Watermark = "Insert Bot Prefix Here";
}
+
+
}
diff --git a/DiscordBotGUI/Program.cs b/DiscordBotGUI/Program.cs
index e1a5fa3..ab83d97 100644
--- a/DiscordBotGUI/Program.cs
+++ b/DiscordBotGUI/Program.cs
@@ -3,6 +3,8 @@ using Avalonia.Controls;
using Avalonia.Controls.ApplicationLifetimes;
using System;
+using System.IO;
+using System.Threading.Tasks;
namespace DiscordBotGUI
{
@@ -12,8 +14,11 @@ namespace DiscordBotGUI
// SynchronizationContext-reliant code before AppMain is called: things aren't initialized
// yet and stuff might break.
[STAThread]
- public static void Main(string[] args) => BuildAvaloniaApp()
+ public static void Main(string[] args)
+ {
+ BuildAvaloniaApp()
.StartWithClassicDesktopLifetime(args);
+ }
// Avalonia configuration, don't remove; also used by visual designer.
public static AppBuilder BuildAvaloniaApp()
diff --git a/DiscordBotGUI/Settings/Commands.axaml.cs b/DiscordBotGUI/Settings/Commands.axaml.cs
index 24bec8c..dc63a7a 100644
--- a/DiscordBotGUI/Settings/Commands.axaml.cs
+++ b/DiscordBotGUI/Settings/Commands.axaml.cs
@@ -57,11 +57,15 @@ namespace DiscordBotGUI.Settings
if (!plugins[i].Contains(OS) || !plugins[i].Contains("Commands"))
continue;
-
-
string[] info = plugins[i].Split(',');
- if (System.IO.Directory.EnumerateFiles("./Data/Plugins/Commands/").Any(x => x.EndsWith(info[0] + ".dll")))
- continue;
+ try
+ {
+
+ if (System.IO.Directory.EnumerateFiles("./Data/Plugins/Commands/").Any(x => x.EndsWith(info[0] + ".dll")))
+ continue;
+ }
+ catch { }
+
data.Add($"{info[0]} - {info[1]} - {info[2]}");
}
diff --git a/DiscordBotGUI/Settings/Events.axaml.cs b/DiscordBotGUI/Settings/Events.axaml.cs
index 28aabc8..cf67f28 100644
--- a/DiscordBotGUI/Settings/Events.axaml.cs
+++ b/DiscordBotGUI/Settings/Events.axaml.cs
@@ -62,8 +62,13 @@ namespace DiscordBotGUI.Settings
continue;
string[] info = plugins[i].Split(',');
- if (System.IO.Directory.EnumerateFiles("./Data/Plugins/Events/").Any(x => x.EndsWith(info[0] + ".dll")))
- continue;
+ try
+ {
+ if (System.IO.Directory.EnumerateFiles("./Data/Plugins/Events/").Any(x => x.EndsWith(info[0] + ".dll")))
+ continue;
+ }
+ catch { }
+
data.Add($"{info[0]} - {info[1]} - {info[2]}");
}
diff --git a/Version.txt b/Version.txt
new file mode 100644
index 0000000..c227083
--- /dev/null
+++ b/Version.txt
@@ -0,0 +1 @@
+0
\ No newline at end of file