This commit is contained in:
@@ -7,11 +7,15 @@ using PluginManager.Others;
|
||||
using System.Threading.Tasks;
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Threading;
|
||||
using System.Drawing;
|
||||
using Avalonia.Media;
|
||||
|
||||
namespace DiscordBotGUI
|
||||
{
|
||||
public partial class AppUpdater : Window
|
||||
{
|
||||
private string _version;
|
||||
public AppUpdater()
|
||||
{
|
||||
InitializeComponent();
|
||||
@@ -19,38 +23,51 @@ namespace DiscordBotGUI
|
||||
{
|
||||
textBox1.Text = "Checking ...";
|
||||
File.WriteAllText("./Version.txt", "DiscordBotVersion=0");
|
||||
DownloadDiscordBotClientNoGUIAsDLL();
|
||||
//DownloadDiscordBotClientNoGUIAsDLL();
|
||||
}
|
||||
|
||||
Updates();
|
||||
|
||||
}
|
||||
|
||||
private async void DownloadDiscordBotClientNoGUIAsDLL()
|
||||
{
|
||||
/* 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;
|
||||
});
|
||||
//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 * 100).ToString() + "%";
|
||||
this.progressBar1.Value = percent * 100;
|
||||
});
|
||||
|
||||
this.progressBar1.IsIndeterminate = false;
|
||||
await ServerCom.DownloadFileAsync(url_bot_dll, "./DiscordBot.dll", progress);
|
||||
new MainWindow().Show();
|
||||
Close();
|
||||
}
|
||||
this.progressBar1.IsIndeterminate = false;
|
||||
try
|
||||
{
|
||||
await ServerCom.DownloadFileAsync(url_bot_dll, "./DiscordBot.dll", progress);
|
||||
}
|
||||
catch
|
||||
{
|
||||
textBox1.Text = "Error downloading DiscordBot.dll. Server is not responding.";
|
||||
|
||||
await Task.Delay(1000);
|
||||
return;
|
||||
}
|
||||
|
||||
//new MainWindow() { Height = 425, Width = 500 }.Show();
|
||||
//Close();
|
||||
}*/
|
||||
|
||||
private async void Updates()
|
||||
{
|
||||
this.progressBar1.IsIndeterminate = true;
|
||||
await Task.Delay(1000);
|
||||
if (!await CheckForUpdates())
|
||||
{
|
||||
await Task.Delay(5000);
|
||||
textBox1.Text = "There is no update found !";
|
||||
//await Task.Delay(5000);
|
||||
textBox1.Text = $"You are running on the latest version ({_version}) !";
|
||||
await Task.Delay(2000);
|
||||
new MainWindow().Show();
|
||||
new MainWindow() { Height = 425, Width = 650 }.Show();
|
||||
this.Close();
|
||||
return;
|
||||
}
|
||||
@@ -59,8 +76,8 @@ namespace DiscordBotGUI
|
||||
if (file == null)
|
||||
{
|
||||
textBox1.Text = "There was an error while downloading the update !";
|
||||
await Task.Delay(5000);
|
||||
new MainWindow().Show();
|
||||
await Task.Delay(2000);
|
||||
new MainWindow() { Height = 425, Width = 650 }.Show();
|
||||
this.Close();
|
||||
return;
|
||||
}
|
||||
@@ -69,12 +86,15 @@ namespace DiscordBotGUI
|
||||
{
|
||||
this.progressBar1.Value = percent;
|
||||
});
|
||||
|
||||
textBox1.Text = "Extracting update files ...";
|
||||
await Functions.ExtractArchive(file, "./", progress);
|
||||
|
||||
|
||||
textBox1.Text = "Update downloaded successfully !";
|
||||
await Task.Delay(2000);
|
||||
new MainWindow().Show();
|
||||
progressBar1.IsIndeterminate = true;
|
||||
textBox1.Text = "Setting up the new version ...";
|
||||
File.Delete(file);
|
||||
File.WriteAllText("./Version.txt", "DiscordBotVersion=" + _version);
|
||||
await Task.Delay(5000);
|
||||
new MainWindow() { Height = 425, Width = 650 }.Show();
|
||||
this.Close();
|
||||
|
||||
}
|
||||
@@ -82,16 +102,47 @@ namespace DiscordBotGUI
|
||||
private async Task<string> DownloadNewUpdate()
|
||||
{
|
||||
string urlNewUpdateZip = (await ServerCom.ReadTextFromFile("https://sethdiscordbot.000webhostapp.com/Storage/Discord%20Bot/Updates/Version"))[1];
|
||||
int secondsPast = 0;
|
||||
|
||||
bool isDownloading = true;
|
||||
this.progressBar1.IsIndeterminate = true;
|
||||
textBox1.Text = "Downloading update ...";
|
||||
|
||||
|
||||
IProgress<long> downloaded = new Progress<long>((bytes) =>
|
||||
{
|
||||
(double, string) download = Functions.ConvertBytes(bytes);
|
||||
textBox1.Text = $"Downloading update ... {Math.Round(download.Item1 / secondsPast, 2)} {download.Item2}/s";
|
||||
});
|
||||
IProgress<float> progress = new Progress<float>((percent) =>
|
||||
{
|
||||
progressBar1.IsIndeterminate = false;
|
||||
this.progressBar1.Value = percent;
|
||||
});
|
||||
|
||||
this.progressBar1.IsIndeterminate = false;
|
||||
string FileName = $"{urlNewUpdateZip.Split('/')[urlNewUpdateZip.Split('/').Length - 1]}.zip";
|
||||
await ServerCom.DownloadFileAsync(urlNewUpdateZip, FileName, progress);
|
||||
|
||||
string FileName = $"{urlNewUpdateZip.Split('/')[urlNewUpdateZip.Split('/').Length - 1]}";
|
||||
try
|
||||
{
|
||||
|
||||
new Thread(new Task(() =>
|
||||
{
|
||||
while (isDownloading)
|
||||
{
|
||||
Thread.Sleep(1000);
|
||||
secondsPast++;
|
||||
}
|
||||
}).Start).Start();
|
||||
await ServerCom.DownloadFileAsync(urlNewUpdateZip, FileName, progress, downloaded);
|
||||
}
|
||||
catch
|
||||
{
|
||||
textBox1.Text = "Error downloading the update. Server is not responding.";
|
||||
isDownloading = false;
|
||||
await Task.Delay(1000);
|
||||
return null;
|
||||
}
|
||||
isDownloading = false;
|
||||
return FileName;
|
||||
}
|
||||
|
||||
@@ -102,6 +153,7 @@ namespace DiscordBotGUI
|
||||
|
||||
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];
|
||||
_version = latest_version;
|
||||
if (current_version != latest_version)
|
||||
{
|
||||
return true;
|
||||
@@ -111,7 +163,7 @@ namespace DiscordBotGUI
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
//File.WriteAllText("./Debug.txt", "Error while checking for updates !\n" + ex.ToString());
|
||||
textBox1.Text = "Error while checking for updates. Server is not responding.";
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user