Example #1
0
        private static string GetExportPath(ArcFileNode arcNode)
        {
            var filePath = ArcPaths.GetOsSafePath(arcNode.Path, arcNode.FileName, arcNode.Extension);

            // If the user selects an absolute path for the extract location, this overrides the current directory.
            var exportDirectory = ApplicationDirectory.CreateAbsolutePath(ApplicationSettings.Instance.ExtractLocation);
            var paths           = new string[] { exportDirectory };

            // Use the OS directory separators instead of the ARC path separators.
            var exportPath = Path.Combine(paths.Concat(filePath.Split('/')).ToArray());

            return(exportPath);
        }
Example #2
0
        private static FileNode CreateFileNode(ArcFile arcFile, ArcFileNode arcNode, Action <string, bool> taskStart, Action <string> taskEnd)
        {
            // Lazy initialize the shared file list for performance reasons.
            List <string> getSharedFiles() => arcFile.GetSharedFilePaths(arcNode, ApplicationSettings.Instance.ArcRegion);

            // TODO: Avoid caching this information since it may change when changing regions.
            var fileNode = new FileNode(arcNode.FileName, arcNode.Path, arcNode.Extension,
                                        arcNode.IsShared, arcNode.IsRegional, arcNode.Offset, arcNode.CompSize, arcNode.DecompSize, arcNode.IsCompressed,
                                        getSharedFiles);

            fileNode.FileExtracting += (s, e) => ExtractFileAsync(arcFile, arcNode, taskStart, taskEnd);

            return(fileNode);
        }
Example #3
0
        private static ExtractResult TryExtractFile(ArcFile arcFile, ArcFileNode arcNode)
        {
            var exportPath = GetExportPath(arcNode);

            // Extraction will fail if the directory doesn't exist.
            var exportFileDirectory = Path.GetDirectoryName(exportPath);

            try
            {
                if (!Directory.Exists(exportFileDirectory))
                {
                    Directory.CreateDirectory(exportFileDirectory);
                }
            }
            catch (Exception e)
            {
                Serilog.Log.Error(e, "Error creating directory {@exportFileDirectory}", exportFileDirectory);
                return(new ExtractResult {
                    CompletionSummary = $"Error creating directory {exportFileDirectory}", Success = false
                });
            }

            // Extraction may fail.
            // TODO: Update the C# bindings to store more detailed error info?
            if (!arcFile.TryExtractFile(arcNode, exportPath, ApplicationSettings.Instance.ArcRegion))
            {
                Serilog.Log.Logger.Error("Failed to extract to {@path}", exportPath);
                return(new ExtractResult {
                    CompletionSummary = $"Failed to extract {arcNode.Path}", Success = false
                });
            }

            return(new ExtractResult {
                CompletionSummary = $"Extracted {arcNode.Path}", Success = false
            });
        }
Example #4
0
 private static async void ExtractFileAsync(ArcFile arcFile, ArcFileNode arcNode, Action <string, bool> taskStart, Action <string> taskEnd)
 {
     // Files extract quickly, so there's no need to update the UI by calling taskStart.
     await RunBackgroundTask($"Extracting {arcNode.Path}", false, () => TryExtractFile(arcFile, arcNode), taskStart, taskEnd);
 }