/// <summary> /// Uncooks a single file by hash. This will both extract and uncook the redengine file /// </summary> /// <param name="ar"></param> /// <param name="hash"></param> /// <param name="outDir"></param> /// <param name="uncookext"></param> /// <param name="flip"></param> /// <returns></returns> public static bool UncookSingle(this Archive.Archive ar, ulong hash, DirectoryInfo outDir, EUncookExtension uncookext = EUncookExtension.dds, bool flip = false) { // checks if (!ar.Files.ContainsKey(hash)) { return(false); } // extract the main file with uncompressed buffers #region unbundle main file using var ms = new MemoryStream(); ar.CopyFileToStream(ms, hash, false); var name = ar.Files[hash].FileName; var outfile = new FileInfo(Path.Combine(outDir.FullName, $"{name}")); if (outfile.Directory == null) { return(false); } Directory.CreateDirectory(outfile.Directory.FullName); using var fs = new FileStream(outfile.FullName, FileMode.Create, FileAccess.Write); ms.Seek(0, SeekOrigin.Begin); ms.CopyTo(fs); #endregion var ext = Path.GetExtension(name)[1..];
/// <summary> /// Extracts a single file + buffers. /// </summary> /// <param name="ar"></param> /// <param name="hash"></param> /// <param name="outDir"></param> /// <returns></returns> public static int ExtractSingle(this Archive.Archive ar, ulong hash, DirectoryInfo outDir) { if (!ar.Files.ContainsKey(hash)) { return(-1); } using var ms = new MemoryStream(); ar.CopyFileToStream(ms, hash, false); string name = ar.Files[hash].FileName; if (string.IsNullOrEmpty(Path.GetExtension(name))) { name += ".bin"; } var outfile = new FileInfo(Path.Combine(outDir.FullName, $"{name}")); if (outfile.Directory == null) { return(-1); } Directory.CreateDirectory(outfile.Directory.FullName); using var fs = new FileStream(outfile.FullName, FileMode.Create, FileAccess.Write); ms.Seek(0, SeekOrigin.Begin); ms.CopyTo(fs); return(1); }