diff --git a/src/CLI/Functions/Unpacker.cs b/src/CLI/Functions/Unpacker.cs index 4092d943d..9abfa28f5 100644 --- a/src/CLI/Functions/Unpacker.cs +++ b/src/CLI/Functions/Unpacker.cs @@ -1,4 +1,4 @@ -using CUE4Parse.Compression; +using CLI.Utils; using CUE4Parse.FileProvider.Objects; using CUE4Parse.UE4.Pak; @@ -7,7 +7,11 @@ namespace CLI.Functions class Unpacker { public static string ZlibPath = "../../temp/zlib.dll"; - public static string VFSWriteDirectory = "../../temp/vfs/"; + public static string VFSWriteDir = "../../temp/vfs/"; + + // this may be different from the one provided in args so check this and not args[1] + // we don't wanna delete my local installation of the game when debugging haha! + public static string tempDepotsDir = "../../temp/depot/"; public static void Unpack(string[] args) { @@ -16,17 +20,7 @@ namespace CLI.Functions throw new ArgumentException("Missing required initial paks directory"); } - if (File.Exists(ZlibPath)) - { - Console.WriteLine($"Zlib found at {ZlibPath}; using that..."); - } - else - { - Console.WriteLine($"Zlib not found; downloading to {ZlibPath}..."); - ZlibHelper.DownloadDll(ZlibPath); - } - - ZlibHelper.Initialize(ZlibPath); + AgnosticZlibHelper.Initialize(); string workingDirectory = args[1]; string paksDirectory = Path.Combine(workingDirectory, "Blitz/Content/Paks"); @@ -36,6 +30,12 @@ namespace CLI.Functions { Exergy(container); } + + if (Directory.Exists(tempDepotsDir)) + { + Console.WriteLine("Deleting temp depots directory..."); + Directory.Delete(tempDepotsDir, true); + } } public static void Exergy(string container) @@ -56,7 +56,7 @@ namespace CLI.Functions continue; } - string writePath = Path.Combine(VFSWriteDirectory, gameFile.Path); + string writePath = Path.Combine(VFSWriteDir, gameFile.Path); if (File.Exists(writePath)) { diff --git a/src/CLI/Utils/AgnosticZlibHelper.cs b/src/CLI/Utils/AgnosticZlibHelper.cs new file mode 100644 index 000000000..4c3519be8 --- /dev/null +++ b/src/CLI/Utils/AgnosticZlibHelper.cs @@ -0,0 +1,48 @@ +using System.Runtime.InteropServices; +using CUE4Parse.Compression; + +namespace CLI.Utils +{ + public static class AgnosticZlibHelper + { + public const string ZlibRootPath = "../../temp/"; + public const string ZlibBinariesPrefix = + "https://github.com/NotOfficer/Zlib-ng.NET/releases/download/1.0.0"; + + public static void Initialize() + { + string binariesUrl; + string fileExtension; + + if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) + { + binariesUrl = $"{ZlibBinariesPrefix}/zlib-ng2.dll"; + fileExtension = "dll"; + } + else if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux)) + { + binariesUrl = $"{ZlibBinariesPrefix}/libz-ng.so"; + fileExtension = "so"; + } + else + { + throw new PlatformNotSupportedException(); + } + + string fileName = $"zlib.{fileExtension}"; + string filePath = Path.Combine(ZlibRootPath, fileName); + + if (File.Exists(filePath)) + { + Console.WriteLine($"Zlib found at {filePath}; using that..."); + } + else + { + Console.WriteLine($"Zlib not found; downloading to {filePath} from {binariesUrl}..."); + ZlibHelper.DownloadDll(filePath, binariesUrl); + } + + ZlibHelper.Initialize(filePath); + } + } +}