/// <summary></summary> /// <param name=""></param> private void CopyDirectory(PairOfFiles PairToCopy) { if (PairToCopy.eComparison == PairOfFiles.nComparison.DestinationOnly) { PairToCopy.eComparison = PairOfFiles.nComparison.Error; PairToCopy.sErrorMessage = "No source directory to copy at '" + PairToCopy.sRelativePath + "'."; } else if (PairToCopy.DestinationDrive.eEncryptionType == Drive.nEncryptionType.DirectoryUnencrypted) { DirectoryInfo DirectoryInfoDestination = new DirectoryInfo(PairToCopy.sDestinationPath); try { if (!DirectoryInfoDestination.Exists) { DirectoryInfoDestination.Create(); } } catch (Exception ex) { PairToCopy.eComparison = PairOfFiles.nComparison.Error; PairToCopy.sErrorMessage = ex.Message; } PairToCopy.CopyProperties(); try { DirectoryInfoDestination.Attributes = (FileAttributes)PairToCopy.uAttributesSource; DirectoryInfoDestination.CreationTime = Directory.GetCreationTime(PairToCopy.sSourcePath); DirectoryInfoDestination.LastAccessTime = Directory.GetLastAccessTime(PairToCopy.sSourcePath); DirectoryInfoDestination.LastWriteTime = PairToCopy.LastWriteTimeSource; } catch { } PairToCopy.eComparison = PairOfFiles.nComparison.Identical; _quReturn.Enqueue(new BackgroundMessage(BackgroundMessage.nType.ReportProgress, PairToCopy)); } else { throw new NotImplementedException("File system encryption is not yet implemented."); } }
/// <summary></summary> /// <param name=""></param> private void CopyFile(PairOfFiles PairToCopy) { FileInfo FileInfoDestination; if (PairToCopy.eComparison == PairOfFiles.nComparison.DestinationOnly) { PairToCopy.eComparison = PairOfFiles.nComparison.Error; PairToCopy.sErrorMessage = "No source file to copy: '" + PairToCopy.sRelativePath + "'."; } else if (PairToCopy.DestinationDrive.eEncryptionType == Drive.nEncryptionType.DirectoryUnencrypted) { FileInfoDestination = new FileInfo(PairToCopy.sDestinationPath); try { if (PairToCopy.SourceDrive.eEncryptionType == Drive.nEncryptionType.DirectoryUnencrypted) { if (PairToCopy.DestinationDrive.kFreeSpace < PairToCopy.kSourceSize) { PairToCopy.eComparison = PairOfFiles.nComparison.Error; PairToCopy.sErrorMessage = "Zu wenig Speicherplatz auf dem Ziellaufwerk."; } else { using (FileStream SourceStream = new FileStream(PairToCopy.sSourcePath, FileMode.Open, FileAccess.Read)) { using (FileStream DestinationStream = new FileStream(PairToCopy.sDestinationPath, FileMode.Create, FileAccess.Write)) CopyWithProgress(SourceStream, DestinationStream); } } } } catch (Exception ex) { PairToCopy.eComparison = PairOfFiles.nComparison.Error; PairToCopy.sErrorMessage = ex.Message; } if (_eState == nState.Working) { if (PairToCopy.eComparison != PairOfFiles.nComparison.Error) { PairToCopy.CopyProperties(); try { FileInfoDestination.Attributes = (FileAttributes)PairToCopy.uAttributesSource; FileInfoDestination.CreationTime = PairToCopy.CreationTimeSource; FileInfoDestination.LastAccessTime = PairToCopy.LastAccessTimeSource; FileInfoDestination.LastWriteTime = PairToCopy.LastWriteTimeSource; // synchronize the write time of the containing directory back to its original value // there is no point of resetting LastAccessTime as it also gets changed by reading access if (PairToCopy.ParentDirectory != null) { Directory.SetLastWriteTime(PairToCopy.ParentDirectory.sDestinationPath, PairToCopy.ParentDirectory.LastWriteTimeDestination); } } catch { } PairToCopy.eComparison = PairOfFiles.nComparison.Identical; } } else // _eState == nState.CancelRequested { try { if (FileInfoDestination.Exists) { FileInfoDestination.Delete(); } } catch (Exception ex) { PairToCopy.eComparison = PairOfFiles.nComparison.Error; PairToCopy.sErrorMessage = ex.Message; } PairToCopy.eComparison = PairOfFiles.nComparison.Error; PairToCopy.sErrorMessage = "Das Kopieren der Datei wurde vom Benutzer abgebrochen."; } _quReturn.Enqueue(new BackgroundMessage(BackgroundMessage.nType.ReportProgress, PairToCopy)); } else { throw new NotImplementedException("File system encryption is not yet implemented."); } }