diff --git a/PCK-Studio/Classes/FileTypes/ARCFile.cs b/PCK-Studio/Classes/FileTypes/ARCFile.cs deleted file mode 100644 index dc194700..00000000 --- a/PCK-Studio/Classes/FileTypes/ARCFile.cs +++ /dev/null @@ -1,10 +0,0 @@ -using System.Collections.Generic; - -namespace PckStudio.Classes.FileTypes -{ - // filepath to file data - public class ConsoleArchive : Dictionary - { - public int SizeOfFile(string filepath) => this[filepath].Length; - } -} \ No newline at end of file diff --git a/PCK-Studio/Classes/IO/ARC/ARCFileReader.cs b/PCK-Studio/Classes/IO/ARC/ARCFileReader.cs deleted file mode 100644 index c0152767..00000000 --- a/PCK-Studio/Classes/IO/ARC/ARCFileReader.cs +++ /dev/null @@ -1,49 +0,0 @@ -using System; -using System.IO; -using System.Text; -using PckStudio.Classes.FileTypes; - -namespace PckStudio.Classes.IO.ARC -{ - internal class ARCFileReader : StreamDataReader - { - public static ConsoleArchive Read(Stream stream, bool useLittleEndian = false) - { - return new ARCFileReader(useLittleEndian).ReadFromStream(stream); - } - - private ARCFileReader(bool useLittleEndian) : base(useLittleEndian) - { - } - - protected override ConsoleArchive ReadFromStream(Stream stream) - { - ConsoleArchive _archive = new ConsoleArchive(); - int numberOfFiles = ReadInt(stream); - for(int i = 0; i < numberOfFiles; i++) - { - string name = ReadString(stream); - int offset = ReadInt(stream); - int size = ReadInt(stream); - _archive[name] = ReadBytesFromPosition(stream, offset, size); - } - return _archive; - } - - private string ReadString(Stream stream) - { - short length = ReadShort(stream); - return ReadString(stream, length, Encoding.UTF8); - } - - private byte[] ReadBytesFromPosition(Stream stream, int position, int size) - { - long originalPOS = stream.Position; - if (stream.Seek(position, SeekOrigin.Begin) != position) throw new Exception(); - byte[] data = ReadBytes(stream, size); - if (stream.Seek(originalPOS, SeekOrigin.Begin) != originalPOS) throw new Exception(); - return data; - } - - } -} diff --git a/PCK-Studio/Classes/IO/ARC/ARCFileWriter.cs b/PCK-Studio/Classes/IO/ARC/ARCFileWriter.cs deleted file mode 100644 index 8ccd25b6..00000000 --- a/PCK-Studio/Classes/IO/ARC/ARCFileWriter.cs +++ /dev/null @@ -1,47 +0,0 @@ -using System.IO; -using System.Linq; -using System.Text; -using PckStudio.Classes.FileTypes; - -namespace PckStudio.Classes.IO.ARC -{ - internal class ARCFileWriter : StreamDataWriter - { - private ConsoleArchive _archive; - - public static void Write(Stream stream, ConsoleArchive archive, bool useLittleEndian = false) - { - new ARCFileWriter(archive, useLittleEndian).WriteToStream(stream); - } - - public ARCFileWriter(ConsoleArchive archive, bool useLittleEndian) : base(useLittleEndian) - { - _archive = archive; - } - - protected override void WriteToStream(Stream stream) - { - var arc = _archive.ToArray(); - WriteInt(stream, arc.Length); - int offset = 4 + arc.Sum(pair => 10 + pair.Key.Length); - foreach (var pair in arc) - { - int size = pair.Value.Length; - WriteString(stream, pair.Key); - WriteInt(stream, offset); - WriteInt(stream, size); - offset += size; - } - foreach (var pair in arc) - { - WriteBytes(stream, pair.Value); - } - } - - private void WriteString(Stream stream, string s) - { - WriteShort(stream, (short)s.Length); - WriteString(stream, s, Encoding.ASCII); - } - } -} diff --git a/PCK-Studio/Classes/Utils/ARC/ARCUtil.cs b/PCK-Studio/Classes/Utils/ARC/ARCUtil.cs index 5acd366c..a4c0946d 100644 --- a/PCK-Studio/Classes/Utils/ARC/ARCUtil.cs +++ b/PCK-Studio/Classes/Utils/ARC/ARCUtil.cs @@ -1,4 +1,4 @@ -using PckStudio.Classes.IO.ARC; +using OMI.Workers.Archive; using System.IO; namespace PckStudio.Classes.Utils.ARC @@ -7,10 +7,12 @@ namespace PckStudio.Classes.Utils.ARC { public static void Inject(Stream stream, (string filepath, byte[] data) entry) { - var archive = ARCFileReader.Read(stream); - stream.Seek(0, SeekOrigin.Begin); + var reader = new ARCFileReader(); + var archive = reader.FromStream(stream); archive.Add(entry.filepath, entry.data); - ARCFileWriter.Write(stream, archive); + var writer = new ARCFileWriter(archive); + stream.Seek(0, SeekOrigin.Begin); + writer.WriteToStream(stream); } } } \ No newline at end of file diff --git a/PCK-Studio/Forms/Utilities/installWiiU.cs b/PCK-Studio/Forms/Utilities/installWiiU.cs index 8cbcef48..557708be 100644 --- a/PCK-Studio/Forms/Utilities/installWiiU.cs +++ b/PCK-Studio/Forms/Utilities/installWiiU.cs @@ -10,8 +10,9 @@ using System.Diagnostics; using PckStudio.Classes.FileTypes; using PckStudio.Classes.IO.PCK; -using PckStudio.Classes.IO.ARC; using PckStudio.Classes.Misc; +using OMI.Formats.Archive; +using OMI.Workers.Archive; namespace PckStudio.Forms { @@ -439,7 +440,8 @@ namespace PckStudio.Forms { using (FTPClient client = new FTPClient("ftp://" + textBoxHost.Text, "", "a3262443")) client.DownloadFile(dlcPath + "../../Common/Media/MediaWiiU.arc", Program.AppData + "MediaWiiU.arc"); - archive = ARCFileReader.Read(new MemoryStream(File.ReadAllBytes(Program.AppData + "MediaWiiU.arc"))); + var reader = new ARCFileReader(); + archive = reader.FromStream(new MemoryStream(File.ReadAllBytes(Program.AppData + "MediaWiiU.arc"))); } private void ReplacePackImage(string PackID) @@ -455,7 +457,8 @@ namespace PckStudio.Forms using (FTPClient client = new FTPClient("ftp://" + textBoxHost.Text, "", "a3262443")) { MemoryStream ms = new MemoryStream(); - ARCFileWriter.Write(ms, archive); + var writer = new ARCFileWriter(archive); + writer.WriteToStream(ms); File.WriteAllBytes(Program.AppData + "MediaWiiU.arc", ms.ToArray()); client.UploadFile(Program.AppData + "MediaWiiU.arc", dlcPath + "../../Common/Media/MediaWiiU.arc"); archive.Clear(); diff --git a/PCK-Studio/PckStudio.csproj b/PCK-Studio/PckStudio.csproj index 4c5ac79c..65edad5e 100644 --- a/PCK-Studio/PckStudio.csproj +++ b/PCK-Studio/PckStudio.csproj @@ -170,7 +170,6 @@ - @@ -180,8 +179,6 @@ - - @@ -788,7 +785,12 @@ 4.5.0 - + + + {693AEBC1-293D-4DF0-BCAE-26A1099FE7BB} + OMI Filetype Library + +