private bool Check(ArchiveInformation info, FileStream fs) { _fileInfo.Refresh(); BinaryReader br = fs.GetBinaryReader(); fs.Seek(-24, SeekOrigin.End); int oldSize = br.ReadInt32(); if (oldSize != _fileInfo.Length) { return(false); } if (_fileInfo.LastWriteTimeUtc != info.FileTime) { return(false); } if (String.Compare(Path.GetFullPath(_fileInfo.FullName), Path.GetFullPath(info.ContentFilePath), StringComparison.InvariantCultureIgnoreCase) != 0) { return(false); } return(true); }
public void Write(ArchiveInformation info) { _fileInfo.Refresh(); info.FileTime = _fileInfo.LastWriteTimeUtc; long position = FindPosition(); using (FileStream fs = new FileStream(_fileInfo.FullName, FileMode.Open, FileAccess.Write, FileShare.ReadWrite)) using (BinaryWriter bw = new BinaryWriter(fs)) { if (position < 0) { position = _fileInfo.Length; } fs.Seek(position, SeekOrigin.Begin); BinaryFormatter bf = new BinaryFormatter(); bf.Serialize(fs, info); bw.Write((int)(fs.Position + 24)); bw.Write((int)(fs.Position - position)); bw.Write(MagicNumber); fs.SetLength(fs.Position); } info.FileSize = _fileInfo.Length; _fileInfo.LastWriteTimeUtc = info.FileTime; }
public ArchiveInformation Read() { long position = FindPosition(); if (position < 0) { return(null); } using (FileStream fs = new FileStream(_fileInfo.FullName, FileMode.Open, FileAccess.Read, FileShare.ReadWrite)) { fs.Seek(position, SeekOrigin.Begin); BinaryFormatter bf = new BinaryFormatter(); ArchiveInformation info = (ArchiveInformation)bf.Deserialize(fs); info.FileSize = _fileInfo.Length; if (!Check(info, fs)) { return(null); } return(info); } }
public ArchiveUncompressor(ArchiveInformation info, Stream input, Stream output) { Exceptions.CheckArgumentNull(info, "info"); Exceptions.CheckArgumentNull(input, "input"); Exceptions.CheckArgumentNull(output, "output"); _info = info; _input = input; _output = output; }
public void MoveFiles(ArchiveInformation target) { File.Delete(target.ContentFilePath); File.Delete(target.MetricFilePath); File.Move(ContentFilePath, target.ContentFilePath); File.Move(MetricFilePath, target.MetricFilePath); FilePath = target.FilePath; RootArchive.Name = target.RootArchive.Name; }
private ArchiveInformation CreateTargetArchiveInformation() { ArchiveInformation result = _info.GetTempArchiveInformation(); foreach (ArchiveFileEntry oldChild in _info.RootArchive.Childs.OfType <ArchiveFileEntry>()) { MoveFile(oldChild, result.RootArchive, result.RootDirectory); } MoveArchive(_info.RootArchive, result.RootArchive, result.RootDirectory); return(result); }
private void WriteMetrics(ArchiveInformation targetInfo) { using (Stream output = new FileStream(targetInfo.MetricFilePath, FileMode.Create, FileAccess.Write, FileShare.None)) using (BinaryWriter bw = new BinaryWriter(output)) { foreach (ArchiveFileEntry file in targetInfo.RootArchive.GetOrderedFileEntries().Values) { bw.Write(file.UncompressedContentSize); bw.Write(file.ContentOffset); bw.Write((int)Compression.None); } } }
private void WriteContent(MemoryMappedFile memoryFile, Stream outputStream, ArchiveInformation inputInfo, ArchiveInformation outputInfo) { List <ArchiveFileEntry> inputFiles = inputInfo.RootArchive.Expand(); List <ArchiveFileEntry> outputFiles = outputInfo.RootArchive.Expand(); for (int i = 0; i < inputFiles.Count; i++) { ArchiveFileEntry inputEntry = inputFiles[i]; ArchiveFileEntry outputEntry = outputFiles[i]; if (inputEntry.Name != outputEntry.Name) { throw new Exception("Порядок элементов в иерархиях изменился."); } using (Stream inputStream = memoryFile.CreateViewStream(inputEntry.GetAbsoluteOffset(), inputEntry.UncompressedContentSize)) { outputStream.Seek(outputEntry.GetAbsoluteOffset(), SeekOrigin.Begin); inputStream.CopyTo(outputStream); } Progress.NullSafeInvoke(this, new ProgressArgs(_info.ContentFilePath, Interlocked.Add(ref _processedSize, inputEntry.UncompressedContentSize), _totalProgress)); } }
public static int CalcUncompressedSize(ArchiveInformation info) { int result = 0; foreach (ArchiveArchiveEntry archive in info.RootArchive.Childs.OfType <ArchiveArchiveEntry>()) { result += archive.MetricsEntry.UncompressedContentSize; } foreach (ArchiveArchiveEntry archive in info.RootArchive.Childs.OfType <ArchiveArchiveEntry>()) { result += archive.ListingEntry.UncompressedContentSize; } foreach (ArchiveArchiveEntry archive in info.RootArchive.Childs.OfType <ArchiveArchiveEntry>()) { result += archive.ContentEntry.UncompressedContentSize; } foreach (ArchiveFileEntry file in info.RootArchive.Childs.OfType <ArchiveFileEntry>()) { result += file.UncompressedContentSize; } return(result); }
public ArchiveAnalizer(ArchiveInformation info) { Exceptions.CheckArgumentNull(info, "info"); _info = info; }