public void Dispose() { if (!disposed) { if (m_should_ascend) { VFS.ChDir(".."); } disposed = true; } GC.SuppressFinalize(this); }
public GarExtract(MainWindow parent, string source) : base(parent, guiStrings.TextExtractionError) { m_arc_name = Path.GetFileName(source); try { VFS.ChDir(source); m_should_ascend = true; } catch (Exception X) { throw new OperationCanceledException(string.Format("{1}: {0}", X.Message, m_arc_name)); } m_fs = VFS.Top as ArchiveFileSystem; }
DirectoryViewModel GetNewViewModel(string path) { if (!string.IsNullOrEmpty(path)) { if (!VFS.IsVirtual) { path = Path.GetFullPath(path); } var entry = VFS.FindFile(path); if (!(entry is SubDirEntry)) { SetBusyState(); } VFS.ChDir(entry); } return(new DirectoryViewModel(VFS.FullPath, VFS.GetFiles(), VFS.IsVirtual)); }
void Run(string[] args) { int argn = 0; while (argn < args.Length) { if (args[argn].Equals("-l")) { ListFormats(); return; } else if (args[argn].Equals("-t")) { TestArc(args); return; } else if (args[argn].Equals("-c")) { if (argn + 1 >= args.Length) { Usage(); return; } var tag = args[argn + 1]; m_image_format = ImageConverter.FindFormat(tag); if (null == m_image_format) { Console.Error.WriteLine("{0}: unknown format specified", tag); return; } argn += 2; } else if (args[argn].Equals("-x")) { m_extract_all = true; ++argn; if (args.Length <= argn) { Usage(); return; } } else { break; } } if (argn >= args.Length) { Usage(); return; } DeserializeGameData(); foreach (var file in VFS.GetFiles(args[argn])) { m_arc_name = file.Name; try { VFS.ChDir(m_arc_name); } catch (Exception X) { Console.Error.WriteLine("{0}: unknown format", m_arc_name); continue; } var arc = (ArchiveFileSystem)VFS.Top; if (args.Length > argn + 1) { for (int i = argn + 1; i < args.Length; ++i) { ExtractFile(arc.Source, args[i]); } } else if (m_extract_all) { ExtractAll(arc.Source); } else { foreach (var entry in arc.Source.Dir.OrderBy(e => e.Offset)) { Console.WriteLine("{0,9} [{2:X8}] {1}", entry.Size, entry.Name, entry.Offset); } } } }
void Run(string[] args) { var command = args.Length < 1? "h": args[0]; switch (command) { case "h": case "-h": case "--help": case "/?": case "-?": Usage(); return; case "f": ListFormats(); return; } if (command.Length != 1) { PrintError(File.Exists(command)? "No command specified. Use -h command line parameter to show help.": "Invalid command: " + command); return; } if (args.Length < 2) { PrintError("No archive file specified"); return; } var inputFile = args[args.Length - 1]; if (!File.Exists(inputFile)) { PrintError("Input file " + inputFile + " does not exist"); return; } var argLength = args.Length - 1; outputDirectory = Directory.GetCurrentDirectory(); for (var i = 1; i < argLength; i++) { switch (args[i]) { case "-o": i++; if (i >= argLength) { PrintError("No output directory specified"); return; } outputDirectory = args[i]; if (File.Exists(outputDirectory)) { PrintError("Invalid output directory"); return; } //Directory.SetCurrentDirectory(outputDirectory); break; case "-f": i++; if (i >= argLength) { PrintError("No filter specified"); return; } try { fileFilter = new Regex(args[i]); } catch (ArgumentException e) { PrintError("Invalid filter: " + e.Message); return; } break; case "-if": i++; var formatTag = args[i].ToUpper(); if (formatTag == "JPG") { formatTag = "JPEG"; } imageFormat = ImageFormat.FindByTag(formatTag); if (imageFormat == null) { PrintError("Unknown image format specified: " + args[i]); return; } break; case "-ca": convertAudio = true; break; case "-na": skipAudio = true; break; case "-ni": skipImages = true; break; case "-ns": skipScript = true; break; case "-aio": adjustImageOffset = true; break; case "-ocu": autoImageFormat = true; break; default: Console.WriteLine("Warning: Unknown command line parameter: " + args[i]); return; } } if (autoImageFormat && imageFormat == null) { PrintError("The parameter -ocu requires the image format (-if parameter) to be set"); return; } DeserializeGameData(); try { VFS.ChDir(inputFile); } catch (Exception) { PrintError("Input file has an unknown format"); return; } var m_fs = (ArchiveFileSystem)VFS.Top; var fileList = m_fs.GetFilesRecursive().Where(e => e.Offset >= 0); if (skipImages || skipScript || skipAudio || fileFilter != null) { fileList = fileList.Where(f => !(skipImages && f.Type == "image") && !(skipScript && f.Type == "script") && !(skipAudio && f.Type == "audio") && (fileFilter == null || fileFilter.IsMatch(f.Name))); } if (!fileList.Any()) { var hasFilter = skipAudio || skipImages || skipScript || fileFilter != null; PrintError(hasFilter? "No files match the given filter": "Archive is empty"); return; } var fileArray = fileList.OrderBy(e => e.Offset).ToArray(); Console.WriteLine(fileArray[0].Offset); switch (command) { case "i": Console.WriteLine(m_fs.Source.Tag); break; case "l": ListFiles(fileArray); break; case "x": ExtractFiles(fileArray, m_fs.Source); break; } }