public bool FileExists(string filename) { if (FileSystemCommands != null) { return(FileSystemCommands.FileExists(filename)); } throw new NullFileSystemCommandsStrategyException(); }
public Zip7CompressCommand(string exeLocation, string targetZipfilename, params string[] sourcesToZip) { ExeLocation = exeLocation; TargetZipfilename = targetZipfilename; SourcesToZip = sourcesToZip; FileSystemCommandsStrategy = new FileSystemCommands(); FileCompressionStrategy = this; }
public void FileCopy(string sourceFile, string destinationFile) { if (FileSystemCommands != null) { FileSystemCommands.FileCopy(sourceFile, destinationFile); return; } throw new NullFileSystemCommandsStrategyException(); }
public void FileDelete(string filename) { if (FileSystemCommands != null) { FileSystemCommands.FileDelete(filename); return; } throw new NullFileSystemCommandsStrategyException(); }
private bool sourceDirExists() { if (!FileSystemCommands.DirectoryExists(SourceDirectory)) { SendReport($"Cannot delete directory {SourceDirectory} because it doesn't exist", ReportType.DoneTaskWithSuccess); DidCommandSucceed = true; return(false); } return(true); }
protected bool TryWriteAccessToDirectory(string destinationDirectory) { int counter = 0; var tempFileName = Path.Combine(destinationDirectory, $"cc_test_file{counter}.tmp"); while (FileExists(tempFileName)) { counter++; tempFileName = Path.Combine(destinationDirectory, $"cc_test_file{counter}.tmp"); } FileSystemCommands.FileCreate(tempFileName); FileSystemCommands.FileDelete(tempFileName); return(true); }
public override void Cleanup() { if (!FileSystemCommands.DirectoryExists(BackedUpDirectory)) { SendReport($"Cannot delete contents of folder {SourceDirectory} during cleanup because it does not exist", ReportType.DoneTaskWithSuccess); return; } try { FileSystemCommands.DirectoryDelete(BackedUpDirectory); SendReport($"Deleted backup folder {BackedUpDirectory} during cleanup", ReportType.DoneCleanupWithSuccess); } catch (Exception exc) { SendReport($"Failed to delete backup folder {BackedUpDirectory} during cleanup. {exc.Message}", ReportType.DoneCleanupWithFailure); } }
/// <summary> /// Implements the copy path for selecteditems command(s) for /// left view A and right view B. /// </summary> /// <param name="p"></param> /// <param name="isFromA">Whether the selection parameter should be interpreted /// for left view A or right view B.</param> private static void CopySelectedItemsPathIntoClipboard(object p, bool isFromA) { var param = (p as string); if (param != null) { FileSystemCommands.CopyString(param); } else { var list = p as IEnumerable <IDirEntryViewModel>; if (list != null) { var scopy = new StringBuilder(); foreach (var item in list) { if (isFromA) { if (item.IsItemInA) { scopy.Append(item.ItemPathA + '\n'); } else { scopy.Append('\n'); } } else { if (item.IsItemInB) { scopy.Append(item.ItemPathB + '\n'); } else { scopy.Append('\n'); } } } FileSystemCommands.CopyString(scopy.ToString()); } } }
private bool createBackup() { BackedUpDirectory = Path.Combine(BackupDirectory, $"{new DirectoryInfo(SourceDirectory).Name}"); var counter = 0; while (FileSystemCommands.DirectoryExists(BackedUpDirectory)) { BackedUpDirectory = Path.Combine(BackupDirectory, $"{new DirectoryInfo(SourceDirectory).Name}{counter}"); counter++; } try { SendReport($"Creating backup of folder {SourceDirectory} to {BackedUpDirectory} ...", ReportType.Progress); FileSystemCommands.DirectoryCopyContents(SourceDirectory, BackedUpDirectory, null, null); SendReport($"Created backup of folder {SourceDirectory} to {BackedUpDirectory}", ReportType.Progress); return(true); } catch (Exception exc) { SendReport($"Directory delete aborted because attempt to backup folder {SourceDirectory} to {BackedUpDirectory} failed: {exc.Message}", ReportType.DoneTaskWithFailure); return(false); } }
private static void CopyHyperlinkUri(object sender, ExecutedRoutedEventArgs e) { try { if (sender == null || e == null) { return; } e.Handled = true; PathTrimmingFileHyperlink whLink = sender as PathTrimmingFileHyperlink; if (whLink == null) { return; } FileSystemCommands.CopyPath(whLink.NavigateUri); } catch { } }
/// <summary> /// Process command when a hyperlink has been clicked. /// Start a web browser and let it browse to where this points to... /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private static void Hyperlink_CommandNavigateTo(object sender, ExecutedRoutedEventArgs e) { try { if (sender == null || e == null) { return; } e.Handled = true; FileHyperlink whLink = sender as FileHyperlink; if (whLink == null) { return; } FileSystemCommands.OpenInWindows(whLink.NavigateUri); } catch {} }
protected bool TryReadAccessFromDirectory(string sourceDirectory) { FileSystemCommands.DirectoryGetFiles(sourceDirectory); return(true); }
public BaseFileCommand() { FileSystemCommands = new FileSystemCommands(); }
public static ITask NewDirectory(Action <FileSystemNewDirectoryParameters> parameters) { return(FileSystemCommands.NewDirectory().Execute(parameters)); }
public static ITask Delete(Action <FileSystemDeleteParameters> parameters) { return(FileSystemCommands.Delete().Execute(parameters)); }