patch: listplugs, plugin version system and progress bar

This commit is contained in:
2022-08-25 15:15:47 +03:00
parent b98f57fcf8
commit f6442af30c
10 changed files with 210 additions and 55 deletions

View File

@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="RiderProjectSettingsUpdater">
<option name="vcsConfiguration" value="2" />
</component>
</project>

View File

@@ -0,0 +1,107 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="AutoGeneratedRunConfigurationManager">
<projectFile>DiscordBot/DiscordBot.csproj</projectFile>
<projectFile pubXmlPath="DiscordBot/Properties/PublishProfiles/WindowsBuild.pubxml">DiscordBot/DiscordBot.csproj</projectFile>
</component>
<component name="AutoImportSettings">
<option name="autoReloadType" value="SELECTIVE" />
</component>
<component name="ChangeListManager">
<list default="true" id="ab173b07-aba1-4bb8-94c1-ae9846bbdb0a" name="Changes" comment="">
<change afterPath="$PROJECT_DIR$/Roles/AddRole.cs" afterDir="false" />
<change afterPath="$PROJECT_DIR$/Roles/Internals/RoleManagement.cs" afterDir="false" />
<change afterPath="$PROJECT_DIR$/Roles/Roles.csproj" afterDir="false" />
<change beforePath="$PROJECT_DIR$/BUILDS/net6.0/CMD_Utils.dll" beforeDir="false" afterPath="$PROJECT_DIR$/BUILDS/net6.0/CMD_Utils.dll" afterDir="false" />
<change beforePath="$PROJECT_DIR$/BUILDS/net6.0/Music Commands.dll" beforeDir="false" afterPath="$PROJECT_DIR$/BUILDS/net6.0/Music Commands.dll" afterDir="false" />
<change beforePath="$PROJECT_DIR$/BUILDS/net6.0/PluginManager.dll" beforeDir="false" afterPath="$PROJECT_DIR$/BUILDS/net6.0/PluginManager.dll" afterDir="false" />
<change beforePath="$PROJECT_DIR$/CMD_LevelingSystem/Level.cs" beforeDir="false" afterPath="$PROJECT_DIR$/CMD_LevelingSystem/Level.cs" afterDir="false" />
<change beforePath="$PROJECT_DIR$/CMD_Utils/Echo.cs" beforeDir="false" afterPath="$PROJECT_DIR$/CMD_Utils/Echo.cs" afterDir="false" />
<change beforePath="$PROJECT_DIR$/CMD_Utils/FlipCoin.cs" beforeDir="false" afterPath="$PROJECT_DIR$/CMD_Utils/FlipCoin.cs" afterDir="false" />
<change beforePath="$PROJECT_DIR$/CMD_Utils/Poll.cs" beforeDir="false" afterPath="$PROJECT_DIR$/CMD_Utils/Poll.cs" afterDir="false" />
<change beforePath="$PROJECT_DIR$/CMD_Utils/Random.cs" beforeDir="false" afterPath="$PROJECT_DIR$/CMD_Utils/Random.cs" afterDir="false" />
<change beforePath="$PROJECT_DIR$/DiscordBot/Discord/Commands/Help.cs" beforeDir="false" afterPath="$PROJECT_DIR$/DiscordBot/Discord/Commands/Help.cs" afterDir="false" />
<change beforePath="$PROJECT_DIR$/DiscordBot/Discord/Commands/Restart.cs" beforeDir="false" afterPath="$PROJECT_DIR$/DiscordBot/Discord/Commands/Restart.cs" afterDir="false" />
<change beforePath="$PROJECT_DIR$/DiscordBot/Discord/Commands/Settings.cs" beforeDir="false" afterPath="$PROJECT_DIR$/DiscordBot/Discord/Commands/Settings.cs" afterDir="false" />
<change beforePath="$PROJECT_DIR$/DiscordBot/Discord/Core/Boot.cs" beforeDir="false" afterPath="$PROJECT_DIR$/DiscordBot/Discord/Core/Boot.cs" afterDir="false" />
<change beforePath="$PROJECT_DIR$/DiscordBot/Discord/Core/CommandHandler.cs" beforeDir="false" afterPath="$PROJECT_DIR$/DiscordBot/Discord/Core/CommandHandler.cs" afterDir="false" />
<change beforePath="$PROJECT_DIR$/DiscordBot/DiscordBot.csproj" beforeDir="false" afterPath="$PROJECT_DIR$/DiscordBot/DiscordBot.csproj" afterDir="false" />
<change beforePath="$PROJECT_DIR$/DiscordBot/Program.cs" beforeDir="false" afterPath="$PROJECT_DIR$/DiscordBot/Program.cs" afterDir="false" />
<change beforePath="$PROJECT_DIR$/MusicCommands/Leave.cs" beforeDir="false" afterPath="$PROJECT_DIR$/MusicCommands/Leave.cs" afterDir="false" />
<change beforePath="$PROJECT_DIR$/MusicCommands/MusicPlayer.cs" beforeDir="false" afterPath="$PROJECT_DIR$/MusicCommands/MusicPlayer.cs" afterDir="false" />
<change beforePath="$PROJECT_DIR$/MusicCommands/Pause.cs" beforeDir="false" afterPath="$PROJECT_DIR$/MusicCommands/Pause.cs" afterDir="false" />
<change beforePath="$PROJECT_DIR$/MusicCommands/Play.cs" beforeDir="false" afterPath="$PROJECT_DIR$/MusicCommands/Play.cs" afterDir="false" />
<change beforePath="$PROJECT_DIR$/MusicCommands/Skip.cs" beforeDir="false" afterPath="$PROJECT_DIR$/MusicCommands/Skip.cs" afterDir="false" />
<change beforePath="$PROJECT_DIR$/MusicCommands/queue.cs" beforeDir="false" afterPath="$PROJECT_DIR$/MusicCommands/queue.cs" afterDir="false" />
<change beforePath="$PROJECT_DIR$/PluginManager/Config.cs" beforeDir="false" afterPath="$PROJECT_DIR$/PluginManager/Config.cs" afterDir="false" />
<change beforePath="$PROJECT_DIR$/PluginManager/Interfaces/DBCommand.cs" beforeDir="false" afterPath="$PROJECT_DIR$/PluginManager/Interfaces/DBCommand.cs" afterDir="false" />
<change beforePath="$PROJECT_DIR$/PluginManager/Items/Command.cs" beforeDir="false" afterPath="$PROJECT_DIR$/PluginManager/Items/Command.cs" afterDir="false" />
<change beforePath="$PROJECT_DIR$/PluginManager/Items/ConsoleCommandsHandler.cs" beforeDir="false" afterPath="$PROJECT_DIR$/PluginManager/Items/ConsoleCommandsHandler.cs" afterDir="false" />
<change beforePath="$PROJECT_DIR$/SethDiscordBot.sln" beforeDir="false" afterPath="$PROJECT_DIR$/SethDiscordBot.sln" afterDir="false" />
</list>
<option name="SHOW_DIALOG" value="false" />
<option name="HIGHLIGHT_CONFLICTS" value="true" />
<option name="HIGHLIGHT_NON_ACTIVE_CHANGELIST" value="false" />
<option name="LAST_RESOLUTION" value="IGNORE" />
</component>
<component name="MarkdownSettingsMigration">
<option name="stateVersion" value="1" />
</component>
<component name="ProjectId" id="2CUQteUHoNWL2Ok4DVEh1GfFaXk" />
<component name="ProjectViewState">
<option name="hideEmptyMiddlePackages" value="true" />
<option name="showLibraryContents" value="true" />
</component>
<component name="PropertiesComponent"><![CDATA[{
"keyToString": {
"ASKED_SHARE_PROJECT_CONFIGURATION_FILES": "true",
"RunOnceActivity.OpenProjectViewOnStart": "true",
"RunOnceActivity.ShowReadmeOnStart": "true",
"WebServerToolWindowFactoryState": "false",
"node.js.detected.package.eslint": "true",
"node.js.detected.package.tslint": "true",
"node.js.selected.package.eslint": "(autodetect)",
"node.js.selected.package.tslint": "(autodetect)",
"nodejs_package_manager_path": "npm",
"settings.editor.selected.configurable": "preferences.pluginManager",
"vue.rearranger.settings.migration": "true"
}
}]]></component>
<component name="RunManager">
<configuration name="DiscordBot: WindowsBuild" type="DotNetMsBuildPublish" factoryName="Publish to IIS">
<riderPublish publish_profile="WindowsBuild.pubxml" pubxml_path="$PROJECT_DIR$/DiscordBot/Properties/PublishProfiles/WindowsBuild.pubxml" uuid_high="612037599008934041" uuid_low="-9069359786678974134" />
<method v="2" />
</configuration>
</component>
<component name="SpellCheckerSettings" RuntimeDictionaries="0" Folders="0" CustomDictionaries="0" DefaultDictionary="application-level" UseSingleDictionary="true" transferred="true" />
<component name="TaskManager">
<task active="true" id="Default" summary="Default task">
<changelist id="ab173b07-aba1-4bb8-94c1-ae9846bbdb0a" name="Changes" comment="" />
<created>1658854902538</created>
<option name="number" value="Default" />
<option name="presentableId" value="Default" />
<updated>1658854902538</updated>
<workItem from="1658854908500" duration="1731000" />
</task>
<servers />
</component>
<component name="TypeScriptGeneratedFilesManager">
<option name="version" value="3" />
</component>
<component name="UnityCheckinConfiguration" checkUnsavedScenes="true" />
<component name="UnityUnitTestConfiguration" currentTestLauncher="NUnit" />
<component name="Vcs.Log.Tabs.Properties">
<option name="TAB_STATES">
<map>
<entry key="MAIN">
<value>
<State />
</value>
</entry>
</map>
</option>
</component>
<component name="VcsManagerConfiguration">
<option name="CLEAR_INITIAL_COMMIT_MESSAGE" value="true" />
</component>
</project>

View File

@@ -112,15 +112,16 @@ public class Program
#if DEBUG #if DEBUG
Console.WriteLine(); Console.WriteLine();
consoleCommandsHandler.HandleCommand("lp"); ConsoleCommandsHandler.ExecuteCommad("lp").Wait();
#else #else
if (loadPluginsOnStartup) consoleCommandsHandler.HandleCommand("lp"); if (loadPluginsOnStartup) consoleCommandsHandler.HandleCommand("lp");
if (listPluginsAtStartup) consoleCommandsHandler.HandleCommand("listplugs"); if (listPluginsAtStartup) consoleCommandsHandler.HandleCommand("listplugs");
#endif #endif
Config.SaveConfig(SaveType.NORMAL); Config.SaveConfig(SaveType.NORMAL).Wait();
while (true) while (true)
{ {
// Console_Utilities.WriteColorText("&rSethBot (&yDEBUG&r) &c> ", false);
var cmd = Console.ReadLine(); var cmd = Console.ReadLine();
if (!consoleCommandsHandler.HandleCommand(cmd! if (!consoleCommandsHandler.HandleCommand(cmd!
#if DEBUG #if DEBUG
@@ -177,7 +178,6 @@ public class Program
#endif #endif
var prefix = Config.GetValue<string>("prefix"); var prefix = Config.GetValue<string>("prefix");
var discordbooter = new Boot(token, prefix); var discordbooter = new Boot(token, prefix);
await discordbooter.Awake(); await discordbooter.Awake();
return discordbooter; return discordbooter;
@@ -230,11 +230,11 @@ public class Program
int p = 1; int p = 1;
bool allowed = true; bool allowed = true;
Console.CancelKeyPress += (sender, e) => allowed = false; Console.CancelKeyPress += (sender, e) => allowed = false;
Console_Utilities.ProgressBar bar = new Console_Utilities.ProgressBar(); Console_Utilities.ProgressBar bar = new(ProgressBarType.NO_END);// { NoColor = false, Color = ConsoleColor.DarkRed };
Console.WriteLine("Press Ctrl + C to stop."); Console.WriteLine("Press Ctrl + C to stop.");
while (p <= int.MaxValue - 1 && allowed) while (p <= int.MaxValue - 1 && allowed)
{ {
bar.Update(ProgressBarType.NO_END, 100 / p); bar.Update(100 / p);
await Task.Delay(100); await Task.Delay(100);
p++; p++;
} }

View File

@@ -181,7 +181,7 @@ namespace PluginManager
SaveConfig(SaveType.NORMAL); SaveConfig(SaveType.NORMAL);
} }
public static async void SaveConfig(SaveType type) public static async Task SaveConfig(SaveType type)
{ {
if (type == SaveType.NORMAL) if (type == SaveType.NORMAL)
{ {

View File

@@ -82,30 +82,48 @@ public class ConsoleCommandsHandler
if (pluginsLoaded) if (pluginsLoaded)
return; return;
var loader = new PluginLoader(client!); var loader = new PluginLoader(client!);
ConsoleColor cc = Console.ForegroundColor;
loader.onCMDLoad += (name, typeName, success, exception) => loader.onCMDLoad += (name, typeName, success, exception) =>
{ {
Console.ForegroundColor = ConsoleColor.Green;
if (name == null || name.Length < 2) if (name == null || name.Length < 2)
name = typeName; name = typeName;
if (success) if (success)
{
Console.ForegroundColor = ConsoleColor.Green;
Console.WriteLine("[CMD] Successfully loaded command : " + name); Console.WriteLine("[CMD] Successfully loaded command : " + name);
}
else else
Console.WriteLine("[CMD] Failed to load command : " + name + " because " + exception!.Message); {
Console.ForegroundColor = ConsoleColor.Red; Console.ForegroundColor = ConsoleColor.Red;
Console.WriteLine("[CMD] Failed to load command : " + name + " because " + exception!.Message);
}
Console.ForegroundColor = cc;
}; };
loader.onEVELoad += (name, typeName, success, exception) => loader.onEVELoad += (name, typeName, success, exception) =>
{ {
if (name == null || name.Length < 2) if (name == null || name.Length < 2)
name = typeName; name = typeName;
Console.ForegroundColor = ConsoleColor.Green;
if (success) if (success)
{
Console.ForegroundColor = ConsoleColor.Green;
Console.WriteLine("[EVENT] Successfully loaded event : " + name); Console.WriteLine("[EVENT] Successfully loaded event : " + name);
}
else else
Console.WriteLine("[EVENT] Failed to load event : " + name + " because " + exception!.Message); {
Console.ForegroundColor = ConsoleColor.Red; Console.ForegroundColor = ConsoleColor.Red;
Console.WriteLine("[EVENT] Failed to load event : " + name + " because " + exception!.Message);
}
Console.ForegroundColor = cc;
}; };
loader.LoadPlugins(); loader.LoadPlugins();
Console.ForegroundColor = cc;
pluginsLoaded = true; pluginsLoaded = true;
} }
); );
@@ -178,14 +196,14 @@ public class ConsoleCommandsHandler
Console.WriteLine($"Extracting {split[1]}"); Console.WriteLine($"Extracting {split[1]}");
var proc = 0f; var proc = 0f;
var isExtracting = true; var isExtracting = true;
var bar = new Console_Utilities.ProgressBar { Max = 100f, Color = ConsoleColor.Green }; var bar = new Console_Utilities.ProgressBar(ProgressBarType.NORMAL) { Max = 100f, Color = ConsoleColor.Green };
IProgress<float> extractProgress = new Progress<float>(value => { proc = value; }); IProgress<float> extractProgress = new Progress<float>(value => { proc = value; });
new Thread(new Task(() => new Thread(new Task(() =>
{ {
while (isExtracting) while (isExtracting)
{ {
bar.Update(ProgressBarType.NORMAL, proc); bar.Update(proc);
if (proc >= 99.9f) if (proc >= 99.9f)
isExtracting = false; isExtracting = false;
Thread.Sleep(500); Thread.Sleep(500);
@@ -194,10 +212,10 @@ public class ConsoleCommandsHandler
).Start ).Start
).Start(); ).Start();
await Functions.ExtractArchive("./" + split[1], "./", extractProgress, UnzipProgressType.PercentageFromTotalSize); await Functions.ExtractArchive("./" + split[1], "./", extractProgress, UnzipProgressType.PercentageFromTotalSize);
bar.Update(ProgressBarType.NORMAL, 100f); bar.Update(100f);
isExtracting = false; isExtracting = false;
await Task.Delay(1000); await Task.Delay(1000);
bar.Update(ProgressBarType.NORMAL, 100); bar.Update(100);
Console.WriteLine("\n"); Console.WriteLine("\n");
File.Delete("./" + split[1]); File.Delete("./" + split[1]);
} }
@@ -207,7 +225,7 @@ 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.PackageID}.{ver.PackageMainVersion}.{ver.PackageCheckVersion}"); Config.SetPluginVersion(name, $"{ver.PackageVersionID}.{ver.PackageMainVersion}.{ver.PackageCheckVersion}");
// Console.WriteLine(); // Console.WriteLine();
isDownloading = false; isDownloading = false;
@@ -255,17 +273,30 @@ public class ConsoleCommandsHandler
} }
); );
AddCommand("sd", "Shuts down the discord bot", () => AddCommand("sd", "Shuts down the discord bot", async () =>
{ {
if (client is null) if (client is null)
return; return;
client.StopAsync(); bool run = true;
client.DisposeAsync(); var t = new Thread(() =>
Config.SaveConfig(SaveType.NORMAL); {
Config.SaveConfig(SaveType.BACKUP); Console_Utilities.ProgressBar bar = new Console_Utilities.ProgressBar(ProgressBarType.NO_END);
Console.WriteLine("Bot is closing in 2 seconds ! Please wait to save data !"); while (run)
Thread.Sleep(2000); {
bar.Update(1);
Thread.Sleep(50);
}
});
t.Start();
await Config.SaveConfig(SaveType.NORMAL);
await Config.SaveConfig(SaveType.BACKUP);
await Task.Delay(4000);
run = false;
Console.WriteLine();
await client.StopAsync();
await client.DisposeAsync();
Environment.Exit(0); Environment.Exit(0);
} }
); );
@@ -346,7 +377,7 @@ public class ConsoleCommandsHandler
Console.WriteLine("Found: " + tuple.ToString()); Console.WriteLine("Found: " + tuple.ToString());
Config.PluginConfig.InstalledPlugins.Remove(tuple); Config.PluginConfig.InstalledPlugins.Remove(tuple);
Config.RemovePluginVersion(plugName); Config.RemovePluginVersion(plugName);
Config.SaveConfig(SaveType.NORMAL); await Config.SaveConfig(SaveType.NORMAL);
} }
Console.WriteLine("Removed the plugin DLL. Checking for other files ..."); Console.WriteLine("Removed the plugin DLL. Checking for other files ...");

