/// <summary> /// Export files synchronously /// </summary> /// <param name="list">File list to export. (generate by <see cref="RecursiveFileList"/>) /// The list must be sort by thier bundle to speed up exportation.</param> /// <param name="ProgressStep">It will be executed every time a file is exported</param> public static void Export(ICollection <KeyValuePair <IFileRecord, string> > list, Action ProgressStep = null) { LibBundle.Records.BundleRecord br = null; MemoryStream ms = null; foreach (var record in list) { Directory.CreateDirectory(Directory.GetParent(record.Value).FullName); if (record.Key is BundleFileNode bfn) { if (br != bfn.BundleFileRecord.bundleRecord) { ms?.Close(); br = bfn.BundleFileRecord.bundleRecord; br.Read(bfn.ggpkContainer.Reader, bfn.ggpkContainer.RecordOfBundle[bfn.BundleFileRecord.bundleRecord].DataBegin); ms = br.Bundle.Read(bfn.ggpkContainer.Reader); } File.WriteAllBytes(record.Value, bfn.BatchReadFileContent(ms)); } else { File.WriteAllBytes(record.Value, record.Key.ReadFileContent()); } ProgressStep(); } }
#pragma warning restore CA1816 // Dispose should call SuppressFinalize /// <summary> /// Export files /// </summary> /// <param name="list">File list to export. (generate by <see cref="RecursiveFileList"/>) /// The list must be sort by thier bundle to speed up exportation.</param> /// <param name="ProgressStep">It will be executed every time a file is exported</param> public static void Export(IEnumerable <KeyValuePair <IFileRecord, string> > list, Action ProgressStep = null) { LibBundle.Records.BundleRecord br = null; MemoryStream ms = null; var failBundles = 0; var failFiles = 0; foreach (var(record, path) in list) { Directory.CreateDirectory(Path.GetDirectoryName(path)); if (record is BundleFileNode bfn) { if (br != bfn.BundleFileRecord.bundleRecord) { ms?.Close(); br = bfn.BundleFileRecord.bundleRecord; br.Read(bfn.ggpkContainer.Reader, bfn.ggpkContainer.RecordOfBundle(br)?.DataBegin); ms = br.Bundle?.Read(bfn.ggpkContainer.Reader); if (ms == null) { ++failBundles; } } if (ms == null) { ++failFiles; } else { File.WriteAllBytes(path, bfn.BatchReadFileContent(ms)); } } else { File.WriteAllBytes(path, record.ReadFileContent()); } ProgressStep?.Invoke(); } if (failBundles != 0 || failFiles != 0) { throw new BundleMissingException(failBundles, failFiles); } }