public OutputFile(FileInfo path, zsyncnet.ControlFile cf, Uri fileUri, Action <SyncState> stateUpdate = null) { _cf = cf; FilePath = path; _fileUri = fileUri; _blockSize = cf.GetHeader().Blocksize; _length = cf.GetHeader().Length; _lastBlockSize = (int)(_length % _blockSize == 0 ? _blockSize : _length % _blockSize); _sha1 = cf.GetHeader().Sha1; _mtime = cf.GetHeader().MTime; this.stateUpdate = stateUpdate; minCopyBlockCount = (int)(AssumedDownloadSpeedBytes / _blockSize); TempPath = new FileInfo(FilePath.FullName + ".part"); // Create all directories Directory.CreateDirectory(TempPath.Directory.FullName); // Open stream _tmpStream = new FileStream(TempPath.FullName, FileMode.Create, FileAccess.ReadWrite); _existingStream = new FileStream(FilePath.FullName, FileMode.OpenOrCreate, FileAccess.ReadWrite); _tmpStream.SetLength(_length); _remoteBlockSums = cf.GetBlockSums(); var fileBuffer = _existingStream.ToByteArray(); _existingStream.Position = 0; _localBlockSums = BlockSum.GenerateBlocksum(fileBuffer, cf.GetHeader().WeakChecksumLength, cf.GetHeader().StrongChecksumLength, cf.GetHeader().Blocksize); TotalBytesDownloaded = 0; // Set the last mod time to the time in the control file. }
public SyncOperation(BlockSum remoteBlock, BlockSum localBlock) { RemoteBlock = remoteBlock; LocalBlock = localBlock; }