Updated Logger. Local plugin database has now only executable dependencies stored in the database
This commit is contained in:
@@ -11,7 +11,7 @@ namespace DiscordBotCore.Interfaces.Logger
|
||||
public string LogMessageFormat { get; set; }
|
||||
|
||||
public void Log(ILogMessage message);
|
||||
public void LogException(Exception exception, object Sender);
|
||||
public void LogException(Exception exception, object Sender, bool logFullStack = false);
|
||||
|
||||
public event EventHandler<FormattedMessage> OnFormattedLog;
|
||||
public event EventHandler<ILogMessage> OnRawLog;
|
||||
|
||||
@@ -1,9 +1,7 @@
|
||||
using System;
|
||||
using System.Collections.Frozen;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using System.Threading.Tasks;
|
||||
using DiscordBotCore.Others;
|
||||
using DiscordBotCore.Plugin;
|
||||
@@ -165,6 +163,9 @@ public class PluginManager
|
||||
File.Delete(dependency.Value);
|
||||
|
||||
await RemovePluginFromDatabase(pluginInfo.PluginName);
|
||||
|
||||
if (Directory.Exists($"Libraries/{pluginInfo.PluginName}"))
|
||||
Directory.Delete($"Libraries/{pluginInfo.PluginName}", true);
|
||||
}
|
||||
|
||||
public async Task<string> GetDependencyLocation(string dependencyName)
|
||||
@@ -177,7 +178,7 @@ public class PluginManager
|
||||
return plugin.ListOfDependancies[dependencyName];
|
||||
}
|
||||
|
||||
throw new Exception("Dependency not found");
|
||||
return string.Empty;
|
||||
}
|
||||
|
||||
public string GenerateDependencyLocation(string pluginName, string dependencyName)
|
||||
|
||||
@@ -71,9 +71,9 @@ namespace DiscordBotCore.Others.Logger
|
||||
return this;
|
||||
}
|
||||
|
||||
public static LogMessage CreateFromException(Exception exception, object Sender)
|
||||
public static LogMessage CreateFromException(Exception exception, object Sender, bool logFullStack)
|
||||
{
|
||||
LogMessage message = new LogMessage(exception.ToString(), Sender, LogType.ERROR);
|
||||
LogMessage message = new LogMessage(logFullStack? exception.ToString() : exception.Message, Sender, LogType.ERROR);
|
||||
return message;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -85,5 +85,5 @@ public sealed class Logger : ILogger
|
||||
public void Log(string message, LogType logType) => Log(new LogMessage(message, logType));
|
||||
public void Log(string message, object Sender) => Log(new LogMessage(message, Sender));
|
||||
public void Log(string message, object Sender, LogType type) => Log(new LogMessage(message, Sender, type));
|
||||
public void LogException(Exception exception, object Sender) => Log(LogMessage.CreateFromException(exception, Sender));
|
||||
public void LogException(Exception exception, object Sender, bool logFullStack = false) => Log(LogMessage.CreateFromException(exception, Sender, logFullStack));
|
||||
}
|
||||
|
||||
@@ -8,12 +8,14 @@ public class OnlineDependencyInfo
|
||||
public string DependencyName { get; private set; }
|
||||
public string DownloadLink { get; private set; }
|
||||
public string DownloadLocation { get; private set; }
|
||||
public bool IsExecutable { get; private set; }
|
||||
|
||||
[JsonConstructor]
|
||||
public OnlineDependencyInfo(string dependencyName, string downloadLink, string downloadLocation)
|
||||
public OnlineDependencyInfo(string dependencyName, string downloadLink, string downloadLocation, bool isExecutable)
|
||||
{
|
||||
DependencyName = dependencyName;
|
||||
DownloadLink = downloadLink;
|
||||
DownloadLocation = downloadLocation;
|
||||
IsExecutable = isExecutable;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text.Json.Serialization;
|
||||
@@ -37,6 +36,11 @@ public class PluginInfo
|
||||
|
||||
public static PluginInfo FromOnlineInfo(PluginOnlineInfo onlineInfo)
|
||||
{
|
||||
return new PluginInfo(onlineInfo.Name, onlineInfo.Version, onlineInfo.Dependencies.Select(dep => new KeyValuePair<string, string>(dep.DependencyName, dep.DownloadLocation)).ToDictionary());
|
||||
return new PluginInfo(onlineInfo.Name,
|
||||
onlineInfo.Version,
|
||||
onlineInfo.Dependencies
|
||||
.Where(dep => dep.IsExecutable)
|
||||
.Select(dep => new KeyValuePair<string, string>(dep.DependencyName, dep.DownloadLocation))
|
||||
.ToDictionary());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -43,7 +43,7 @@ public class PluginUpdater
|
||||
await ServerCom.DownloadFileAsync(pluginInfo.DownLoadLink, $"{DiscordBotCore.Application.CurrentApplication.ApplicationEnvironmentVariables["PluginFolder"]}/{pluginName}.dll", progressMeter);
|
||||
|
||||
foreach(OnlineDependencyInfo dependency in pluginInfo.Dependencies)
|
||||
await ServerCom.DownloadFileAsync(dependency.DownloadLocation, dependency.DownloadLocation, progressMeter);
|
||||
await ServerCom.DownloadFileAsync(dependency.DownloadLink, dependency.DownloadLocation, progressMeter);
|
||||
|
||||
await _PluginsManager.RemovePluginFromDatabase(pluginName);
|
||||
await _PluginsManager.AppendPluginToDatabase(PluginInfo.FromOnlineInfo(pluginInfo));
|
||||
|
||||
Reference in New Issue
Block a user