-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
93 additions
and
13 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
10 changes: 10 additions & 0 deletions
10
src/StarBreaker.Cli/ChfCommands/StarBreakerSerializerContext.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,10 @@ | ||
using System.Text.Json.Serialization; | ||
|
||
namespace StarBreaker.Chf; | ||
|
||
[JsonSourceGenerationOptions(WriteIndented = true, UseStringEnumConverter = true)] | ||
[JsonSerializable(typeof(DownloadCommand.SccRoot))] | ||
[JsonSerializable(typeof(DownloadCommand.SccBody))] | ||
[JsonSerializable(typeof(DownloadCommand.SccCharacter))] | ||
[JsonSerializable(typeof(StarCitizenCharacter))] | ||
internal partial class StarBreakerSerializerContext : JsonSerializerContext; |
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,23 @@ | ||
using StarBreaker.CryXmlB; | ||
|
||
namespace StarBreaker.P4k; | ||
|
||
public sealed class CryXmlProcessor : IFileProcessor | ||
{ | ||
public bool CanProcess(string entryName, Stream stream) | ||
{ | ||
if (stream.Length < 4) | ||
return false; | ||
|
||
Span<byte> test = stackalloc byte[4]; | ||
if (stream.Read(test) != 4) | ||
return false; | ||
|
||
return CryXml.IsCryXmlB(test); | ||
} | ||
|
||
public void ProcessEntry(string outputRootFolder, string entryName, Stream stream) | ||
{ | ||
throw new NotImplementedException(); | ||
} | ||
} |
15 changes: 15 additions & 0 deletions
15
src/StarBreaker.P4k/FileProcessing/GenericFileProcessor.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,15 @@ | ||
namespace StarBreaker.P4k; | ||
|
||
public sealed class GenericFileProcessor : IFileProcessor | ||
{ | ||
public bool CanProcess(string entryName, Stream stream) => true; | ||
|
||
public void ProcessEntry(string outputRootFolder, string entryName, Stream entryStream) | ||
{ | ||
var entryPath = Path.Combine(outputRootFolder, entryName); | ||
|
||
using var writeStream = new FileStream(entryPath, FileMode.Create, FileAccess.Write, FileShare.None); | ||
|
||
entryStream.CopyTo(writeStream); | ||
} | ||
} |
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,29 @@ | ||
using System.IO.Compression; | ||
|
||
namespace StarBreaker.P4k; | ||
|
||
public sealed class ZipFileProcessor : IFileProcessor | ||
{ | ||
public bool CanProcess(string entryName, Stream stream) | ||
{ | ||
//todo: optimistic list of extensions? | ||
return entryName.EndsWith(".zip", StringComparison.OrdinalIgnoreCase); | ||
} | ||
|
||
public void ProcessEntry(string outputRootFolder, string entryName, Stream stream) | ||
{ | ||
var entryPath = Path.Combine(outputRootFolder, Path.ChangeExtension(entryName, "unzipped")); | ||
|
||
using var archive = new ZipArchive(stream, ZipArchiveMode.Read); | ||
foreach (var childEntry in archive.Entries) | ||
{ | ||
if (childEntry.Length == 0) | ||
continue; | ||
|
||
using var childStream = childEntry.Open(); | ||
|
||
var processor = FileProcessors.GetProcessor(childEntry.FullName, childStream); | ||
processor.ProcessEntry(entryPath, childEntry.FullName, childStream); | ||
} | ||
} | ||
} |
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