private void RebuildArchive(string path) { var archiveOptions = new ArcArchiveOptions { Mode = ArcArchiveMode.Create, // Layout = Format, CompressionLevel = CompressionLevel, SafeWrite = false, HeaderAreaLength = HeaderAreaSize, ChunkLength = ChunkSize, // TODO: UseLibDeflate = setup from global option }; using var progressBar = CreateProgressBar(); using var inputArchive = ArcArchive.Open(ArchivePath, ArcArchiveMode.Read); if (Format == default) { archiveOptions.Format = inputArchive.GetFormat(); } else { archiveOptions.Format = Format; } long totalLength = 0; foreach (var entry in inputArchive.GetEntries()) { totalLength += entry.Length; } progressBar.SetMaxValue(totalLength); if (true || SafeWrite) { var outputStream = new MemoryStream(); using var outputArchive = ArcArchive.Open(outputStream, archiveOptions); CopyEntries(inputArchive, outputArchive, progressBar); outputArchive.Dispose(); inputArchive.Dispose(); Utilities.ReplaceFile(ArchivePath, outputStream, progressBar); } else { // TODO: implement writing into different file throw Error.NotImplemented(); } }
public int Run() { Check.True(InputPaths.Count > 0); var archiveOptions = new ArcArchiveOptions { // Mode Format = Format, CompressionLevel = CompressionLevel, SafeWrite = SafeWrite, HeaderAreaLength = HeaderAreaSize, ChunkLength = ChunkSize, // TODO: UseLibDeflate = setup from global option }; var archiveExist = File.Exists(ArchivePath); archiveOptions.Mode = archiveExist ? ArcArchiveMode.Update : ArcArchiveMode.Create; long totalInputLength = 0; var inputFileInfos = new List <InputFileInfo>(); { using var progressBar = CreateProgressBar(); progressBar.Title = "Gathering input files..."; var inputs = GetAllInputs(); foreach (var inputFile in inputs) { progressBar.Message = inputFile; var fileInfo = new FileInfo(inputFile); totalInputLength += fileInfo.Length; var info = new InputFileInfo { FileName = inputFile, EntryName = CreateEntryName(inputFile), LastWriteTime = new DateTimeOffset(fileInfo.LastWriteTimeUtc), }; inputFileInfos.Add(info); } if (!PreserveCase) { var hashSet = new HashSet <string>(StringComparer.Ordinal); foreach (var x in inputFileInfos) { if (!hashSet.Add(x.EntryName)) { throw Error.InvalidOperation("Invalid casing. Final entry names must be unique."); } } } // Validate Entry Names foreach (var x in inputFileInfos) { EntryNameUtilities.Validate(x.EntryName); } } { using var progressBar = CreateProgressBar(); progressBar.Title = GetProcessInputFilesTitle(); using var archive = ArcArchive.Open(ArchivePath, archiveOptions); progressBar.SetMaxValue(totalInputLength); foreach (var inputFileInfo in inputFileInfos) { progressBar.Message = inputFileInfo.FileName; ProcessInputFile(archive, inputFileInfo, progressBar); } PostProcessArchive(archive, progressBar); } return(0); }