From 66fef2185989944f8d45581e3f02b0e05c621506 Mon Sep 17 00:00:00 2001 From: Bioruebe Date: Mon, 31 Aug 2020 14:31:46 +0200 Subject: [PATCH] Updated for BioLib 2.0.0 --- godotdec/App.config | 2 +- godotdec/Program.cs | 28 +++++++++++----------------- godotdec/godotdec.csproj | 7 +++---- godotdec/packages.config | 2 +- 4 files changed, 16 insertions(+), 23 deletions(-) diff --git a/godotdec/App.config b/godotdec/App.config index d1428ad..74ade9d 100644 --- a/godotdec/App.config +++ b/godotdec/App.config @@ -1,6 +1,6 @@ - + diff --git a/godotdec/Program.cs b/godotdec/Program.cs index 88a5266..fbce629 100644 --- a/godotdec/Program.cs +++ b/godotdec/Program.cs @@ -1,4 +1,5 @@ using BioLib; +using BioLib.Streams; using System; using System.Collections.Generic; using System.IO; @@ -7,6 +8,8 @@ namespace godotdec { class Program { + private const string VERSION = "2.1.1"; + private const string PROMPT_ID = "godotdec_overwrite"; private const int MAGIC = 0x43504447; private static string inputFile; @@ -14,7 +17,7 @@ class Program { private static bool convertAssets; static void Main(string[] args) { - Bio.Header("godotdec", "2.1.0", "2018-2020", "A simple unpacker for Godot Engine package files (.pck|.exe)", + Bio.Header("godotdec", VERSION, "2018-2020", "A simple unpacker for Godot Engine package files (.pck|.exe)", "[] []\n\nOptions:\n-c\t--convert\tConvert textures and audio files"); if (Bio.HasCommandlineSwitchHelp(args)) return; @@ -27,9 +30,9 @@ class Program { CheckMagic(inputStream.ReadInt32()); - inputStream.BaseStream.Seek(-12, SeekOrigin.Current); + inputStream.BaseStream.Skip(-12); var offset = inputStream.ReadInt64(); - inputStream.BaseStream.Seek(-offset - 8, SeekOrigin.Current); + inputStream.BaseStream.Skip(-offset - 8); CheckMagic(inputStream.ReadInt32()); } @@ -37,7 +40,7 @@ class Program { Bio.Cout($"Godot Engine version: {inputStream.ReadInt32()}.{inputStream.ReadInt32()}.{inputStream.ReadInt32()}.{inputStream.ReadInt32()}"); // Skip reserved bytes (16x Int32) - inputStream.BaseStream.Seek(16 * 4, SeekOrigin.Current); + inputStream.BaseStream.Skip(16 * 4); var fileCount = inputStream.ReadInt32(); Bio.Cout($"Found {fileCount} files in package"); @@ -50,7 +53,7 @@ class Program { var fileEntry = new FileEntry(path.ToString(), inputStream.ReadInt64(), inputStream.ReadInt64()); fileIndex.Add(fileEntry); Bio.Debug(fileEntry); - inputStream.BaseStream.Seek(16, SeekOrigin.Current); + inputStream.BaseStream.Skip(16); //break; } @@ -87,21 +90,12 @@ class Program { } } + inputStream.BaseStream.Position = fileEntry.offset; var destination = Path.Combine(outputDirectory, fileEntry.path); - destination = Bio.EnsureFileDoesNotExist(destination, "godotdec_overwrite"); - inputStream.BaseStream.Seek(fileEntry.offset, SeekOrigin.Begin); - if (destination == null) continue; try { - var fileMode = FileMode.CreateNew; - Directory.CreateDirectory(Path.GetDirectoryName(destination)); - - if (File.Exists(destination)) { - fileMode = FileMode.Create; - } - using (var outputStream = new FileStream(destination, fileMode)) { - Bio.CopyStream(inputStream.BaseStream, outputStream, (int) fileEntry.size, false); - } + Action copyFunction = (input, output) => input.Copy(output, (int) fileEntry.size); + inputStream.BaseStream.WriteToFile(destination, PROMPT_ID, copyFunction); } catch (Exception e) { Bio.Error(e); diff --git a/godotdec/godotdec.csproj b/godotdec/godotdec.csproj index 8bffc0e..4e58c7e 100644 --- a/godotdec/godotdec.csproj +++ b/godotdec/godotdec.csproj @@ -8,7 +8,7 @@ Exe godotdec godotdec - v4.5 + v4.0 512 true true @@ -34,8 +34,8 @@ 4 - - ..\packages\Bioruebe.BioLib.1.0.0\lib\net45\Bio.cs.dll + + ..\packages\Bioruebe.BioLib.2.0.0\lib\net40\Bio.cs.dll @@ -43,7 +43,6 @@ - diff --git a/godotdec/packages.config b/godotdec/packages.config index fe8e075..0c02574 100644 --- a/godotdec/packages.config +++ b/godotdec/packages.config @@ -1,4 +1,4 @@  - + \ No newline at end of file