Skip to content

Commit

Permalink
Feat | Check plugin.json In Zip && Unzip DllName Folder
Browse files Browse the repository at this point in the history
  • Loading branch information
kitUIN committed Dec 26, 2024
1 parent fd22766 commit 92e111e
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 20 deletions.
13 changes: 7 additions & 6 deletions ShadowPluginLoader.WinUI/AbstractPluginLoader.Assignable.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,10 @@ public void Import(Type type)
}
catch (PluginImportException e)
{
Logger?.Warning("{Pre}{Message}", LoggerPrefix, e.Message);
Logger.Warning("{Pre}{Message}", LoggerPrefix, e.Message);
}
}

/// <summary>
/// <inheritdoc />
/// </summary>
Expand All @@ -60,12 +61,14 @@ public async Task ImportFromZipAsync(string zipPath)
{
try
{
CheckPluginInZip(zipPath);
await ImportFromDirAsync(UnZip(PluginFolder, zipPath));
var meta = await CheckPluginInZip(zipPath);
var outPath = Path.Combine(PluginFolder, meta!.DllName);
Logger.Information("{t}",outPath);
await ImportFromDirAsync(await UnZip(zipPath, outPath));
}
catch (PluginImportException e)
{
Logger?.Warning("{Pre}{Message}", LoggerPrefix, e.Message);
Logger.Warning("{Pre}{Message}", LoggerPrefix, e.Message);
}
}

Expand Down Expand Up @@ -195,6 +198,4 @@ public void UpgradePlugin(string id)
{
// TODO
}


}
18 changes: 14 additions & 4 deletions ShadowPluginLoader.WinUI/AbstractPluginLoader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
using System.Threading.Tasks;
using ShadowPluginLoader.WinUI.Args;
using ShadowPluginLoader.WinUI.Enums;
using SharpCompress.Archives;
using SharpCompress.IO;
using Path = System.IO.Path;

namespace ShadowPluginLoader.WinUI;
Expand Down Expand Up @@ -249,20 +251,28 @@ protected virtual void LoadPluginDi(Type tPlugin, TAPlugin aPlugin, TMeta meta)
/// </summary>
/// <param name="zipPath">plugin zip path</param>
/// <exception cref="PluginImportException">Not Found plugin.json in zip</exception>
protected virtual void CheckPluginInZip(string zipPath)
protected virtual async Task<TMeta?> CheckPluginInZip(string zipPath)
{
using FileStream zipToOpen = new(zipPath, FileMode.Open);
await using FileStream zipToOpen = new(zipPath, FileMode.Open);
using ZipArchive archive = new(zipToOpen, ZipArchiveMode.Update);
var jsonEntry = archive.GetEntry(PluginJson) ??
throw new PluginImportException($"Not Found {PluginJson} in zip {zipPath}");
using var reader = new StreamReader(jsonEntry.Open());
var jsonContent = await reader.ReadToEndAsync();
Logger.Information("{Pre} plugin.json content: {Content}",
LoggerPrefix, jsonContent);
return JsonSerializer.Deserialize<TMeta>(jsonContent);
}

/// <summary>
/// UnZip
/// </summary>
protected virtual string UnZip(string zipPath, string outputPath)
protected virtual async Task<string> UnZip(string zipPath, string outputPath)
{
ZipFile.ExtractToDirectory(zipPath, outputPath, true);
await using var fStream = File.OpenRead(zipPath);
await using var stream = NonDisposingStream.Create(fStream);
using var archive = ArchiveFactory.Open(stream);
archive.ExtractToDirectory(outputPath);
return outputPath;
}
}
12 changes: 6 additions & 6 deletions ShadowPluginLoader.WinUI/DIFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@

namespace ShadowPluginLoader.WinUI;


/// <summary>
/// 依赖注入-工厂
/// </summary>
Expand All @@ -13,13 +12,14 @@ public static class DiFactory
/// 依赖注入-容器
/// </summary>
public static Container Services { get; }

static DiFactory()
{
Services = new Container(rules => rules.With(FactoryMethod.ConstructorWithResolvableArguments));
Services.Register(
Made.Of(() => Serilog.Log.ForContext(Arg.Index<Type>(0)), r => r.Parent.ImplementationType),
setup: Setup.With(condition: r => r.Parent.ImplementationType != null));
Services.Register<PluginEventService>(reuse:Reuse.Singleton);
Made.Of(() => Serilog.Log.ForContext(Arg.Index<Type>(0)),
r => r.ImplementationType ?? r.Parent.ImplementationType ?? typeof(object)),
setup: Setup.With(condition: r => r.Parent.ImplementationType != null || r.ImplementationType != null));
Services.Register<PluginEventService>(reuse: Reuse.Singleton);
}

}
}
3 changes: 1 addition & 2 deletions ShadowPluginLoader.WinUI/Helpers/SettingsHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@ public static void Set(string container, string key, object value)
ApplicationData.Current.LocalSettings.CreateContainer(container,
ApplicationDataCreateDisposition.Always);
coreSettings.Values[key] = value;
DiFactory.Services.Resolve<ILogger>().Debug("Container: {container} | [{key}] {value}",
container, key, value);
Log.Debug("Container: {container} | [{key}] {value}", container, key, value);
}
}
5 changes: 3 additions & 2 deletions ShadowPluginLoader.WinUI/ShadowPluginLoader.WinUI.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
<EnableMsixTooling>true</EnableMsixTooling>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<!-- Nuget -->
<Version>1.4.2</Version>
<Version>1.4.3</Version>
<PackageId>ShadowPluginLoader.WinUI</PackageId>
<Owner>kitUIN</Owner>
<Authors>kitUIN</Authors>
Expand All @@ -28,12 +28,13 @@

<ItemGroup>
<PackageReference Include="DryIoc.dll" Version="5.4.3" />
<PackageReference Include="Serilog" Version="4.1.0" />
<PackageReference Include="Serilog" Version="4.2.0" />
<PackageReference Include="Microsoft.WindowsAppSDK" Version="1.5.241107002" />
<PackageReference Include="Microsoft.Windows.SDK.BuildTools" Version="10.0.22621.756" />
<PackageReference Include="ShadowPluginLoader.SourceGenerator" Version="1.4.10" />
<PackageReference Include="kitUIN.CustomExtensions.WinUI" Version="0.6.3" />
<PackageReference Include="ShadowPluginLoader.Tool" Version="1.3.0" />
<PackageReference Include="SharpCompress" Version="0.38.0" />
</ItemGroup>
<ItemGroup>
<None Include="..\README.md" Pack="true" PackagePath="\" />
Expand Down

0 comments on commit 92e111e

Please sign in to comment.