Code cleanup
This commit is contained in:
@@ -1,51 +1,51 @@
|
||||
using PluginManager.Items;
|
||||
using PluginManager.Online.Helpers;
|
||||
using System;
|
||||
using System.Threading.Tasks;
|
||||
using PluginManager.Items;
|
||||
using PluginManager.Others;
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Threading.Tasks;
|
||||
namespace PluginManager.Online.Updates;
|
||||
|
||||
namespace PluginManager.Online.Updates
|
||||
public class PluginUpdater
|
||||
{
|
||||
public class PluginUpdater
|
||||
public static async Task<bool> CheckForUpdates(string pakName)
|
||||
{
|
||||
public static async Task<bool> CheckForUpdates(string pakName)
|
||||
try
|
||||
{
|
||||
try
|
||||
{
|
||||
var webV = await Online.ServerCom.GetVersionOfPackageFromWeb(pakName);
|
||||
var local = Online.ServerCom.GetVersionOfPackage(pakName);
|
||||
var webV = await ServerCom.GetVersionOfPackageFromWeb(pakName);
|
||||
var local = ServerCom.GetVersionOfPackage(pakName);
|
||||
|
||||
if (local is null) return true;
|
||||
if (webV is null) return false;
|
||||
if (local is null) return true;
|
||||
if (webV is null) return false;
|
||||
|
||||
if (webV == local) return false;
|
||||
if (webV > local) return true;
|
||||
}
|
||||
catch (Exception ex) { Console.WriteLine(ex.Message); }
|
||||
|
||||
|
||||
return false;
|
||||
if (webV == local) return false;
|
||||
if (webV > local) return true;
|
||||
}
|
||||
|
||||
public static async Task<Update> DownloadUpdateInfo(string pakName)
|
||||
catch (Exception ex)
|
||||
{
|
||||
string url = "https://raw.githubusercontent.com/Wizzy69/installer/discord-bot-files/Versions";
|
||||
List<string> info = await ServerCom.ReadTextFromURL(url);
|
||||
VersionString? version = await Online.ServerCom.GetVersionOfPackageFromWeb(pakName);
|
||||
|
||||
if (version is null) return Update.Empty;
|
||||
Update update = new Update(pakName, string.Join('\n', info), version);
|
||||
return update;
|
||||
}
|
||||
|
||||
public static async Task Download(string pakName)
|
||||
{
|
||||
Console_Utilities.WriteColorText("An update was found for &g" + pakName + "&c. Version: &r" + (await Online.ServerCom.GetVersionOfPackageFromWeb(pakName))?.ToShortString() + "&c. Current Version: &y" + Online.ServerCom.GetVersionOfPackage(pakName)?.ToShortString());
|
||||
await ConsoleCommandsHandler.ExecuteCommad("dwplug " + pakName);
|
||||
Console.WriteLine(ex.Message);
|
||||
}
|
||||
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public static async Task<Update> DownloadUpdateInfo(string pakName)
|
||||
{
|
||||
var url = "https://raw.githubusercontent.com/Wizzy69/installer/discord-bot-files/Versions";
|
||||
var info = await ServerCom.ReadTextFromURL(url);
|
||||
var version = await ServerCom.GetVersionOfPackageFromWeb(pakName);
|
||||
|
||||
if (version is null) return Update.Empty;
|
||||
var update = new Update(pakName, string.Join('\n', info), version);
|
||||
return update;
|
||||
}
|
||||
|
||||
public static async Task Download(string pakName)
|
||||
{
|
||||
Console_Utilities.WriteColorText("An update was found for &g" + pakName + "&c. Version: &r" +
|
||||
(await ServerCom.GetVersionOfPackageFromWeb(pakName))?.ToShortString() +
|
||||
"&c. Current Version: &y" +
|
||||
ServerCom.GetVersionOfPackage(pakName)?.ToShortString());
|
||||
await ConsoleCommandsHandler.ExecuteCommad("dwplug " + pakName);
|
||||
}
|
||||
}
|
||||
@@ -1,36 +1,34 @@
|
||||
using PluginManager.Online.Helpers;
|
||||
using System;
|
||||
using PluginManager.Online.Helpers;
|
||||
|
||||
namespace PluginManager.Online.Updates
|
||||
namespace PluginManager.Online.Updates;
|
||||
|
||||
public class Update
|
||||
{
|
||||
public class Update
|
||||
public static Update Empty = new(null, null, null);
|
||||
|
||||
private readonly bool isEmpty;
|
||||
|
||||
public VersionString newVersion;
|
||||
public string pakName;
|
||||
public string UpdateMessage;
|
||||
|
||||
public Update(string pakName, string updateMessage, VersionString newVersion)
|
||||
{
|
||||
public static Update Empty = new Update(null, null, null);
|
||||
public string pakName;
|
||||
public string UpdateMessage;
|
||||
|
||||
public VersionString newVersion;
|
||||
|
||||
private bool isEmpty;
|
||||
|
||||
public Update(string pakName, string updateMessage, VersionString newVersion)
|
||||
{
|
||||
this.pakName = pakName;
|
||||
UpdateMessage = updateMessage;
|
||||
this.newVersion = newVersion;
|
||||
|
||||
if (pakName is null && updateMessage is null && newVersion is null)
|
||||
isEmpty = true;
|
||||
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
if (isEmpty)
|
||||
throw new System.Exception("The update is EMPTY. Can not print information about an empty update !");
|
||||
return $"Package Name: {this.pakName}\n" +
|
||||
$"Update Message: {UpdateMessage}\n" +
|
||||
$"Version: {newVersion.ToString()}";
|
||||
}
|
||||
this.pakName = pakName;
|
||||
UpdateMessage = updateMessage;
|
||||
this.newVersion = newVersion;
|
||||
|
||||
if (pakName is null && updateMessage is null && newVersion is null)
|
||||
isEmpty = true;
|
||||
}
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
if (isEmpty)
|
||||
throw new Exception("The update is EMPTY. Can not print information about an empty update !");
|
||||
return $"Package Name: {pakName}\n" +
|
||||
$"Update Message: {UpdateMessage}\n" +
|
||||
$"Version: {newVersion}";
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user