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]),

View File

@ -8,6 +8,8 @@ public abstract class ImGuiModalPanel : IImGuiPanel
{
protected abstract string ImGuiId { get; }
protected Vector2 WindowSize { get; set; } = new Vector2(600, 400);
private bool _shouldOpen = false;
public virtual void Open()
@ -27,7 +29,7 @@ public abstract class ImGuiModalPanel : IImGuiPanel
_shouldOpen = false;
}
ImGui.SetNextWindowSize(new Vector2(600, 400));
ImGui.SetNextWindowSize(WindowSize);
if (ImGui.BeginPopup(ImGuiId, ImGuiWindowFlags.NoResize))
{

View File

@ -11,9 +11,11 @@ namespace NResUI.ImGuiUI
{
private readonly ExplorerViewModel _explorerViewModel;
public MainMenuBar(ExplorerViewModel explorerViewModel)
private readonly MessageBoxModalPanel _messageBox;
public MainMenuBar(ExplorerViewModel explorerViewModel, MessageBoxModalPanel messageBox)
{
_explorerViewModel = explorerViewModel;
_messageBox = messageBox;
}
public void OnImGuiRender()
@ -45,8 +47,10 @@ namespace NResUI.ImGuiUI
if (result.IsOk)
{
var path = result.Path;
Console.WriteLine(path);
NResExporter.Export(_explorerViewModel.Archive!, path, _explorerViewModel.Path!);
_messageBox.Show("Успешно экспортировано");
}
}
}

View File

@ -0,0 +1,33 @@
using System.Numerics;
using ImGuiNET;
using NResUI.Abstractions;
namespace NResUI.ImGuiUI;
public class MessageBoxModalPanel : ImGuiModalPanel
{
private string? _text;
protected override string ImGuiId { get; } = "#message-box";
public MessageBoxModalPanel()
{
WindowSize = new Vector2(300, 150);
}
public void Show(string? text)
{
_text = text;
base.Open();
}
protected override void OnImGuiRenderContent()
{
ImGui.Text(_text);
ImGui.Spacing();
if (ImGui.Button("Ок"))
{
ImGui.CloseCurrentPopup();
}
}
}