UI patch
This commit is contained in:
BIN
DiscordBot.dll
Normal file
BIN
DiscordBot.dll
Normal file
Binary file not shown.
@@ -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();
|
Console.WriteLine();
|
||||||
break;
|
break;
|
||||||
|
|||||||
@@ -2,6 +2,6 @@
|
|||||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||||
x:Class="DiscordBotGUI.App">
|
x:Class="DiscordBotGUI.App">
|
||||||
<Application.Styles>
|
<Application.Styles>
|
||||||
<FluentTheme Mode="Light"/>
|
<FluentTheme Mode="Dark"/>
|
||||||
</Application.Styles>
|
</Application.Styles>
|
||||||
</Application>
|
</Application>
|
||||||
|
|||||||
@@ -15,7 +15,10 @@ namespace DiscordBotGUI
|
|||||||
{
|
{
|
||||||
if (ApplicationLifetime is IClassicDesktopStyleApplicationLifetime desktop)
|
if (ApplicationLifetime is IClassicDesktopStyleApplicationLifetime desktop)
|
||||||
{
|
{
|
||||||
desktop.MainWindow = new MainWindow();
|
|
||||||
|
|
||||||
|
desktop.MainWindow = new AppUpdater() { Width = 250, Height = 50 };
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
base.OnFrameworkInitializationCompleted();
|
base.OnFrameworkInitializationCompleted();
|
||||||
|
|||||||
13
DiscordBotGUI/AppUpdater.axaml
Normal file
13
DiscordBotGUI/AppUpdater.axaml
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
<Window xmlns="https://github.com/avaloniaui"
|
||||||
|
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||||
|
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||||
|
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||||
|
mc:Ignorable="d" d:DesignWidth="250" d:DesignHeight="50"
|
||||||
|
x:Class="DiscordBotGUI.AppUpdater"
|
||||||
|
Title="AppUpdater">
|
||||||
|
|
||||||
|
<StackPanel Margin="10">
|
||||||
|
<TextBlock x:Class="DiscordBotGUI.AppUpdater" x:Name="textBox1" Text="Checking for updates..." />
|
||||||
|
<ProgressBar IsIndeterminate="True" x:Class="DiscordBotGUI.AppUpdater" x:Name="progressBar1" Foreground="Purple" />
|
||||||
|
</StackPanel>
|
||||||
|
</Window>
|
||||||
119
DiscordBotGUI/AppUpdater.axaml.cs
Normal file
119
DiscordBotGUI/AppUpdater.axaml.cs
Normal file
@@ -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<float> progress = new Progress<float>((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<float> progress = new Progress<float>((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<string> DownloadNewUpdate()
|
||||||
|
{
|
||||||
|
string urlNewUpdateZip = (await ServerCom.ReadTextFromFile("https://sethdiscordbot.000webhostapp.com/Storage/Discord%20Bot/Updates/Version"))[1];
|
||||||
|
|
||||||
|
IProgress<float> progress = new Progress<float>((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<bool> 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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -17,10 +17,14 @@ namespace DiscordBotGUI
|
|||||||
InitializeComponent();
|
InitializeComponent();
|
||||||
|
|
||||||
LoadElements();
|
LoadElements();
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void LoadElements()
|
private void LoadElements()
|
||||||
{
|
{
|
||||||
|
|
||||||
|
|
||||||
textBox3.Watermark = "Insert start arguments";
|
textBox3.Watermark = "Insert start arguments";
|
||||||
button1.Click += async (sender, e) =>
|
button1.Click += async (sender, e) =>
|
||||||
{
|
{
|
||||||
@@ -74,6 +78,8 @@ namespace DiscordBotGUI
|
|||||||
textBox2.Watermark = "Insert Bot Prefix Here";
|
textBox2.Watermark = "Insert Bot Prefix Here";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -3,6 +3,8 @@ using Avalonia.Controls;
|
|||||||
using Avalonia.Controls.ApplicationLifetimes;
|
using Avalonia.Controls.ApplicationLifetimes;
|
||||||
|
|
||||||
using System;
|
using System;
|
||||||
|
using System.IO;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
namespace DiscordBotGUI
|
namespace DiscordBotGUI
|
||||||
{
|
{
|
||||||
@@ -12,8 +14,11 @@ namespace DiscordBotGUI
|
|||||||
// SynchronizationContext-reliant code before AppMain is called: things aren't initialized
|
// SynchronizationContext-reliant code before AppMain is called: things aren't initialized
|
||||||
// yet and stuff might break.
|
// yet and stuff might break.
|
||||||
[STAThread]
|
[STAThread]
|
||||||
public static void Main(string[] args) => BuildAvaloniaApp()
|
public static void Main(string[] args)
|
||||||
|
{
|
||||||
|
BuildAvaloniaApp()
|
||||||
.StartWithClassicDesktopLifetime(args);
|
.StartWithClassicDesktopLifetime(args);
|
||||||
|
}
|
||||||
|
|
||||||
// Avalonia configuration, don't remove; also used by visual designer.
|
// Avalonia configuration, don't remove; also used by visual designer.
|
||||||
public static AppBuilder BuildAvaloniaApp()
|
public static AppBuilder BuildAvaloniaApp()
|
||||||
|
|||||||
@@ -57,11 +57,15 @@ namespace DiscordBotGUI.Settings
|
|||||||
if (!plugins[i].Contains(OS) || !plugins[i].Contains("Commands"))
|
if (!plugins[i].Contains(OS) || !plugins[i].Contains("Commands"))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
string[] info = plugins[i].Split(',');
|
string[] info = plugins[i].Split(',');
|
||||||
|
try
|
||||||
|
{
|
||||||
|
|
||||||
if (System.IO.Directory.EnumerateFiles("./Data/Plugins/Commands/").Any(x => x.EndsWith(info[0] + ".dll")))
|
if (System.IO.Directory.EnumerateFiles("./Data/Plugins/Commands/").Any(x => x.EndsWith(info[0] + ".dll")))
|
||||||
continue;
|
continue;
|
||||||
|
}
|
||||||
|
catch { }
|
||||||
|
|
||||||
data.Add($"{info[0]} - {info[1]} - {info[2]}");
|
data.Add($"{info[0]} - {info[1]} - {info[2]}");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -62,8 +62,13 @@ namespace DiscordBotGUI.Settings
|
|||||||
continue;
|
continue;
|
||||||
|
|
||||||
string[] info = plugins[i].Split(',');
|
string[] info = plugins[i].Split(',');
|
||||||
|
try
|
||||||
|
{
|
||||||
if (System.IO.Directory.EnumerateFiles("./Data/Plugins/Events/").Any(x => x.EndsWith(info[0] + ".dll")))
|
if (System.IO.Directory.EnumerateFiles("./Data/Plugins/Events/").Any(x => x.EndsWith(info[0] + ".dll")))
|
||||||
continue;
|
continue;
|
||||||
|
}
|
||||||
|
catch { }
|
||||||
|
|
||||||
|
|
||||||
data.Add($"{info[0]} - {info[1]} - {info[2]}");
|
data.Add($"{info[0]} - {info[1]} - {info[2]}");
|
||||||
}
|
}
|
||||||
|
|||||||
1
Version.txt
Normal file
1
Version.txt
Normal file
@@ -0,0 +1 @@
|
|||||||
|
0
|
||||||
Reference in New Issue
Block a user