private void ImportFile(string source, Folder destination, string name, CallbacksBase importCallbacks) { if (importCallbacks.ShouldAbort()) return; var f = new FileInfo(source); if (f.Length > _options.MaximumFileSize) throw new VFSException( string.Format("File is too big. Maximum file size is {0}. You can adjust the BlockSize in the Options to allow bigger files.", _options.MaximumFileSize)); var file = CreateFile(source, destination, name); AppendBlockReference(destination, file.BlockNumber); importCallbacks.CurrentlyProcessed++; }
public void Copy(IIndexNode nodeToCopy, Folder destination, string name, CallbacksBase copyCallbacks) { CheckDisposed(); CheckName(name); CheckVersion(); // Gather totals (copy in ~O(1) :D) copyCallbacks.TotalToProcess++; // Do the real copy if (nodeToCopy is Folder) CopyFolder(nodeToCopy as Folder, destination, name, copyCallbacks); else if (nodeToCopy is VFSFile) CopyFile(nodeToCopy as VFSFile, destination, name, copyCallbacks); else throw new ArgumentException("nodeToCopy must be of type Folder or VFSFile", "nodeToCopy"); SetBlocksUsed(); copyCallbacks.OperationCompleted(!copyCallbacks.ShouldAbort()); }
private void ExportFolder(Folder folder, string destination, CallbacksBase exportCallbacks) { if (exportCallbacks.ShouldAbort()) return; Directory.CreateDirectory(destination); exportCallbacks.CurrentlyProcessed++; foreach (var vfsFile in Files(folder)) { ExportFile(vfsFile, Path.Combine(destination, vfsFile.Name), exportCallbacks); } foreach (var f in Folders(folder)) { ExportFolder(f, Path.Combine(destination, f.Name), exportCallbacks); } }
private void ImportDirectory(string source, Folder destination, string name, CallbacksBase importCallbacks, bool createVersion) { if (importCallbacks.ShouldAbort()) return; var info = new DirectoryInfo(source); var newFolder = CreateFolder(destination, name, createVersion); importCallbacks.CurrentlyProcessed++; foreach (var directoryInfo in info.GetDirectories()) ImportDirectory(directoryInfo.FullName, newFolder, directoryInfo.Name, importCallbacks, false); foreach (var fileInfo in info.GetFiles()) ImportFile(fileInfo.FullName, newFolder, fileInfo.Name, importCallbacks); }
private void ExportFile(VFSFile file, string destination, CallbacksBase exportCallbacks) { if (exportCallbacks.ShouldAbort()) return; EnsureParentDirectoryExists(destination); using (var stream = File.OpenWrite(destination)) { using (var reader = DecorateToHostStream( new VFSFileStream(file, _blockParser, _options, _blockAllocation, _blockManipulator, _persistence))) { var buffer = new byte[_options.BlockSize]; int read; while ((read = reader.Read(buffer, 0, _options.BlockSize)) > 0) { stream.Write(buffer, 0, read); } } } exportCallbacks.CurrentlyProcessed++; }
private void CopyFolder(Folder folderToCopy, Folder destination, string name, CallbacksBase copyCallbacks) { if (copyCallbacks.ShouldAbort()) return; CheckName(name); var copiedFolder = CreateFolder(destination, name, true); copiedFolder.IndirectNodeNumber = folderToCopy.IndirectNodeNumber; copiedFolder.BlocksCount = folderToCopy.BlocksCount; copiedFolder.PredecessorBlockNr = folderToCopy.BlockNumber; //copiedFolder.Version = NextVersion; _persistence.Persist(copiedFolder); //ArchiveAndReplaceRoot(copiedFolder.Parent, null, copiedFolder); copyCallbacks.CurrentlyProcessed++; }
private void CopyFile(VFSFile fileToCopy, Folder destination, string name, CallbacksBase copyCallbacks) { if (copyCallbacks.ShouldAbort()) return; CheckName(name); var newFile = new VFSFile(name) { Parent = destination, BlockNumber = _blockAllocation.Allocate(), LastBlockSize = fileToCopy.LastBlockSize, IndirectNodeNumber = fileToCopy.IndirectNodeNumber, BlocksCount = fileToCopy.BlocksCount, PredecessorBlockNr = fileToCopy.BlockNumber, Version = NextVersion }; _persistence.Persist(newFile); copyCallbacks.CurrentlyProcessed++; ArchiveAndReplaceRoot(destination, null, newFile); }
public void Import(string source, Folder destination, string name, CallbacksBase importCallbacks) { CheckDisposed(); CheckName(name); CheckVersion(); destination = ArchiveAndReplaceRoot(destination, null, null); if (Directory.Exists(source)) CollectImportDirectoryTotals(source, importCallbacks); else if (File.Exists(source)) importCallbacks.TotalToProcess++; else throw new NotFoundException(); if (Directory.Exists(source)) ImportDirectory(source, destination, name, importCallbacks, false); else if (File.Exists(source)) ImportFile(source, destination, name, importCallbacks); else throw new NotFoundException(); SetBlocksUsed(); importCallbacks.OperationCompleted(!importCallbacks.ShouldAbort()); }
public void Export(IIndexNode source, string destination, CallbacksBase exportCallbacks) { var absoluteDestination = Path.GetFullPath(destination); EnsureParentDirectoryExists(absoluteDestination); CheckDisposed(); if (source == null) throw new NotFoundException(); if (File.Exists(absoluteDestination) || Directory.Exists(absoluteDestination)) throw new VFSException("Destination already exists!"); // Gather totals if (source is Folder) CollectExportDirectoryTotals(source as Folder, exportCallbacks); else if (source is VFSFile) exportCallbacks.TotalToProcess++; else throw new ArgumentException("Source must be of type Folder or VFSFile", "source"); // Do the real export if (source is Folder) ExportFolder(source as Folder, absoluteDestination, exportCallbacks); else ExportFile(source as VFSFile, absoluteDestination, exportCallbacks); exportCallbacks.OperationCompleted(!exportCallbacks.ShouldAbort()); }