update logging and add pl splash as the main one
All checks were successful
Build / Build Launcher (push) Successful in 2m31s
All checks were successful
Build / Build Launcher (push) Successful in 2m31s
This commit is contained in:
@@ -1,9 +1,11 @@
|
||||
using System.Collections;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.IO.Compression;
|
||||
using System.Xml.Serialization;
|
||||
using PluginLoader.Data;
|
||||
using PluginLoader.Network;
|
||||
using ProtoBuf;
|
||||
using ProtoBuf.Meta;
|
||||
|
||||
namespace PluginLoader;
|
||||
|
||||
@@ -20,13 +22,13 @@ public class PluginList : IEnumerable<PluginData>
|
||||
|
||||
if (plugins.Count == 0)
|
||||
{
|
||||
LogFile.WriteLine("WARNING: No plugins in the plugin list. Plugin list will contain local plugins only.");
|
||||
LogFile.Log.Warn("WARNING: No plugins in the plugin list. Plugin list will contain local plugins only.");
|
||||
HasError = true;
|
||||
}
|
||||
|
||||
FindWorkshopPlugins(config);
|
||||
FindLocalPlugins(config, mainDirectory);
|
||||
LogFile.WriteLine($"Found {plugins.Count} plugins");
|
||||
LogFile.Log.Debug($"Found {plugins.Count} plugins");
|
||||
FindPluginGroups();
|
||||
FindModDependencies();
|
||||
}
|
||||
@@ -92,7 +94,7 @@ public class PluginList : IEnumerable<PluginData>
|
||||
}
|
||||
|
||||
if (groups > 0)
|
||||
LogFile.WriteLine($"Found {groups} plugin groups");
|
||||
LogFile.Log.Debug($"Found {groups} plugin groups");
|
||||
}
|
||||
|
||||
private void FindModDependencies()
|
||||
@@ -164,13 +166,13 @@ public class PluginList : IEnumerable<PluginData>
|
||||
plugins = list.ToDictionary(x => x.Id);
|
||||
}
|
||||
|
||||
private bool TryReadWhitelistFile(string file, out PluginData[] list)
|
||||
private bool TryReadWhitelistFile(string file, [NotNullWhen(true)] out PluginData[]? list)
|
||||
{
|
||||
list = null;
|
||||
|
||||
if (File.Exists(file) && new FileInfo(file).Length > 0)
|
||||
{
|
||||
LogFile.WriteLine("Reading whitelist from cache");
|
||||
LogFile.Log.Debug("Reading whitelist from cache");
|
||||
try
|
||||
{
|
||||
using (Stream binFile = File.OpenRead(file))
|
||||
@@ -178,17 +180,17 @@ public class PluginList : IEnumerable<PluginData>
|
||||
list = Serializer.Deserialize<PluginData[]>(binFile);
|
||||
}
|
||||
|
||||
LogFile.WriteLine("Whitelist retrieved from disk");
|
||||
LogFile.Log.Debug("Whitelist retrieved from disk");
|
||||
return true;
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
LogFile.WriteLine("Error while reading whitelist: " + e);
|
||||
LogFile.Log.Warn(e, "Error while reading whitelist");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
LogFile.WriteLine("No whitelist cache exists");
|
||||
LogFile.Log.Debug("No whitelist cache exists");
|
||||
}
|
||||
|
||||
return false;
|
||||
@@ -196,7 +198,6 @@ public class PluginList : IEnumerable<PluginData>
|
||||
|
||||
private bool TryDownloadWhitelistFile(string file, string hash, PluginConfig config, out PluginData[] list)
|
||||
{
|
||||
list = null;
|
||||
var newPlugins = new Dictionary<string, PluginData>();
|
||||
|
||||
try
|
||||
@@ -210,19 +211,16 @@ public class PluginList : IEnumerable<PluginData>
|
||||
if (!entry.FullName.EndsWith("xml", StringComparison.OrdinalIgnoreCase))
|
||||
continue;
|
||||
|
||||
using (var entryStream = entry.Open())
|
||||
using (var entryReader = new StreamReader(entryStream))
|
||||
using var entryStream = entry.Open();
|
||||
|
||||
try
|
||||
{
|
||||
try
|
||||
{
|
||||
var data = (PluginData)xml.Deserialize(entryReader);
|
||||
newPlugins[data.Id] = data;
|
||||
}
|
||||
catch (InvalidOperationException e)
|
||||
{
|
||||
LogFile.WriteLine("An error occurred while reading the plugin xml: " +
|
||||
(e.InnerException ?? e));
|
||||
}
|
||||
var data = (PluginData?)xml.Deserialize(entryStream) ?? throw new InvalidOperationException($"Deserialized data is null for {entry.FullName}");
|
||||
newPlugins[data.Id] = data;
|
||||
}
|
||||
catch (InvalidOperationException e)
|
||||
{
|
||||
LogFile.Log.Error(e, "An error occurred while reading the plugin xml");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -232,35 +230,30 @@ public class PluginList : IEnumerable<PluginData>
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
LogFile.WriteLine("Error while downloading whitelist: " + e);
|
||||
LogFile.Log.Error(e, "Error while downloading whitelist");
|
||||
throw;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
private bool TrySaveWhitelist(string file, PluginData[] list, string hash, PluginConfig config)
|
||||
{
|
||||
try
|
||||
{
|
||||
LogFile.WriteLine("Saving whitelist to disk");
|
||||
using (var mem = new MemoryStream())
|
||||
LogFile.Log.Debug("Saving whitelist to disk");
|
||||
using (var binFile = File.Create(file))
|
||||
{
|
||||
Serializer.Serialize(mem, list);
|
||||
using (Stream binFile = File.Create(file))
|
||||
{
|
||||
mem.WriteTo(binFile);
|
||||
}
|
||||
Serializer.Serialize(binFile, list);
|
||||
}
|
||||
|
||||
config.ListHash = hash;
|
||||
config.Save();
|
||||
|
||||
LogFile.WriteLine("Whitelist updated");
|
||||
LogFile.Log.Debug("Whitelist updated");
|
||||
return true;
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
LogFile.WriteLine("Error while saving whitelist: " + e);
|
||||
LogFile.Log.Error(e, "Error while saving whitelist");
|
||||
try
|
||||
{
|
||||
File.Delete(file);
|
||||
@@ -289,7 +282,7 @@ public class PluginList : IEnumerable<PluginData>
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
LogFile.WriteLine("Error while downloading whitelist hash: " + e);
|
||||
LogFile.Log.Debug("Error while downloading whitelist hash: " + e);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -318,7 +311,7 @@ public class PluginList : IEnumerable<PluginData>
|
||||
{
|
||||
var steamPlugins = new List<ISteamItem>(plugins.Values.Select(x => x as ISteamItem).Where(x => x != null));
|
||||
|
||||
Main.Instance.Splash.SetText("Updating workshop items...");
|
||||
Main.Instance.Splash?.SetText("Updating workshop items...");
|
||||
|
||||
SteamAPI.Update(steamPlugins.Where(x => config.IsEnabled(x.Id)).Select(x => x.WorkshopId));
|
||||
|
||||
@@ -335,12 +328,12 @@ public class PluginList : IEnumerable<PluginData>
|
||||
else if (config.IsEnabled(steam.Id))
|
||||
{
|
||||
((PluginData)steam).Status = PluginStatus.Error;
|
||||
LogFile.WriteLine($"The plugin '{steam}' is missing and cannot be loaded.");
|
||||
LogFile.Log.Debug($"The plugin '{steam}' is missing and cannot be loaded.");
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
LogFile.WriteLine($"An error occurred while searching for the workshop plugin {steam}: {e}");
|
||||
LogFile.Log.Debug($"An error occurred while searching for the workshop plugin {steam}: {e}");
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user