2019-04-12 00:05:15 +02:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.IO;
|
|
|
|
|
using System.Text;
|
|
|
|
|
using System.Threading.Tasks;
|
2019-07-16 23:35:21 +02:00
|
|
|
|
using Toolbox;
|
2019-04-12 00:05:15 +02:00
|
|
|
|
using System.Windows.Forms;
|
2019-07-16 23:35:21 +02:00
|
|
|
|
using Toolbox.Library;
|
|
|
|
|
using Toolbox.Library.IO;
|
|
|
|
|
using Toolbox.Library.Forms;
|
2019-04-12 00:05:15 +02:00
|
|
|
|
|
|
|
|
|
namespace FirstPlugin
|
|
|
|
|
{
|
|
|
|
|
public class APAKFileInfo : ArchiveFileInfo
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
2019-05-08 22:28:04 +02:00
|
|
|
|
public class APAK : TreeNodeFile
|
2019-04-12 00:05:15 +02:00
|
|
|
|
{
|
|
|
|
|
public bool CanSave { get; set; }
|
|
|
|
|
public string[] Description { get; set; } = new string[] { "APAK" };
|
|
|
|
|
public string[] Extension { get; set; } = new string[] { "*.apak" };
|
|
|
|
|
public string FileName { get; set; }
|
|
|
|
|
public string FilePath { get; set; }
|
|
|
|
|
public IFileInfo IFileInfo { get; set; }
|
|
|
|
|
|
|
|
|
|
public bool Identify(System.IO.Stream stream)
|
|
|
|
|
{
|
2019-07-16 23:35:21 +02:00
|
|
|
|
using (var reader = new Toolbox.Library.IO.FileReader(stream, true))
|
2019-04-12 00:05:15 +02:00
|
|
|
|
{
|
|
|
|
|
return reader.CheckSignature(4, "APAK");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public Type[] Types
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
List<Type> types = new List<Type>();
|
|
|
|
|
return types.ToArray();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public IEnumerable<ArchiveFileInfo> Files { get; }
|
|
|
|
|
|
|
|
|
|
public bool CanAddFiles { get; set; } = true;
|
|
|
|
|
public bool CanRenameFiles { get; set; } = true;
|
|
|
|
|
public bool CanReplaceFiles { get; set; } = true;
|
|
|
|
|
public bool CanDeleteFiles { get; set; } = true;
|
|
|
|
|
|
|
|
|
|
public void Load(System.IO.Stream stream)
|
|
|
|
|
{
|
|
|
|
|
Text = FileName;
|
|
|
|
|
|
|
|
|
|
CanDelete = true;
|
|
|
|
|
|
|
|
|
|
using (var reader = new FileReader(stream))
|
|
|
|
|
{
|
|
|
|
|
reader.ByteOrder = Syroot.BinaryData.ByteOrder.BigEndian;
|
|
|
|
|
|
|
|
|
|
reader.ReadSignature(4, "APAK");
|
|
|
|
|
uint Version = reader.ReadUInt32();
|
|
|
|
|
uint FileCount = reader.ReadUInt32();
|
|
|
|
|
uint unk = reader.ReadUInt32();
|
|
|
|
|
uint unk2 = reader.ReadUInt32();
|
|
|
|
|
uint DataTotalSize = reader.ReadUInt32();
|
|
|
|
|
uint unk3 = reader.ReadUInt32();
|
|
|
|
|
|
|
|
|
|
for (int i = 0; i < FileCount; i++)
|
|
|
|
|
{
|
|
|
|
|
var info = new FileInfo(reader);
|
|
|
|
|
|
|
|
|
|
APAKFileInfo archive = new APAKFileInfo();
|
2019-05-12 02:51:23 +02:00
|
|
|
|
archive.FileData = info.Data;
|
2019-04-12 00:05:15 +02:00
|
|
|
|
archive.Name = info.Text;
|
|
|
|
|
|
|
|
|
|
Nodes.Add(info);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public class FileInfo : TreeNodeCustom
|
|
|
|
|
{
|
|
|
|
|
public byte[] Data;
|
|
|
|
|
|
|
|
|
|
public FileInfo()
|
|
|
|
|
{
|
|
|
|
|
ContextMenu = new ContextMenu();
|
|
|
|
|
MenuItem export = new MenuItem("Export Raw Data");
|
|
|
|
|
ContextMenu.MenuItems.Add(export);
|
|
|
|
|
export.Click += Export;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void Export(object sender, EventArgs args)
|
|
|
|
|
{
|
|
|
|
|
SaveFileDialog sfd = new SaveFileDialog();
|
|
|
|
|
sfd.FileName = Text;
|
|
|
|
|
sfd.DefaultExt = Path.GetExtension(Text);
|
|
|
|
|
sfd.Filter = "Raw Data (*.*)|*.*";
|
|
|
|
|
|
|
|
|
|
if (sfd.ShowDialog() == DialogResult.OK)
|
|
|
|
|
{
|
|
|
|
|
File.WriteAllBytes(sfd.FileName, Data);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override void OnClick(TreeView treeview)
|
|
|
|
|
{
|
2019-07-11 23:22:59 +02:00
|
|
|
|
HexEditor editor = (HexEditor)LibraryGUI.GetActiveContent(typeof(HexEditor));
|
2019-04-12 00:05:15 +02:00
|
|
|
|
if (editor == null)
|
|
|
|
|
{
|
|
|
|
|
editor = new HexEditor();
|
2019-07-11 23:22:59 +02:00
|
|
|
|
LibraryGUI.LoadEditor(editor);
|
2019-04-12 00:05:15 +02:00
|
|
|
|
}
|
|
|
|
|
editor.Text = Text;
|
|
|
|
|
editor.Dock = DockStyle.Fill;
|
|
|
|
|
editor.LoadData(Data);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public FileInfo(FileReader reader)
|
|
|
|
|
{
|
|
|
|
|
long pos = reader.Position;
|
|
|
|
|
|
|
|
|
|
uint dataOffset = reader.ReadUInt32();
|
|
|
|
|
uint uncompressedSize = reader.ReadUInt32();
|
|
|
|
|
uint compressedSize = reader.ReadUInt32();
|
|
|
|
|
uint unk = reader.ReadUInt32();
|
|
|
|
|
uint unk2 = reader.ReadUInt32();
|
|
|
|
|
uint unk3 = reader.ReadUInt32();
|
|
|
|
|
uint unk4 = reader.ReadUInt32();
|
|
|
|
|
|
|
|
|
|
uint FileOffset = reader.ReadUInt32();
|
|
|
|
|
uint FileSize = reader.ReadUInt32();
|
|
|
|
|
uint padding = reader.ReadUInt32();
|
|
|
|
|
|
|
|
|
|
// reader.Seek(NameOffset, System.IO.SeekOrigin.Begin);
|
|
|
|
|
Text = reader.ReadString(Syroot.BinaryData.BinaryStringFormat.ZeroTerminated);
|
|
|
|
|
|
|
|
|
|
reader.Seek(dataOffset, System.IO.SeekOrigin.Begin);
|
|
|
|
|
Data = reader.ReadBytes((int)compressedSize);
|
|
|
|
|
|
|
|
|
|
reader.Seek(pos + 16, System.IO.SeekOrigin.Begin);
|
|
|
|
|
|
|
|
|
|
ContextMenu = new ContextMenu();
|
|
|
|
|
MenuItem export = new MenuItem("Export Raw Data");
|
|
|
|
|
ContextMenu.MenuItems.Add(export);
|
|
|
|
|
export.Click += Export;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public void Unload()
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
public byte[] Save()
|
|
|
|
|
{
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public bool AddFile(ArchiveFileInfo archiveFileInfo)
|
|
|
|
|
{
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public bool DeleteFile(ArchiveFileInfo archiveFileInfo)
|
|
|
|
|
{
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|