private static ExtractResult TryExtractAllFiles(ArcFile arcFile, Action <string, double> reportProgress, bool mergeTrailingSlash) { // Loading the files first uses more memory but allows for determinate progress. var filesToExtract = new List <ArcFileNode>(); foreach (var arcNode in arcFile.GetRootNodes()) { if (arcNode is ArcDirectoryNode directory) { AddFilesRecursive(arcFile, directory, filesToExtract, mergeTrailingSlash); } } for (int i = 0; i < filesToExtract.Count; i++) { TryExtractFile(arcFile, filesToExtract[i]); var percentage = i / (double)filesToExtract.Count * 100; // Fix the string length to avoid strange flickering when the progress bar resizes. var desiredLength = 60; reportProgress(filesToExtract[i].Path.PadRight(desiredLength).Substring(0, desiredLength), percentage); } // Assume the operation succeeds for now. // Individual file extractions may still fail. var result = new ExtractResult { Success = true, CompletionSummary = $"Extracted {filesToExtract.Count} files" }; return(result); }
/// <summary> /// Loads the base level from <paramref name="arcFile"/>. /// The parameter to <paramref name="extractStartCallBack"/> is the task description. /// </summary> /// <param name="arcFile">the ARC to load</param> /// <param name="extractStartCallBack">called before starting an extract operation</param> /// <param name="extractReportProgressCallBack">contains the file path and progress percentage on extracting multiple files</param> /// <param name="extractEndCallBack">called after starting an extract operation with a progress message</param> /// <param name="mergeTrailingSlash">Directories with and without a trailing slash are considered identical when <c>true</c></param> /// <returns>The nodes for the root level</returns> public static List <FileNodeBase> CreateRootLevelNodes(ArcFile arcFile, Action <string, bool> extractStartCallBack, Action <string, double> extractReportProgressCallBack, Action <string> extractEndCallBack, bool mergeTrailingSlash) { var files = new List <FileNodeBase>(); foreach (var node in arcFile.GetRootNodes(ApplicationSettings.Instance.ArcRegion)) { // There is no parent for root nodes, so leave the parent as null. var treeNode = CreateNode(arcFile, node, extractStartCallBack, extractReportProgressCallBack, extractEndCallBack, mergeTrailingSlash); files.Add(treeNode); } return(files); }