Linux compatibility update
This commit is contained in:
@@ -8,7 +8,7 @@
|
|||||||
<StartupObject />
|
<StartupObject />
|
||||||
<SignAssembly>False</SignAssembly>
|
<SignAssembly>False</SignAssembly>
|
||||||
<IsPublishable>True</IsPublishable>
|
<IsPublishable>True</IsPublishable>
|
||||||
<AssemblyVersion>1.0.0.13</AssemblyVersion>
|
<AssemblyVersion>1.0.0.14</AssemblyVersion>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
|
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
|
||||||
|
|||||||
@@ -4,12 +4,14 @@ using System.Diagnostics;
|
|||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Reflection;
|
using System.Reflection;
|
||||||
|
using System.Runtime.CompilerServices;
|
||||||
using System.Threading;
|
using System.Threading;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
using Discord;
|
using Discord;
|
||||||
|
|
||||||
using DiscordBot.Discord.Core;
|
using DiscordBot.Discord.Core;
|
||||||
|
|
||||||
using PluginManager;
|
using PluginManager;
|
||||||
using PluginManager.Items;
|
using PluginManager.Items;
|
||||||
using PluginManager.Online;
|
using PluginManager.Online;
|
||||||
@@ -230,6 +232,11 @@ public class Program
|
|||||||
len = 0;
|
len = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (len == 2 && args[0] == "/procKill")
|
||||||
|
{
|
||||||
|
Process.GetProcessById(int.Parse(args[1])).Kill();
|
||||||
|
len = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
var b = await StartNoGUI();
|
var b = await StartNoGUI();
|
||||||
@@ -370,7 +377,7 @@ public class Program
|
|||||||
|
|
||||||
|
|
||||||
List<string> onlineSettingsList = await ServerCom.ReadTextFromURL("https://raw.githubusercontent.com/Wizzy69/installer/discord-bot-files/OnlineData");
|
List<string> onlineSettingsList = await ServerCom.ReadTextFromURL("https://raw.githubusercontent.com/Wizzy69/installer/discord-bot-files/OnlineData");
|
||||||
main.Stop();
|
main.Stop("Loaded online settings. Loading updates ...");
|
||||||
foreach (var key in onlineSettingsList)
|
foreach (var key in onlineSettingsList)
|
||||||
{
|
{
|
||||||
if (key.Length <= 3 || !key.Contains(' ')) continue;
|
if (key.Length <= 3 || !key.Contains(' ')) continue;
|
||||||
@@ -394,7 +401,14 @@ public class Program
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
string url = $"https://github.com/Wizzy69/SethDiscordBot/releases/download/v{newVersion}/net6.0_linux.zip";
|
string url = $"https://github.com/Wizzy69/SethDiscordBot/releases/download/v{newVersion}/net6.0_linux.zip";
|
||||||
Process.Start("./Updater/Updater", $"/update {url} ./DiscordBot ./");
|
Console_Utilities.ProgressBar bar = new Console_Utilities.ProgressBar(ProgressBarType.NO_END);
|
||||||
|
bar.Start();
|
||||||
|
await ServerCom.DownloadFileNoProgressAsync(url, "./update.zip");
|
||||||
|
await Functions.ExtractArchive("./update.zip", "./", null, UnzipProgressType.PercentageFromNumberOfFiles);
|
||||||
|
bar.Stop("Console is now Updated");
|
||||||
|
|
||||||
|
Process.Start("./DiscordBot /procKill " + Process.GetCurrentProcess().Id);
|
||||||
|
|
||||||
}
|
}
|
||||||
//Environment.Exit(0);
|
//Environment.Exit(0);
|
||||||
}
|
}
|
||||||
@@ -402,7 +416,7 @@ public class Program
|
|||||||
break;
|
break;
|
||||||
case "UpdaterVersion":
|
case "UpdaterVersion":
|
||||||
string updaternewversion = s[1];
|
string updaternewversion = s[1];
|
||||||
if (Config.UpdaterVersion != updaternewversion)
|
if (Config.UpdaterVersion != updaternewversion && Functions.GetOperatingSystem() == PluginManager.Others.OperatingSystem.WINDOWS)
|
||||||
{
|
{
|
||||||
Console.Clear();
|
Console.Clear();
|
||||||
Console.WriteLine("Installing updater ...\nDo NOT close the bot during update !");
|
Console.WriteLine("Installing updater ...\nDo NOT close the bot during update !");
|
||||||
@@ -413,7 +427,7 @@ public class Program
|
|||||||
Config.UpdaterVersion = updaternewversion;
|
Config.UpdaterVersion = updaternewversion;
|
||||||
File.Delete("Updater.zip");
|
File.Delete("Updater.zip");
|
||||||
await Config.SaveConfig(SaveType.NORMAL);
|
await Config.SaveConfig(SaveType.NORMAL);
|
||||||
bar.Stop();
|
bar.Stop("Updater has been updated !");
|
||||||
Console.Clear();
|
Console.Clear();
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|||||||
@@ -14,9 +14,7 @@ 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.Online.Updates;
|
|
||||||
using PluginManager.Others;
|
using PluginManager.Others;
|
||||||
|
|
||||||
namespace PluginManager.Items;
|
namespace PluginManager.Items;
|
||||||
|
|
||||||
public class ConsoleCommandsHandler
|
public class ConsoleCommandsHandler
|
||||||
@@ -162,8 +160,18 @@ public class ConsoleCommandsHandler
|
|||||||
path = "./Data/Plugins/" + info[0] + "s/" + name + "." + (info[0] == "Command" ? PluginLoader.pluginCMDExtension : PluginLoader.pluginEVEExtension);
|
path = "./Data/Plugins/" + info[0] + "s/" + name + "." + (info[0] == "Command" ? PluginLoader.pluginCMDExtension : PluginLoader.pluginEVEExtension);
|
||||||
else
|
else
|
||||||
path = $"./{info[1].Split('/')[info[1].Split('/').Length - 1]}";
|
path = $"./{info[1].Split('/')[info[1].Split('/').Length - 1]}";
|
||||||
//Console.WriteLine("Downloading: " + path + " [" + info[1] + "]");
|
if (Others.OperatingSystem.WINDOWS == Functions.GetOperatingSystem())
|
||||||
await ServerCom.DownloadFileAsync(info[1], path);
|
{
|
||||||
|
await ServerCom.DownloadFileAsync(info[1], path);
|
||||||
|
}
|
||||||
|
else if (Others.OperatingSystem.LINUX == Functions.GetOperatingSystem())
|
||||||
|
{
|
||||||
|
Others.Console_Utilities.ProgressBar bar = new Console_Utilities.ProgressBar(ProgressBarType.NO_END);
|
||||||
|
bar.Start();
|
||||||
|
await ServerCom.DownloadFileNoProgressAsync(info[1], path);
|
||||||
|
bar.Stop("Plugin Downloaded !");
|
||||||
|
}
|
||||||
|
|
||||||
if (info[0] == "Event")
|
if (info[0] == "Event")
|
||||||
Config.PluginConfig.InstalledPlugins.Add(new(name, PluginType.Event));
|
Config.PluginConfig.InstalledPlugins.Add(new(name, PluginType.Event));
|
||||||
else if (info[0] == "Command")
|
else if (info[0] == "Command")
|
||||||
@@ -187,7 +195,16 @@ public class ConsoleCommandsHandler
|
|||||||
var split = line.Split(',');
|
var split = line.Split(',');
|
||||||
Console.WriteLine($"\nDownloading item: {split[1]}");
|
Console.WriteLine($"\nDownloading item: {split[1]}");
|
||||||
if (File.Exists("./" + split[1])) File.Delete("./" + split[1]);
|
if (File.Exists("./" + split[1])) File.Delete("./" + split[1]);
|
||||||
await ServerCom.DownloadFileAsync(split[0], "./" + split[1]);
|
if (Others.OperatingSystem.WINDOWS == Functions.GetOperatingSystem())
|
||||||
|
await ServerCom.DownloadFileAsync(split[0], "./" + split[1]);
|
||||||
|
else if (Others.OperatingSystem.LINUX == Functions.GetOperatingSystem())
|
||||||
|
{
|
||||||
|
Others.Console_Utilities.ProgressBar bar = new Console_Utilities.ProgressBar(ProgressBarType.NO_END);
|
||||||
|
bar.Start();
|
||||||
|
await ServerCom.DownloadFileNoProgressAsync(split[0], "./" + split[1]);
|
||||||
|
bar.Stop("Item downloaded !");
|
||||||
|
|
||||||
|
}
|
||||||
Console.WriteLine();
|
Console.WriteLine();
|
||||||
if (split[0].EndsWith(".pak"))
|
if (split[0].EndsWith(".pak"))
|
||||||
File.Move("./" + split[1], "./Data/PAKS/" + split[1], true);
|
File.Move("./" + split[1], "./Data/PAKS/" + split[1], true);
|
||||||
@@ -197,7 +214,7 @@ public class ConsoleCommandsHandler
|
|||||||
var bar = new Console_Utilities.ProgressBar(ProgressBarType.NO_END);// { Max = 100f, Color = ConsoleColor.Green };
|
var bar = new Console_Utilities.ProgressBar(ProgressBarType.NO_END);// { Max = 100f, Color = ConsoleColor.Green };
|
||||||
bar.Start();
|
bar.Start();
|
||||||
await Functions.ExtractArchive("./" + split[1], "./", null, UnzipProgressType.PercentageFromTotalSize);
|
await Functions.ExtractArchive("./" + split[1], "./", null, UnzipProgressType.PercentageFromTotalSize);
|
||||||
bar.Stop();
|
bar.Stop("Extracted");
|
||||||
Console.WriteLine("\n");
|
Console.WriteLine("\n");
|
||||||
File.Delete("./" + split[1]);
|
File.Delete("./" + split[1]);
|
||||||
}
|
}
|
||||||
@@ -208,10 +225,12 @@ public class ConsoleCommandsHandler
|
|||||||
VersionString? ver = await VersionString.GetVersionOfPackageFromWeb(name);
|
VersionString? ver = await VersionString.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}");
|
||||||
// Console.WriteLine();
|
|
||||||
|
|
||||||
isDownloading = false;
|
isDownloading = false;
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
||||||
@@ -264,11 +283,12 @@ public class ConsoleCommandsHandler
|
|||||||
bar.Start();
|
bar.Start();
|
||||||
await Config.SaveConfig(SaveType.NORMAL);
|
await Config.SaveConfig(SaveType.NORMAL);
|
||||||
await Config.SaveConfig(SaveType.BACKUP);
|
await Config.SaveConfig(SaveType.BACKUP);
|
||||||
await Task.Delay(4000);
|
bar.Stop("Saved config !");
|
||||||
bar.Stop();
|
|
||||||
Console.WriteLine();
|
Console.WriteLine();
|
||||||
await client.StopAsync();
|
await client.StopAsync();
|
||||||
await client.DisposeAsync();
|
await client.DisposeAsync();
|
||||||
|
|
||||||
|
await Task.Delay(1000);
|
||||||
Environment.Exit(0);
|
Environment.Exit(0);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -42,12 +42,15 @@ namespace PluginManager.Others
|
|||||||
public bool NoColor { get; init; }
|
public bool NoColor { get; init; }
|
||||||
public ProgressBarType type { get; set; }
|
public ProgressBarType type { get; set; }
|
||||||
|
|
||||||
|
public int TotalLength { get; private set; }
|
||||||
|
|
||||||
private int BarLength = 32;
|
private int BarLength = 32;
|
||||||
private int position = 1;
|
private int position = 1;
|
||||||
private bool positive = true;
|
private bool positive = true;
|
||||||
|
|
||||||
private bool isRunning;
|
private bool isRunning;
|
||||||
|
|
||||||
|
|
||||||
public async void Start()
|
public async void Start()
|
||||||
{
|
{
|
||||||
if (type != ProgressBarType.NO_END)
|
if (type != ProgressBarType.NO_END)
|
||||||
@@ -63,6 +66,23 @@ namespace PluginManager.Others
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public async void Start(string message)
|
||||||
|
{
|
||||||
|
if (type != ProgressBarType.NO_END)
|
||||||
|
throw new Exception("Only NO_END progress bar can use this method");
|
||||||
|
if (isRunning)
|
||||||
|
throw new Exception("This progress bar is already running");
|
||||||
|
|
||||||
|
isRunning = true;
|
||||||
|
|
||||||
|
TotalLength = message.Length + BarLength + 5;
|
||||||
|
while (isRunning)
|
||||||
|
{
|
||||||
|
UpdateNoEnd(message);
|
||||||
|
await System.Threading.Tasks.Task.Delay(100);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public void Stop()
|
public void Stop()
|
||||||
{
|
{
|
||||||
if (type != ProgressBarType.NO_END)
|
if (type != ProgressBarType.NO_END)
|
||||||
@@ -72,20 +92,45 @@ namespace PluginManager.Others
|
|||||||
isRunning = false;
|
isRunning = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void Stop(string message)
|
||||||
|
{
|
||||||
|
Stop();
|
||||||
|
|
||||||
|
if (message is not null)
|
||||||
|
{
|
||||||
|
Console.CursorLeft = 0;
|
||||||
|
for (int i = 0; i < BarLength + message.Length + 1; i++)
|
||||||
|
Console.Write(" ");
|
||||||
|
Console.CursorLeft = 0;
|
||||||
|
Console.WriteLine(message);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public void Update(float progress)
|
public void Update(float progress)
|
||||||
{
|
{
|
||||||
switch (type)
|
if (type == ProgressBarType.NO_END)
|
||||||
{
|
throw new Exception("This function is for progress bars with end");
|
||||||
case ProgressBarType.NORMAL:
|
|
||||||
UpdateNormal(progress);
|
UpdateNormal(progress);
|
||||||
return;
|
}
|
||||||
case ProgressBarType.NO_END:
|
|
||||||
if (progress <= 99.9f)
|
private void UpdateNoEnd(string message)
|
||||||
UpdateNoEnd();
|
{
|
||||||
return;
|
Console.CursorLeft = 0;
|
||||||
default:
|
Console.Write("[");
|
||||||
return;
|
for (int i = 1; i <= position; i++)
|
||||||
}
|
Console.Write(" ");
|
||||||
|
Console.Write("<==()==>");
|
||||||
|
position += positive ? 1 : -1;
|
||||||
|
for (int i = position; i <= BarLength - 1 - (positive ? 0 : 2); i++)
|
||||||
|
Console.Write(" ");
|
||||||
|
Console.Write("] " + message);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
if (position == BarLength - 1 || position == 1)
|
||||||
|
positive = !positive;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void UpdateNoEnd()
|
private void UpdateNoEnd()
|
||||||
@@ -101,6 +146,8 @@ namespace PluginManager.Others
|
|||||||
Console.Write("]");
|
Console.Write("]");
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
if (position == BarLength - 1 || position == 1)
|
if (position == BarLength - 1 || position == 1)
|
||||||
positive = !positive;
|
positive = !positive;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user