Implement Migration of PluginLoader configs (UI is temporary atm)
All checks were successful
Build / Compute Version (push) Successful in 5s
Build / Build Nuget package (CringeBootstrap.Abstractions) (push) Successful in 1m24s
Build / Build Nuget package (NuGet) (push) Successful in 2m8s
Build / Build Nuget package (CringePlugins) (push) Successful in 3m21s
Build / Build Nuget package (SharedCringe) (push) Successful in 2m32s
Build / Build Launcher (push) Successful in 3m31s

Add profiles to Config
Error handling for package resolution
Remove debug code from wndproc hook
This commit is contained in:
2024-11-09 18:23:40 -05:00
parent 2e4c7f5e15
commit c25bf3bb3d
9 changed files with 126 additions and 16 deletions

View File

@@ -1,7 +1,9 @@
using System.Collections.Immutable;
using System.Diagnostics;
using System.Text.Json;
using System.Xml.Serialization;
using CringePlugins.Abstractions;
using CringePlugins.Compatability;
using CringePlugins.Config;
using CringePlugins.Loader;
using CringePlugins.Resolver;
@@ -33,16 +35,18 @@ internal class PluginListComponent : IRenderComponent
private readonly PackageSourceMapping _sourceMapping;
private ImmutableHashSet<PackageSource>? _selectedSources;
private readonly string _configPath;
private readonly string _gameFolder;
private readonly ImmutableArray<PluginInstance> _plugins;
private (SearchResultEntry entry, NuGetClient client)? _selected;
private (PackageSource source, int index)? _selectedSource;
public PluginListComponent(PackagesConfig packagesConfig, PackageSourceMapping sourceMapping, string configPath,
public PluginListComponent(PackagesConfig packagesConfig, PackageSourceMapping sourceMapping, string configPath, string gameFolder,
ImmutableArray<PluginInstance> plugins)
{
_packagesConfig = packagesConfig;
_sourceMapping = sourceMapping;
_configPath = configPath;
_gameFolder = gameFolder;
_plugins = plugins;
_packages = packagesConfig.Packages.ToImmutableDictionary(b => b.Id, b => b.Range,
StringComparer.OrdinalIgnoreCase);
@@ -251,8 +255,20 @@ internal class PluginListComponent : IRenderComponent
if (BeginTabItem("Settings"))
{
//todo
Text("Todo");
var oldConfigPath = Path.Join(_gameFolder, "Plugins", "config.xml");
if (File.Exists(oldConfigPath) && Button("Migrate PluginLoader Config"))
{
var configSerializer = new XmlSerializer(typeof(PluginLoaderConfig));
using var fs = File.OpenRead(oldConfigPath);
if (configSerializer.Deserialize(fs) is PluginLoaderConfig oldConfig)
{
_packagesConfig = oldConfig.Migrate(_packagesConfig);
Save(false);
}
}
EndTabItem();
}
@@ -481,15 +497,15 @@ internal class PluginListComponent : IRenderComponent
_searchResults = builder.ToImmutable();
}
private void Save()
private void Save(bool keepPackages = true)
{
_changed = true;
using var stream = File.Create(_configPath);
JsonSerializer.Serialize(stream, _packagesConfig with
JsonSerializer.Serialize(stream, keepPackages ? _packagesConfig with
{
Packages = [.._packages.Select(b => new PackageReference(b.Key, b.Value))]
}, NuGetClient.SerializerOptions);
} : _packagesConfig, NuGetClient.SerializerOptions);
}
}