Skip to content

Commit

Permalink
新增mmc-pack导入支持
Browse files Browse the repository at this point in the history
  • Loading branch information
d3ara1n committed Jun 15, 2023
1 parent 75e21ac commit 0728070
Show file tree
Hide file tree
Showing 10 changed files with 100 additions and 12 deletions.
1 change: 1 addition & 0 deletions changelogs/v0.4.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

- **优化**增加主窗体初始尺寸
- **新增**更新整合包到指定版本(#20)
- **新增**支持Prism(mmc-pack)整合包导入

## v0.4.4

Expand Down
1 change: 1 addition & 0 deletions src/Polymerium.Abstractions/Importers/ImporterBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ public abstract class ImporterBase
public CancellationToken Token { get; set; }

public abstract Task<Result<ModpackContent, GameImportError>> ExtractMetadataAsync(
string fileName,
string indexContent,
IEnumerable<string> rawFileList,
Uri? source,
Expand Down
1 change: 1 addition & 0 deletions src/Polymerium.App/App.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ private IServiceProvider ConfigureServices()
configure
.Register<CurseForgeImporter>("manifest.json")
.Register<ModrinthImporter>("modrinth.index.json")
.Register<PrismImporter>("mmc-pack.json")
)
.AddSingleton<LocalizationService>();
// global services
Expand Down
1 change: 1 addition & 0 deletions src/Polymerium.App/Services/ImportService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ public async Task<Result<ImportResult, GameImportError>> ExtractMetadataFromFile
using var reader = new StreamReader(indexFileStream);
var indexFileContent = await reader.ReadToEndAsync();
var result = await importer.ExtractMetadataAsync(
filePath,
indexFileContent,
rawFileList,
reference,
Expand Down
1 change: 1 addition & 0 deletions src/Polymerium.Core/Importers/CurseForgeImporter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ public CurseForgeImporter(IMemoryCache cache, ResolveEngine resolver)
}

public override async Task<Result<ModpackContent, GameImportError>> ExtractMetadataAsync(
string fileName,
string indexContent,
IEnumerable<string> rawFileList,
Uri? source,
Expand Down
1 change: 1 addition & 0 deletions src/Polymerium.Core/Importers/ModrinthImporter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ public ModrinthImporter(IMemoryCache cache, ResolveEngine resolver)
}

public override async Task<Result<ModpackContent, GameImportError>> ExtractMetadataAsync(
string fileName,
string indexContent,
IEnumerable<string> rawFileList,
Uri? source,
Expand Down
53 changes: 53 additions & 0 deletions src/Polymerium.Core/Importers/PrismImporter.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
using DotNext;
using Newtonsoft.Json;
using Polymerium.Abstractions.Importers;
using Polymerium.Abstractions.Meta;
using Polymerium.Core.Models.Prism;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Polymerium.Core.Importers
{
public class PrismImporter : ImporterBase
{
public override Task<Result<ModpackContent, GameImportError>> ExtractMetadataAsync(string fileName, string indexContent, IEnumerable<string> rawFileList, Uri? source, bool forceOffline)
{
var model = JsonConvert.DeserializeObject<PrismModpackIndex>(indexContent);
var metadata = new GameMetadata();
foreach (var component in model.Components)
{
metadata.Components.Add(new Component()
{
Identity = component.Uid,
Version = component.Version
});
}
var list = new List<PackedSolidFile>();
foreach (var raw in rawFileList.Where(x => x.StartsWith("minecraft")))
{
var packed = new PackedSolidFile()
{
FileName = raw,
Path = Path.GetRelativePath("minecraft", raw)
};
list.Add(packed);
}
foreach (var raw in rawFileList.Where(x => x.StartsWith(".minecraft")))
{
var packed = new PackedSolidFile()
{
FileName = raw,
Path = Path.GetRelativePath(".minecraft", raw)
};
list.Add(packed);
}
var name = Path.GetFileNameWithoutExtension(fileName);
var version = Path.GetFileName(fileName);
return Task.FromResult(Finished(name, version, string.Empty, null, null, metadata, list));
}
}
}
15 changes: 15 additions & 0 deletions src/Polymerium.Core/Models/Prism/PrismModpackComponent.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Polymerium.Core.Models.Prism
{
public struct PrismModpackComponent
{
public bool? Important { get; set; }
public string Uid { get; set; }
public string Version { get; set; }
}
}
14 changes: 14 additions & 0 deletions src/Polymerium.Core/Models/Prism/PrismModpackIndex.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Polymerium.Core.Models.Prism
{
public struct PrismModpackIndex
{
public IEnumerable<PrismModpackComponent> Components { get; set; }
public uint FormatVersion { get; set; }
}
}
24 changes: 12 additions & 12 deletions src/Polymerium.Core/Polymerium.Core.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -13,21 +13,21 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="DotNext.Threading" Version="4.12.0"/>
<PackageReference Include="fNbt" Version="0.6.4"/>
<PackageReference Include="IBuilder" Version="0.1.0"/>
<PackageReference Include="Markdig" Version="0.31.0"/>
<PackageReference Include="Microsoft.Extensions.Caching.Abstractions" Version="7.0.0"/>
<PackageReference Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="7.0.0"/>
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="7.0.0"/>
<PackageReference Include="Tomlyn" Version="0.16.2"/>
<PackageReference Include="DotNext.Threading" Version="4.12.0" />
<PackageReference Include="fNbt" Version="0.6.4" />
<PackageReference Include="IBuilder" Version="0.1.0" />
<PackageReference Include="Markdig" Version="0.31.0" />
<PackageReference Include="Microsoft.Extensions.Caching.Abstractions" Version="7.0.0" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="7.0.0" />
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="7.0.0" />
<PackageReference Include="Tomlyn" Version="0.16.2" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\..\submodules\Duffet\src\Duffet\Duffet.csproj"/>
<ProjectReference Include="..\..\submodules\FluentPipeline\src\FluentPipeline\FluentPipeline.csproj"/>
<ProjectReference Include="..\..\submodules\Wupoo\src\Wupoo\Wupoo.csproj"/>
<ProjectReference Include="..\Polymerium.Abstractions\Polymerium.Abstractions.csproj"/>
<ProjectReference Include="..\..\submodules\Duffet\src\Duffet\Duffet.csproj" />
<ProjectReference Include="..\..\submodules\FluentPipeline\src\FluentPipeline\FluentPipeline.csproj" />
<ProjectReference Include="..\..\submodules\Wupoo\src\Wupoo\Wupoo.csproj" />
<ProjectReference Include="..\Polymerium.Abstractions\Polymerium.Abstractions.csproj" />
</ItemGroup>

</Project>

0 comments on commit 0728070

Please sign in to comment.