View File

@@ -69,7 +69,7 @@ public class PluginLoader
{ {
string name = new FileInfo(file).Name.Split('.')[0]; string name = new FileInfo(file).Name.Split('.')[0];
if (!Config.PluginVersionsContainsKey(name)) if (!Config.PluginVersionsContainsKey(name))
Config.SetPluginVersion(name, (await VersionString.GetVersionOfPackageFromWeb(name))?.PackageID + ".0.0"); Config.SetPluginVersion(name, (await VersionString.GetVersionOfPackageFromWeb(name))?.PackageVersionID + ".0.0");
if (await PluginUpdater.CheckForUpdates(name)) if (await PluginUpdater.CheckForUpdates(name))
await PluginUpdater.Download(name); await PluginUpdater.Download(name);
@@ -84,7 +84,7 @@ public class PluginLoader
{ {
string name = new FileInfo(file).Name.Split('.')[0]; string name = new FileInfo(file).Name.Split('.')[0];
if (!Config.PluginVersionsContainsKey(name)) if (!Config.PluginVersionsContainsKey(name))
Config.SetPluginVersion(name, (await VersionString.GetVersionOfPackageFromWeb(name))?.PackageID + ".0.0"); Config.SetPluginVersion(name, (await VersionString.GetVersionOfPackageFromWeb(name))?.PackageVersionID + ".0.0");
if (await PluginUpdater.CheckForUpdates(name)) if (await PluginUpdater.CheckForUpdates(name))
await PluginUpdater.Download(name); await PluginUpdater.Download(name);
@@ -94,7 +94,7 @@ public class PluginLoader
//Save the new config file (after the updates) //Save the new config file (after the updates)
Config.SaveConfig(SaveType.NORMAL); await Config.SaveConfig(SaveType.NORMAL);
//Load all plugins //Load all plugins

View File

@@ -9,7 +9,7 @@ namespace PluginManager.Online.Helpers
{ {
public class VersionString public class VersionString
{ {
public int PackageID; public int PackageVersionID;
public int PackageMainVersion; public int PackageMainVersion;
public int PackageCheckVersion; public int PackageCheckVersion;
@@ -18,7 +18,7 @@ namespace PluginManager.Online.Helpers
string[] data = version.Split('.'); string[] data = version.Split('.');
try try
{ {
PackageID = int.Parse(data[0]); PackageVersionID = int.Parse(data[0]);
PackageMainVersion = int.Parse(data[1]); PackageMainVersion = int.Parse(data[1]);
PackageCheckVersion = int.Parse(data[2]); PackageCheckVersion = int.Parse(data[2]);
} }
@@ -28,21 +28,25 @@ namespace PluginManager.Online.Helpers
} }
} }
#region operators
public static bool operator >(VersionString s1, VersionString s2) public static bool operator >(VersionString s1, VersionString s2)
{ {
if (s1.PackageID != s2.PackageID) throw new Exception("Can not compare two different paks"); if (s1.PackageVersionID > s2.PackageVersionID) return true;
if (s1.PackageVersionID == s2.PackageVersionID)
{
if (s1.PackageMainVersion > s2.PackageMainVersion) return true; if (s1.PackageMainVersion > s2.PackageMainVersion) return true;
if (s1.PackageMainVersion == s2.PackageMainVersion && s1.PackageCheckVersion > s2.PackageCheckVersion) return true; if (s1.PackageMainVersion == s2.PackageMainVersion && s1.PackageCheckVersion > s2.PackageCheckVersion) return true;
}
return false; return false;
} }
#region operators
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 static bool operator ==(VersionString s1, VersionString s2) public static bool operator ==(VersionString s1, VersionString s2)
{ {
if (s1.PackageID == s2.PackageID && s1.PackageMainVersion == s2.PackageMainVersion && s1.PackageCheckVersion == s2.PackageCheckVersion) return true; if (s1.PackageVersionID == s2.PackageVersionID && s1.PackageMainVersion == s2.PackageMainVersion && s1.PackageCheckVersion == s2.PackageCheckVersion) return true;
return false; return false;
} }
@@ -55,12 +59,14 @@ namespace PluginManager.Online.Helpers
public override string ToString() public override string ToString()
{ {
return "{PackageID: " + PackageID + ", PackageVersion: " + PackageMainVersion + ", PackageCheckVersion: " + PackageCheckVersion + "}"; return "{PackageID: " + PackageVersionID + ", PackageVersion: " + PackageMainVersion + ", PackageCheckVersion: " + PackageCheckVersion + "}";
} }
public string ToShortString() public string ToShortString()
{ {
return $"{PackageID}.{PackageMainVersion}.{PackageCheckVersion}"; if (PackageVersionID == 0 && PackageCheckVersion == 0 && PackageMainVersion == 0)
return "Unknown";
return $"{PackageVersionID}.{PackageMainVersion}.{PackageCheckVersion}";
} }
public static VersionString? GetVersionOfPackage(string pakName) public static VersionString? GetVersionOfPackage(string pakName)

View File

@@ -2,6 +2,7 @@
using System.Collections.Generic; using System.Collections.Generic;
using System.Threading.Tasks; using System.Threading.Tasks;
using PluginManager.Online.Helpers;
using PluginManager.Others; using PluginManager.Others;
using OperatingSystem = PluginManager.Others.OperatingSystem; using OperatingSystem = PluginManager.Others.OperatingSystem;
@@ -39,7 +40,7 @@ public class PluginsManager
var op = Functions.GetOperatingSystem(); var op = Functions.GetOperatingSystem();
var len = lines.Length; var len = lines.Length;
string[] titles = { "Name", "Description", "Plugin Type", "Libraries", "Installed" }; string[] titles = { "Name", "Description", "Type", "Version", "Installed" };
data.Add(new[] { "-", "-", "-", "-", "-" }); data.Add(new[] { "-", "-", "-", "-", "-" });
data.Add(titles); data.Add(titles);
data.Add(new[] { "-", "-", "-", "-", "-" }); data.Add(new[] { "-", "-", "-", "-", "-" });
@@ -56,11 +57,7 @@ public class PluginsManager
display[0] = content[0]; display[0] = content[0];
display[1] = content[1]; display[1] = content[1];
display[2] = content[2]; display[2] = content[2];
if (content.Length == 6 && (content[5] != null || content[5].Length > 2)) display[3] = (await VersionString.GetVersionOfPackageFromWeb(content[0]) ?? new VersionString("0.0.0")).ToShortString();
display[3] = ((await ServerCom.ReadTextFromURL(content[5])).Count + 1).ToString();
else
display[3] = "1";
if (Config.PluginConfig.Contains(content[0]) || Config.PluginConfig.Contains(content[0])) if (Config.PluginConfig.Contains(content[0]) || Config.PluginConfig.Contains(content[0]))
display[4] = "✓"; display[4] = "✓";
else else
@@ -75,8 +72,7 @@ public class PluginsManager
display[0] = content[0]; display[0] = content[0];
display[1] = content[1]; display[1] = content[1];
display[2] = content[2]; display[2] = content[2];
if (content.Length == 6 && (content[5] != null || content[5].Length > 2)) display[3] = (await VersionString.GetVersionOfPackageFromWeb(content[0]) ?? new VersionString("0.0.0")).ToShortString();
display[3] = ((await ServerCom.ReadTextFromURL(content[5])).Count + 1).ToString();
if (Config.PluginConfig.Contains(content[0]) || Config.PluginConfig.Contains(content[0])) if (Config.PluginConfig.Contains(content[0]) || Config.PluginConfig.Contains(content[0]))
display[4] = "✓"; display[4] = "✓";
else else

View File

@@ -54,7 +54,7 @@ namespace PluginManager.Online
bool isDownloading = true; bool isDownloading = true;
float c_progress = 0; float c_progress = 0;
Console_Utilities.ProgressBar pbar = new Console_Utilities.ProgressBar { Max = 100f, NoColor = true }; Console_Utilities.ProgressBar pbar = new Console_Utilities.ProgressBar(ProgressBarType.NORMAL) { Max = 100f, NoColor = true };
IProgress<float> progress = new Progress<float>(percent => { c_progress = percent; }); IProgress<float> progress = new Progress<float>(percent => { c_progress = percent; });
@@ -63,7 +63,7 @@ namespace PluginManager.Online
{ {
while (isDownloading) while (isDownloading)
{ {
pbar.Update(ProgressBarType.NORMAL, c_progress); pbar.Update(c_progress);
if (c_progress == 100f) if (c_progress == 100f)
break; break;
Thread.Sleep(500); Thread.Sleep(500);
@@ -76,7 +76,7 @@ namespace PluginManager.Online
c_progress = pbar.Max; c_progress = pbar.Max;
pbar.Update(ProgressBarType.NORMAL, 100f); pbar.Update(100f);
isDownloading = false; isDownloading = false;
} }
} }

View File

@@ -2,7 +2,6 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq;
namespace PluginManager.Others namespace PluginManager.Others
{ {
@@ -33,15 +32,21 @@ namespace PluginManager.Others
/// </summary> /// </summary>
public class ProgressBar public class ProgressBar
{ {
public ProgressBar(ProgressBarType type)
{
this.type = type;
}
public float Max { get; init; } public float Max { get; init; }
public ConsoleColor Color { get; init; } public ConsoleColor Color { get; init; }
public bool NoColor { get; init; } public bool NoColor { get; init; }
public ProgressBarType type { get; 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;
public void Update(ProgressBarType type, float progress) public void Update(float progress)
{ {
switch (type) switch (type)
{ {
@@ -52,6 +57,8 @@ namespace PluginManager.Others
if (progress <= 99.9f) if (progress <= 99.9f)
UpdateNoEnd(); UpdateNoEnd();
return; return;
default:
return;
} }
} }
@@ -81,6 +88,8 @@ namespace PluginManager.Others
Console.CursorLeft = 1; Console.CursorLeft = 1;
float onechunk = 30.0f / Max; float onechunk = 30.0f / Max;
int position = 1;
for (int i = 0; i < onechunk * progress; i++) for (int i = 0; i < onechunk * progress; i++)
{ {
Console.BackgroundColor = NoColor ? ConsoleColor.Black : this.Color; Console.BackgroundColor = NoColor ? ConsoleColor.Black : this.Color;
@@ -88,14 +97,14 @@ namespace PluginManager.Others
Console.Write("#"); Console.Write("#");
} }
for (int i = position; i <= BarLength - 1; i++) for (int i = position; i < BarLength; i++)
{ {
Console.BackgroundColor = NoColor ? ConsoleColor.Black : ConsoleColor.DarkGray; Console.BackgroundColor = NoColor ? ConsoleColor.Black : ConsoleColor.DarkGray;
Console.CursorLeft = position++; Console.CursorLeft = position++;
Console.Write(" "); Console.Write(" ");
} }
Console.CursorLeft = 35; Console.CursorLeft = BarLength + 4;
Console.BackgroundColor = ConsoleColor.Black; Console.BackgroundColor = ConsoleColor.Black;
if (progress.CanAproximateTo(Max)) if (progress.CanAproximateTo(Max))
Console.Write(progress + " % ✓"); Console.Write(progress + " % ✓");