-
-
Notifications
You must be signed in to change notification settings - Fork 69
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added: Ability to allow package provider to set its own extractor.
- Loading branch information
Showing
11 changed files
with
129 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
37 changes: 37 additions & 0 deletions
37
source/Reloaded.Mod.Loader.Update/Providers/AggregatePackageResolverEx.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
using System.Collections.Generic; | ||
using System.Threading; | ||
using System.Threading.Tasks; | ||
using NuGet.Versioning; | ||
using Sewer56.Update.Extractors.SevenZipSharp; | ||
using Sewer56.Update.Interfaces; | ||
using Sewer56.Update.Packaging.Interfaces; | ||
using Sewer56.Update.Resolvers; | ||
|
||
namespace Reloaded.Mod.Loader.Update.Providers; | ||
|
||
/// <summary> | ||
/// Aggregate package resolver. | ||
/// </summary> | ||
public class AggregatePackageResolverEx : AggregatePackageResolver | ||
{ | ||
private readonly Dictionary<IPackageResolver, IPackageExtractor> _packageExtractors; | ||
|
||
/// <summary/> | ||
public AggregatePackageResolverEx(List<IPackageResolver> resolvers, Dictionary<IPackageResolver, IPackageExtractor> packageExtractors) : base(resolvers) | ||
{ | ||
_packageExtractors = packageExtractors; | ||
} | ||
|
||
/// <summary> | ||
/// Retrieves the package extractor to be used for removing packages. | ||
/// </summary> | ||
public async Task<IPackageExtractor> GetExtractorAsync(NuGetVersion version) | ||
{ | ||
var resolver = await GetResolverForVersionAsync(version, CancellationToken.None); | ||
if (_packageExtractors.TryGetValue(resolver.Resolver, out var extractor)) | ||
return extractor; | ||
|
||
// Fallback | ||
return new SevenZipSharpExtractor(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
32 changes: 32 additions & 0 deletions
32
source/Reloaded.Mod.Loader.Update/Providers/ProxyPackageExtractor.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading; | ||
using System.Threading.Tasks; | ||
using Sewer56.Update.Packaging.Interfaces; | ||
|
||
namespace Reloaded.Mod.Loader.Update.Providers; | ||
|
||
/// <summary> | ||
/// Package extractor that wraps a mutable inner extractor. | ||
/// </summary> | ||
public class ProxyPackageExtractor : IPackageExtractor | ||
{ | ||
/// <summary> | ||
/// The extractor wrapped by this proxy. | ||
/// </summary> | ||
public IPackageExtractor Extractor { get; set; } | ||
|
||
/// <summary> | ||
/// A proxy package extractor what wraps an external extractor. | ||
/// </summary> | ||
public ProxyPackageExtractor(IPackageExtractor extractor) => Extractor = extractor; | ||
|
||
/// <inheritdoc /> | ||
public async Task ExtractPackageAsync(string sourceFilePath, string destDirPath, IProgress<double>? progress = null, | ||
CancellationToken cancellationToken = new CancellationToken()) | ||
{ | ||
await Extractor.ExtractPackageAsync(sourceFilePath, destDirPath, progress, cancellationToken); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters