diff --git a/src/archive/archive_amb/AMB.cs b/src/archive/archive_amb/AMB.cs new file mode 100644 index 00000000..64a3e759 --- /dev/null +++ b/src/archive/archive_amb/AMB.cs @@ -0,0 +1,82 @@ +using System; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using System.Text; +using Kuriimu.Compression; +using Kuriimu.Kontract; +using Kuriimu.IO; + +namespace archive_amb +{ + public class AMB + { + public List Files = new List(); + Stream _stream = null; + + public Header header; + public List entries = new List(); + + public AMB(Stream input) + { + _stream = input; + using (BinaryReaderX br = new BinaryReaderX(input, true, ByteOrder.BigEndian)) + { + //Header + header = br.ReadStruct
(); + + //FileEntries + entries = br.ReadMultiple((int)header.fileCount); + + //Files + var count = 0; + foreach (var entry in entries) + Files.Add(new AMBFileInfo + { + State = ArchiveFileState.Archived, + FileName = $"{count++:00000000}.bin", + FileData = new SubStream(br.BaseStream, entry.offset, entry.size) + }); + } + } + + public void Save(Stream output) + { + using (var bw = new BinaryWriterX(output, ByteOrder.BigEndian)) + { + //Header + bw.WriteStruct(header); + + //FileEntries + var count = 0; + var dataOffset = header.dataOffset; + foreach (var file in Files) + { + entries[count].offset = dataOffset; + entries[count++].size = (uint)file.FileSize; + + dataOffset = (uint)((dataOffset + (uint)file.FileSize + 0xf) & ~0xf); + } + + foreach (var entry in entries) + { + bw.WriteStruct(entry); + } + + //Files + bw.BaseStream.Position = header.dataOffset; + foreach (var file in Files) + { + file.FileData.CopyTo(bw.BaseStream); + bw.WriteAlignment(); + } + } + } + + public void Close() + { + _stream?.Close(); + _stream = null; + } + } +} diff --git a/src/archive/archive_amb/AmbManager.cs b/src/archive/archive_amb/AmbManager.cs new file mode 100644 index 00000000..cea36202 --- /dev/null +++ b/src/archive/archive_amb/AmbManager.cs @@ -0,0 +1,92 @@ +using System.Collections.Generic; +using System.Drawing; +using System.IO; +using Kuriimu.Kontract; +using Kuriimu.IO; + +namespace archive_amb +{ + public class AmbManager : IArchiveManager + { + private AMB _amb = null; + + #region Properties + + // Information + public string Name => "AMB"; + public string Description => "Whatever AMB means"; + public string Extension => "*.amb"; + public string About => "This is the AMB archive manager for Karameru."; + + // Feature Support + public bool ArchiveHasExtendedProperties => false; + public bool CanAddFiles => false; + public bool CanRenameFiles => false; + public bool CanReplaceFiles => true; + public bool CanDeleteFiles => false; + public bool CanSave => true; + + public FileInfo FileInfo { get; set; } + + #endregion + + public bool Identify(string filename) + { + using (var br = new BinaryReaderX(File.OpenRead(filename))) + { + if (br.BaseStream.Length < 4) return false; + var magic = br.ReadString(4); + return magic == "#AMB"; + } + } + + public void Load(string filename) + { + FileInfo = new FileInfo(filename); + + if (FileInfo.Exists) + _amb = new AMB(FileInfo.OpenRead()); + } + + public void Save(string filename = "") + { + if (!string.IsNullOrEmpty(filename)) + FileInfo = new FileInfo(filename); + + // Save As... + if (!string.IsNullOrEmpty(filename)) + { + _amb.Save(FileInfo.Create()); + _amb.Close(); + } + else + { + // Create the temp file + _amb.Save(File.Create(FileInfo.FullName + ".tmp")); + _amb.Close(); + // Delete the original + FileInfo.Delete(); + // Rename the temporary file + File.Move(FileInfo.FullName + ".tmp", FileInfo.FullName); + } + + // Reload the new file to make sure everything is in order + Load(FileInfo.FullName); + } + + public void Unload() + { + _amb?.Close(); + } + + // Files + public IEnumerable Files => _amb.Files; + + public bool AddFile(ArchiveFileInfo afi) => false; + + public bool DeleteFile(ArchiveFileInfo afi) => false; + + // Features + public bool ShowProperties(Icon icon) => false; + } +} diff --git a/src/archive/archive_amb/AmbSupport.cs b/src/archive/archive_amb/AmbSupport.cs new file mode 100644 index 00000000..a81e5084 --- /dev/null +++ b/src/archive/archive_amb/AmbSupport.cs @@ -0,0 +1,32 @@ +using System.Runtime.InteropServices; +using Kuriimu.Kontract; + +namespace archive_amb +{ + public class AMBFileInfo : ArchiveFileInfo + { + + } + + [StructLayout(LayoutKind.Sequential, Pack = 1)] + public class Header + { + public Magic magic; + public uint headerSize; + public int zero0; + public uint dirCount; //?? + public uint fileCount; + public uint fileEntryOffset; + public uint dataOffset; + public uint zero1; + } + + [StructLayout(LayoutKind.Sequential, Pack = 1)] + public class FileEntry + { + public uint offset; + public uint size; + public uint id; + public uint zero0; + } +} diff --git a/src/archive/archive_amb/Properties/AssemblyInfo.cs b/src/archive/archive_amb/Properties/AssemblyInfo.cs new file mode 100644 index 00000000..96fb04d9 --- /dev/null +++ b/src/archive/archive_amb/Properties/AssemblyInfo.cs @@ -0,0 +1,36 @@ +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +// General Information about an assembly is controlled through the following +// set of attributes. Change these attribute values to modify the information +// associated with an assembly. +[assembly: AssemblyTitle("archive_amb")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("archive_amb")] +[assembly: AssemblyCopyright("Copyright © 2017")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// Setting ComVisible to false makes the types in this assembly not visible +// to COM components. If you need to access a type in this assembly from +// COM, set the ComVisible attribute to true on that type. +[assembly: ComVisible(false)] + +// The following GUID is for the ID of the typelib if this project is exposed to COM +[assembly: Guid("65b03a2b-bcf5-494e-a87c-dd4ac2d4f286")] + +// Version information for an assembly consists of the following four values: +// +// Major Version +// Minor Version +// Build Number +// Revision +// +// You can specify all the values or you can default the Build and Revision Numbers +// by using the '*' as shown below: +// [assembly: AssemblyVersion("1.0.*")] +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/src/archive/archive_amb/Properties/Settings.Designer.cs b/src/archive/archive_amb/Properties/Settings.Designer.cs new file mode 100644 index 00000000..be30f542 --- /dev/null +++ b/src/archive/archive_amb/Properties/Settings.Designer.cs @@ -0,0 +1,41 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by a tool. +// Runtime Version:4.0.30319.42000 +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +namespace archive_amb.Properties +{ + + + [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "15.1.0.0")] + internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase + { + + private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings()))); + + public static Settings Default + { + get + { + return defaultInstance; + } + } + + [global::System.Configuration.ApplicationScopedSettingAttribute()] + [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] + [global::System.Configuration.DefaultSettingValueAttribute("")] + public string PluginName + { + get + { + return ((string)(this["PluginName"])); + } + } + } +} diff --git a/src/archive/archive_amb/Properties/Settings.settings b/src/archive/archive_amb/Properties/Settings.settings new file mode 100644 index 00000000..b097ca90 --- /dev/null +++ b/src/archive/archive_amb/Properties/Settings.settings @@ -0,0 +1,9 @@ + + + + + + + + + \ No newline at end of file diff --git a/src/archive/archive_amb/app.config b/src/archive/archive_amb/app.config new file mode 100644 index 00000000..84ddcd96 --- /dev/null +++ b/src/archive/archive_amb/app.config @@ -0,0 +1,15 @@ + + + + +
+ + + + + + + + + + \ No newline at end of file diff --git a/src/archive/archive_amb/archive_amb.csproj b/src/archive/archive_amb/archive_amb.csproj new file mode 100644 index 00000000..12fa18f6 --- /dev/null +++ b/src/archive/archive_amb/archive_amb.csproj @@ -0,0 +1,68 @@ + + + + + Debug + AnyCPU + {65B03A2B-BCF5-494E-A87C-DD4AC2D4F286} + Library + Properties + archive_amb + archive_amb + v4.5.2 + 512 + + + true + full + false + ..\..\Kuriimu\bin\Debug\plugins\ + DEBUG;TRACE + prompt + 4 + + + pdbonly + true + ..\..\Kuriimu\bin\Release\plugins\ + TRACE + prompt + 4 + + + + + + + + + + + + + + + + True + True + Settings.settings + + + + + + + + + SettingsSingleFileGenerator + Settings.Designer.cs + + + + + {51e474f7-1497-4c30-bc18-c357c884b8b2} + KuriimuContract + + + + \ No newline at end of file