public void UnpackAll(UnpackOptions options = null) { options = options ?? new UnpackOptions(); if (!ArchiveFiles.Any()) { return; } options.DestinationDirectory = string.IsNullOrWhiteSpace(options.DestinationDirectory) ? Path.GetDirectoryName(ArchiveFiles.First()) : options.DestinationDirectory; var fileStream = ArchiveFiles .Select(File.OpenRead) .ToList(); using (var reader = RarReader.Open(fileStream)) { reader.CompressedBytesRead += CompressedBytesRead; reader.EntryExtractionBegin += EntryExtractionBegin; reader.EntryExtractionEnd += EntryExtractionEnd; reader.FilePartExtractionBegin += FilePartExtractionBegin; reader.WriteAllToDirectory(options.DestinationDirectory, new ExtractionOptions { ExtractFullPath = true, Overwrite = options.Overwrite }); if (options.DeleteArchiveOnSuccess) { foreach (var file in ArchiveFiles) { File.Delete(file); } } foreach (var stream in fileStream) { stream.Close(); stream.Dispose(); } } }
private static int RunUnpack(UnpackOptions args) { if (!Directory.Exists(args.InputDirectory)) { throw new Exception($"Non-existent input directory: {args.InputDirectory}"); } if (!Directory.Exists(args.OutputDirectory)) { Directory.CreateDirectory(args.OutputDirectory); } var profile = ResolveProfile(args.ProfileName); if (profile == null) { Console.WriteLine("ERROR: Unknown profile {0}", args.ProfileName); Console.WriteLine("AVAILABLE PROFILES:"); foreach (var baseProfile in Profiles) { Console.WriteLine("\tNAME: {0}", baseProfile.GetName()); } return(1); } var database = new Database(new DatabaseOptions(profile.GetGame(), profile.GetDatabaseType())); var files = profile.LoadFiles(database, args.InputDirectory); database.CompleteLoad(); var stopwatch = Stopwatch.StartNew(); var serializer = new DatabaseSerializer(database, args.OutputDirectory); serializer.Serialize(files); stopwatch.Stop(); Console.WriteLine("Exported database to {2} in {0}ms ({1:f2}s)", stopwatch.ElapsedMilliseconds, stopwatch.ElapsedMilliseconds / 1000f, args.OutputDirectory); return(0); }
private static int RunUnpack(UnpackOptions options) { Directory.CreateDirectory(options.TargetDir); using (var ifs = new FileStream(options.SourceFile, FileMode.Open, FileAccess.Read)) { var box = CzBox.Load(ifs); var def = box.GetContentDefinition(); if (def != null) { using (var cnBoxFs = new FileStream(Path.Combine(options.TargetDir, "contentDefinition.json"), FileMode.Create, FileAccess.Write)) AuthoringUtil.JsonSerialize(def, cnBoxFs); } foreach (var(name, srcResFs) in box.GetDataEnumerator()) { using (var resFs = new FileStream(Path.Combine(options.TargetDir, name), FileMode.Create, FileAccess.Write)) srcResFs.CopyTo(resFs); } } return(0); }