mirror of
https://github.com/sampletext32/ParkanPlayground.git
synced 2025-06-19 16:08:02 +03:00
add export
This commit is contained in:
38
NResLib/NResExporter.cs
Normal file
38
NResLib/NResExporter.cs
Normal 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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -24,7 +24,7 @@ public static class NResParser
|
|||||||
}
|
}
|
||||||
|
|
||||||
var header = new NResArchiveHeader(
|
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]),
|
Version: BinaryPrimitives.ReadInt32LittleEndian(buffer[4..8]),
|
||||||
FileCount: BinaryPrimitives.ReadInt32LittleEndian(buffer[8..12]),
|
FileCount: BinaryPrimitives.ReadInt32LittleEndian(buffer[8..12]),
|
||||||
TotalFileLengthBytes: BinaryPrimitives.ReadInt32LittleEndian(buffer[12..16])
|
TotalFileLengthBytes: BinaryPrimitives.ReadInt32LittleEndian(buffer[12..16])
|
||||||
@ -51,11 +51,11 @@ public static class NResParser
|
|||||||
|
|
||||||
elements.Add(
|
elements.Add(
|
||||||
new ListMetadataItem(
|
new ListMetadataItem(
|
||||||
FileType: Encoding.ASCII.GetString(metaDataBuffer[..8]),
|
FileType: Encoding.ASCII.GetString(metaDataBuffer[..8]).TrimEnd('\0'),
|
||||||
Magic1: BinaryPrimitives.ReadInt32LittleEndian(metaDataBuffer[8..12]),
|
Magic1: BinaryPrimitives.ReadInt32LittleEndian(metaDataBuffer[8..12]),
|
||||||
FileLength: BinaryPrimitives.ReadInt32LittleEndian(metaDataBuffer[12..16]),
|
FileLength: BinaryPrimitives.ReadInt32LittleEndian(metaDataBuffer[12..16]),
|
||||||
Magic2: BinaryPrimitives.ReadInt32LittleEndian(metaDataBuffer[16..20]),
|
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]),
|
Magic3: BinaryPrimitives.ReadInt32LittleEndian(metaDataBuffer[40..44]),
|
||||||
Magic4: BinaryPrimitives.ReadInt32LittleEndian(metaDataBuffer[44..48]),
|
Magic4: BinaryPrimitives.ReadInt32LittleEndian(metaDataBuffer[44..48]),
|
||||||
Magic5: BinaryPrimitives.ReadInt32LittleEndian(metaDataBuffer[48..52]),
|
Magic5: BinaryPrimitives.ReadInt32LittleEndian(metaDataBuffer[48..52]),
|
||||||
|
@ -8,6 +8,8 @@ public abstract class ImGuiModalPanel : IImGuiPanel
|
|||||||
{
|
{
|
||||||
protected abstract string ImGuiId { get; }
|
protected abstract string ImGuiId { get; }
|
||||||
|
|
||||||
|
protected Vector2 WindowSize { get; set; } = new Vector2(600, 400);
|
||||||
|
|
||||||
private bool _shouldOpen = false;
|
private bool _shouldOpen = false;
|
||||||
|
|
||||||
public virtual void Open()
|
public virtual void Open()
|
||||||
@ -27,7 +29,7 @@ public abstract class ImGuiModalPanel : IImGuiPanel
|
|||||||
_shouldOpen = false;
|
_shouldOpen = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
ImGui.SetNextWindowSize(new Vector2(600, 400));
|
ImGui.SetNextWindowSize(WindowSize);
|
||||||
|
|
||||||
if (ImGui.BeginPopup(ImGuiId, ImGuiWindowFlags.NoResize))
|
if (ImGui.BeginPopup(ImGuiId, ImGuiWindowFlags.NoResize))
|
||||||
{
|
{
|
||||||
|
@ -11,9 +11,11 @@ namespace NResUI.ImGuiUI
|
|||||||
{
|
{
|
||||||
private readonly ExplorerViewModel _explorerViewModel;
|
private readonly ExplorerViewModel _explorerViewModel;
|
||||||
|
|
||||||
public MainMenuBar(ExplorerViewModel explorerViewModel)
|
private readonly MessageBoxModalPanel _messageBox;
|
||||||
|
public MainMenuBar(ExplorerViewModel explorerViewModel, MessageBoxModalPanel messageBox)
|
||||||
{
|
{
|
||||||
_explorerViewModel = explorerViewModel;
|
_explorerViewModel = explorerViewModel;
|
||||||
|
_messageBox = messageBox;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void OnImGuiRender()
|
public void OnImGuiRender()
|
||||||
@ -46,7 +48,9 @@ namespace NResUI.ImGuiUI
|
|||||||
{
|
{
|
||||||
var path = result.Path;
|
var path = result.Path;
|
||||||
|
|
||||||
Console.WriteLine(path);
|
NResExporter.Export(_explorerViewModel.Archive!, path, _explorerViewModel.Path!);
|
||||||
|
|
||||||
|
_messageBox.Show("Успешно экспортировано");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
33
NResUI/ImGuiUI/MessageBoxModalPanel.cs
Normal file
33
NResUI/ImGuiUI/MessageBoxModalPanel.cs
Normal 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();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Reference in New Issue
Block a user