Fixed some text and added some missing texts to commands. Added new command to clear screen and formated code.
This commit is contained in:
@@ -3,7 +3,6 @@ using System.IO;
|
||||
using System.Net.Http;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
using PluginManager.Others;
|
||||
|
||||
namespace PluginManager.Online.Helpers;
|
||||
@@ -19,10 +18,11 @@ internal static class OnlineFunctions
|
||||
/// <param name="progress">The <see cref="IProgress{T}" /> that is used to track the download progress</param>
|
||||
/// <param name="cancellation">The cancellation token</param>
|
||||
/// <returns></returns>
|
||||
internal static async Task DownloadFileAsync(this HttpClient client, string url, Stream destination,
|
||||
IProgress<float>? progress = null,
|
||||
IProgress<long>? downloadedBytes = null, int bufferSize = 81920,
|
||||
CancellationToken cancellation = default)
|
||||
internal static async Task DownloadFileAsync(
|
||||
this HttpClient client, string url, Stream destination,
|
||||
IProgress<float>? progress = null,
|
||||
IProgress<long>? downloadedBytes = null, int bufferSize = 81920,
|
||||
CancellationToken cancellation = default)
|
||||
{
|
||||
using (var response = await client.GetAsync(url, HttpCompletionOption.ResponseHeadersRead, cancellation))
|
||||
{
|
||||
@@ -40,11 +40,12 @@ internal static class OnlineFunctions
|
||||
|
||||
// Convert absolute progress (bytes downloaded) into relative progress (0% - 100%)
|
||||
var relativeProgress = new Progress<long>(totalBytes =>
|
||||
{
|
||||
progress?.Report((float)totalBytes / contentLength.Value * 100);
|
||||
downloadedBytes?.Report(totalBytes);
|
||||
}
|
||||
);
|
||||
{
|
||||
progress?.Report((float)totalBytes / contentLength.Value *
|
||||
100);
|
||||
downloadedBytes?.Report(totalBytes);
|
||||
}
|
||||
);
|
||||
|
||||
// Use extension method to report progress while downloading
|
||||
await download.CopyToOtherStreamAsync(destination, bufferSize, relativeProgress, cancellation);
|
||||
@@ -64,4 +65,4 @@ internal static class OnlineFunctions
|
||||
using var client = new HttpClient();
|
||||
return await client.GetStringAsync(url, cancellation);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,24 +4,6 @@ namespace PluginManager.Online.Helpers;
|
||||
|
||||
public class VersionString
|
||||
{
|
||||
private bool Equals(VersionString other)
|
||||
{
|
||||
return PackageCheckVersion == other.PackageCheckVersion && PackageMainVersion == other.PackageMainVersion && PackageVersionID == other.PackageVersionID;
|
||||
}
|
||||
|
||||
public override bool Equals(object? obj)
|
||||
{
|
||||
if (ReferenceEquals(null, obj)) return false;
|
||||
if (ReferenceEquals(this, obj)) return true;
|
||||
if (obj.GetType() != this.GetType()) return false;
|
||||
return Equals((VersionString)obj);
|
||||
}
|
||||
|
||||
public override int GetHashCode()
|
||||
{
|
||||
return HashCode.Combine(PackageCheckVersion, PackageMainVersion, PackageVersionID);
|
||||
}
|
||||
|
||||
public int PackageCheckVersion;
|
||||
public int PackageMainVersion;
|
||||
public int PackageVersionID;
|
||||
@@ -33,20 +15,21 @@ public class VersionString
|
||||
{
|
||||
if (data.Length == 3)
|
||||
{
|
||||
PackageVersionID = int.Parse(data[0]);
|
||||
PackageMainVersion = int.Parse(data[1]);
|
||||
PackageVersionID = int.Parse(data[0]);
|
||||
PackageMainVersion = int.Parse(data[1]);
|
||||
PackageCheckVersion = int.Parse(data[2]);
|
||||
}
|
||||
else if (data.Length == 4)
|
||||
{
|
||||
// ignore the first item data[0]
|
||||
PackageVersionID = int.Parse(data[1]);
|
||||
PackageMainVersion = int.Parse(data[2]);
|
||||
PackageVersionID = int.Parse(data[1]);
|
||||
PackageMainVersion = int.Parse(data[2]);
|
||||
PackageCheckVersion = int.Parse(data[3]);
|
||||
}
|
||||
else
|
||||
else
|
||||
{
|
||||
throw new Exception("Invalid version string");
|
||||
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
@@ -55,6 +38,25 @@ public class VersionString
|
||||
}
|
||||
}
|
||||
|
||||
private bool Equals(VersionString other)
|
||||
{
|
||||
return PackageCheckVersion == other.PackageCheckVersion && PackageMainVersion == other.PackageMainVersion &&
|
||||
PackageVersionID == other.PackageVersionID;
|
||||
}
|
||||
|
||||
public override bool Equals(object? obj)
|
||||
{
|
||||
if (ReferenceEquals(null, obj)) return false;
|
||||
if (ReferenceEquals(this, obj)) return true;
|
||||
if (obj.GetType() != GetType()) return false;
|
||||
return Equals((VersionString)obj);
|
||||
}
|
||||
|
||||
public override int GetHashCode()
|
||||
{
|
||||
return HashCode.Combine(PackageCheckVersion, PackageMainVersion, PackageVersionID);
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return "{PackageID: " + PackageVersionID + ", PackageVersion: " + PackageMainVersion +
|
||||
@@ -112,4 +114,4 @@ public class VersionString
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,10 +1,8 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
using PluginManager.Online.Helpers;
|
||||
using PluginManager.Others;
|
||||
|
||||
using OperatingSystem = PluginManager.Others.OperatingSystem;
|
||||
|
||||
namespace PluginManager.Online;
|
||||
@@ -18,7 +16,7 @@ public class PluginsManager
|
||||
/// <param name="vlink">The link to the file where all plugin versions are stored</param>
|
||||
public PluginsManager(string plink, string vlink)
|
||||
{
|
||||
PluginsLink = plink;
|
||||
PluginsLink = plink;
|
||||
VersionsLink = vlink;
|
||||
}
|
||||
|
||||
@@ -26,7 +24,8 @@ public class PluginsManager
|
||||
/// The URL of the server
|
||||
/// </summary>
|
||||
public string PluginsLink { get; }
|
||||
public string VersionsLink {get; }
|
||||
|
||||
public string VersionsLink { get; }
|
||||
|
||||
/// <summary>
|
||||
/// The method to load all plugins
|
||||
@@ -36,11 +35,11 @@ public class PluginsManager
|
||||
{
|
||||
try
|
||||
{
|
||||
var list = await ServerCom.ReadTextFromURL(PluginsLink);
|
||||
var list = await ServerCom.ReadTextFromURL(PluginsLink);
|
||||
var lines = list.ToArray();
|
||||
|
||||
var data = new List<string[]>();
|
||||
var op = Functions.GetOperatingSystem();
|
||||
var op = Functions.GetOperatingSystem();
|
||||
|
||||
var len = lines.Length;
|
||||
for (var i = 0; i < len; i++)
|
||||
@@ -58,7 +57,7 @@ public class PluginsManager
|
||||
display[2] = content[2];
|
||||
display[3] =
|
||||
(await GetVersionOfPackageFromWeb(content[0]) ?? new VersionString("0.0.0"))
|
||||
.ToShortString();
|
||||
.ToShortString();
|
||||
data.Add(display);
|
||||
}
|
||||
}
|
||||
@@ -71,7 +70,7 @@ public class PluginsManager
|
||||
display[2] = content[2];
|
||||
display[3] =
|
||||
(await GetVersionOfPackageFromWeb(content[0]) ?? new VersionString("0.0.0"))
|
||||
.ToShortString();
|
||||
.ToShortString();
|
||||
data.Add(display);
|
||||
}
|
||||
}
|
||||
@@ -83,7 +82,8 @@ public class PluginsManager
|
||||
}
|
||||
catch (Exception exception)
|
||||
{
|
||||
Config.Logger.Log("Failed to execute command: listplugs\nReason: " + exception.Message, this, LogLevel.ERROR);
|
||||
Config.Logger.Log("Failed to execute command: listplugs\nReason: " + exception.Message, this,
|
||||
LogLevel.ERROR);
|
||||
}
|
||||
|
||||
return null;
|
||||
@@ -97,14 +97,15 @@ public class PluginsManager
|
||||
if (item.StartsWith("#"))
|
||||
continue;
|
||||
|
||||
string[] split = item.Split(',');
|
||||
var split = item.Split(',');
|
||||
if (split[0] == pakName)
|
||||
{
|
||||
Console.WriteLine("Searched for " + pakName + " and found " + split[1] + " as version.\nUsed url: " + VersionsLink);
|
||||
Console.WriteLine("Searched for " + pakName + " and found " + split[1] + " as version.\nUsed url: " +
|
||||
VersionsLink);
|
||||
return new VersionString(split[1]);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -117,9 +118,9 @@ public class PluginsManager
|
||||
{
|
||||
try
|
||||
{
|
||||
var list = await ServerCom.ReadTextFromURL(PluginsLink);
|
||||
var list = await ServerCom.ReadTextFromURL(PluginsLink);
|
||||
var lines = list.ToArray();
|
||||
var len = lines.Length;
|
||||
var len = lines.Length;
|
||||
for (var i = 0; i < len; i++)
|
||||
{
|
||||
var contents = lines[i].Split(',');
|
||||
@@ -135,7 +136,8 @@ public class PluginsManager
|
||||
}
|
||||
catch (Exception exception)
|
||||
{
|
||||
Config.Logger.Log("Failed to execute command: listplugs\nReason: " + exception.Message, this, LogLevel.ERROR);
|
||||
Config.Logger.Log("Failed to execute command: listplugs\nReason: " + exception.Message, this,
|
||||
LogLevel.ERROR);
|
||||
}
|
||||
|
||||
return null;
|
||||
|
||||
@@ -1,13 +1,10 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Net.Http;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using System.Collections.Generic;
|
||||
|
||||
using PluginManager.Online.Helpers;
|
||||
using PluginManager.Others;
|
||||
|
||||
namespace PluginManager.Online;
|
||||
|
||||
@@ -21,7 +18,7 @@ public static class ServerCom
|
||||
public static async Task<List<string>> ReadTextFromURL(string link)
|
||||
{
|
||||
var response = await OnlineFunctions.DownloadStringAsync(link);
|
||||
var lines = response.Split('\n');
|
||||
var lines = response.Split('\n');
|
||||
return lines.ToList();
|
||||
}
|
||||
|
||||
@@ -32,8 +29,9 @@ public static class ServerCom
|
||||
/// <param name="location">The location where to store the downloaded data</param>
|
||||
/// <param name="progress">The <see cref="IProgress{T}" /> to track the download</param>
|
||||
/// <returns></returns>
|
||||
public static async Task DownloadFileAsync(string URL, string location, IProgress<float> progress,
|
||||
IProgress<long>? downloadedBytes)
|
||||
public static async Task DownloadFileAsync(
|
||||
string URL, string location, IProgress<float> progress,
|
||||
IProgress<long>? downloadedBytes)
|
||||
{
|
||||
using (var client = new HttpClient())
|
||||
{
|
||||
@@ -50,4 +48,4 @@ public static class ServerCom
|
||||
{
|
||||
await DownloadFileAsync(URl, location, progress, null);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user