0
mirror of https://github.com/sampletext32/ParkanPlayground.git synced 2025-06-18 15:49:47 +03:00

add export

This commit is contained in:
bird_egop
2024-11-15 20:29:02 +03:00
parent 465a7cb336
commit 3c47549fde
5 changed files with 84 additions and 7 deletions

38
NResLib/NResExporter.cs Normal file
View File

@ -0,0 +1,38 @@
namespace NResLib;
public class NResExporter
{
public static void Export(NResArchive archive, string directory, string nResPath)
{
var openedFileName = Path.GetFileName(nResPath)!;
var targetDirectoryPath = Path.Combine(directory, openedFileName);
if (!Directory.Exists(targetDirectoryPath))
{
Directory.CreateDirectory(targetDirectoryPath);
}
using var fs = new FileStream(nResPath, FileMode.Open);
foreach (var archiveFile in archive.Files)
{
fs.Seek(archiveFile.OffsetInFile, SeekOrigin.Begin);
var buffer = new byte[archiveFile.FileLength];
fs.ReadExactly(buffer, 0, archiveFile.FileLength);
var extension = Path.GetExtension(archiveFile.FileName);
var fileName = Path.GetFileNameWithoutExtension(archiveFile.FileName);
if (extension == "")
{
extension = ".bin";
}
var targetFilePath = Path.Combine(targetDirectoryPath, $"{archiveFile.Index}_{fileName}{extension}");
File.WriteAllBytes(targetFilePath, buffer);
}
}
}

View File

@ -24,7 +24,7 @@ public static class NResParser
}
var header = new NResArchiveHeader(
NRes: Encoding.ASCII.GetString(buffer[0..4]),
NRes: Encoding.ASCII.GetString(buffer[0..4]).TrimEnd('\0'),
Version: BinaryPrimitives.ReadInt32LittleEndian(buffer[4..8]),
FileCount: BinaryPrimitives.ReadInt32LittleEndian(buffer[8..12]),
TotalFileLengthBytes: BinaryPrimitives.ReadInt32LittleEndian(buffer[12..16])
@ -51,11 +51,11 @@ public static class NResParser
elements.Add(
new ListMetadataItem(
FileType: Encoding.ASCII.GetString(metaDataBuffer[..8]),
FileType: Encoding.ASCII.GetString(metaDataBuffer[..8]).TrimEnd('\0'),
Magic1: BinaryPrimitives.ReadInt32LittleEndian(metaDataBuffer[8..12]),
FileLength: BinaryPrimitives.ReadInt32LittleEndian(metaDataBuffer[12..16]),
Magic2: BinaryPrimitives.ReadInt32LittleEndian(metaDataBuffer[16..20]),
FileName: Encoding.ASCII.GetString(metaDataBuffer[20..40]),
FileName: Encoding.ASCII.GetString(metaDataBuffer[20..40]).TrimEnd('\0'),
Magic3: BinaryPrimitives.ReadInt32LittleEndian(metaDataBuffer[40..44]),
Magic4: BinaryPrimitives.ReadInt32LittleEndian(metaDataBuffer[44..48]),
Magic5: BinaryPrimitives.ReadInt32LittleEndian(metaDataBuffer[48..52]),