CLI zip file extract to memory
This commit is contained in:
parent
21b7671426
commit
eeb8f43d3d
@ -1,5 +1,9 @@
|
|||||||
using System.Text.Json;
|
using System.IO;
|
||||||
|
using System.IO.Compression;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text.Json;
|
||||||
using ParadoxSaveParser.Lib;
|
using ParadoxSaveParser.Lib;
|
||||||
|
using Path = DTLib.Filesystem.Path;
|
||||||
|
|
||||||
namespace ParadoxSaveParser.CLI;
|
namespace ParadoxSaveParser.CLI;
|
||||||
|
|
||||||
@ -12,7 +16,24 @@ internal static class Modes
|
|||||||
{
|
{
|
||||||
internal static void Search(string searchQuery, IOPath inputPath, IOPath? outputPath)
|
internal static void Search(string searchQuery, IOPath inputPath, IOPath? outputPath)
|
||||||
{
|
{
|
||||||
using var inputStream = File.OpenRead(inputPath);
|
Stream inputStream = File.OpenRead(inputPath);
|
||||||
|
try
|
||||||
|
{
|
||||||
|
byte[] head4 = new byte[4];
|
||||||
|
inputStream.ReadExactly(head4);
|
||||||
|
inputStream.Seek(0, SeekOrigin.Begin);
|
||||||
|
if (head4.SequenceEqual<byte>([(byte)'P', (byte)'K', 3, 4]))
|
||||||
|
{
|
||||||
|
var zipArchive = new ZipArchive(inputStream, ZipArchiveMode.Read);
|
||||||
|
var zipEntry = zipArchive.Entries.FirstOrDefault(e => e.Name == "gamestate");
|
||||||
|
if (zipEntry is null)
|
||||||
|
throw new Exception("'gamestate' file not found in zip archive");
|
||||||
|
var unzipped = new MemoryStream((int)zipEntry.Length);
|
||||||
|
zipEntry.Open().CopyTo(unzipped);
|
||||||
|
zipArchive.Dispose(); // closes inputStream
|
||||||
|
unzipped.Seek(0, SeekOrigin.Begin);
|
||||||
|
inputStream = unzipped;
|
||||||
|
}
|
||||||
|
|
||||||
using var outputStream = outputPath is null
|
using var outputStream = outputPath is null
|
||||||
? Console.OpenStandardOutput()
|
? Console.OpenStandardOutput()
|
||||||
@ -22,9 +43,15 @@ internal static class Modes
|
|||||||
|
|
||||||
var parser = new SaveParserEU4(inputStream, searchExpression);
|
var parser = new SaveParserEU4(inputStream, searchExpression);
|
||||||
var parsedValue = parser.Parse();
|
var parsedValue = parser.Parse();
|
||||||
JsonSerializer.Serialize(outputStream, parsedValue, ParsedValueJsonContext.Default.DictionaryStringListObject);
|
JsonSerializer.Serialize(outputStream, parsedValue,
|
||||||
|
ParsedValueJsonContext.Default.DictionaryStringListObject);
|
||||||
outputStream.WriteByte((byte)'\n');
|
outputStream.WriteByte((byte)'\n');
|
||||||
}
|
}
|
||||||
|
finally
|
||||||
|
{
|
||||||
|
inputStream.Dispose();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
internal static void Interactive()
|
internal static void Interactive()
|
||||||
{
|
{
|
||||||
|
|||||||
4
TODO.txt
4
TODO.txt
@ -1,6 +1,3 @@
|
|||||||
Parser.CLI:
|
|
||||||
Temp files management system
|
|
||||||
|
|
||||||
Main:
|
Main:
|
||||||
Temp files management system
|
Temp files management system
|
||||||
Database???
|
Database???
|
||||||
@ -11,4 +8,3 @@ ParseSaveHandler:
|
|||||||
Add debug log
|
Add debug log
|
||||||
Save parsed data in protobuf
|
Save parsed data in protobuf
|
||||||
Re-parse if saved data was parsed with another query
|
Re-parse if saved data was parsed with another query
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user