// Resolves any conflicts for the given output path. // Returns a non-conflicting output path. // May return the same value if there are no conflicts. // null means cancel. public string ResolveOutputPathConflicts(string initialOutputPath, string sourcePath, HashSet <string> excludedPaths, bool isBatch) { // If the output is going to be the same as the source path, add (Encoded) to it if (string.Compare(initialOutputPath, sourcePath, StringComparison.InvariantCultureIgnoreCase) == 0) { string outputFolder = Path.GetDirectoryName(initialOutputPath); string fileNameWithoutExtension = Path.GetFileNameWithoutExtension(initialOutputPath); string extension = Path.GetExtension(initialOutputPath); initialOutputPath = Path.Combine(outputFolder, fileNameWithoutExtension + " (Encoded)" + extension); } HashSet <string> queuedFiles = excludedPaths; bool? conflict = Utilities.FileExists(initialOutputPath, queuedFiles); if (conflict == null) { return(initialOutputPath); } WhenFileExists preference; if (isBatch) { preference = CustomConfig.WhenFileExistsBatch; } else { preference = CustomConfig.WhenFileExists; } switch (preference) { case WhenFileExists.Prompt: break; case WhenFileExists.Overwrite: return(initialOutputPath); case WhenFileExists.AutoRename: return(FileUtilities.CreateUniqueFileName(initialOutputPath, queuedFiles)); default: throw new ArgumentOutOfRangeException(); } // Continue and prompt user for resolution string dialogMessageTemplate; if ((bool)conflict) { dialogMessageTemplate = MiscRes.FileConflictWarning; } else { dialogMessageTemplate = MiscRes.QueueFileConflictWarning; } string dialogMessage = string.Format(dialogMessageTemplate, initialOutputPath); var conflictDialog = new CustomMessageDialogViewModel <FileConflictResolution>( MiscRes.FileConflictDialogTitle, dialogMessage, new List <CustomDialogButton <FileConflictResolution> > { new CustomDialogButton <FileConflictResolution>(FileConflictResolution.Overwrite, MiscRes.OverwriteButton, ButtonType.Default), new CustomDialogButton <FileConflictResolution>(FileConflictResolution.AutoRename, MiscRes.AutoRenameButton), new CustomDialogButton <FileConflictResolution>(FileConflictResolution.Cancel, CommonRes.Cancel, ButtonType.Cancel), }); StaticResolver.Resolve <IWindowManager>().OpenDialog(conflictDialog); switch (conflictDialog.Result) { case FileConflictResolution.Cancel: return(null); case FileConflictResolution.Overwrite: return(initialOutputPath); case FileConflictResolution.AutoRename: return(FileUtilities.CreateUniqueFileName(initialOutputPath, queuedFiles)); default: throw new ArgumentOutOfRangeException(); } }
// Resolves any conflicts for the given output path. // Returns a non-conflicting output path. // May return the same value if there are no conflicts. // null means cancel. public string ResolveOutputPathConflicts(string initialOutputPath, HashSet <string> excludedPaths, bool isBatch) { HashSet <string> queuedFiles = excludedPaths; bool? conflict = Utilities.FileExists(initialOutputPath, queuedFiles); if (conflict == null) { return(initialOutputPath); } WhenFileExists preference; if (isBatch) { preference = CustomConfig.WhenFileExistsBatch; } else { preference = CustomConfig.WhenFileExists; } switch (preference) { case WhenFileExists.Prompt: break; case WhenFileExists.Overwrite: return(initialOutputPath); case WhenFileExists.AutoRename: return(FileUtilities.CreateUniqueFileName(initialOutputPath, queuedFiles)); default: throw new ArgumentOutOfRangeException(); } // Continue and prompt user for resolution string dialogMessageTemplate; if ((bool)conflict) { dialogMessageTemplate = MiscRes.FileConflictWarning; } else { dialogMessageTemplate = MiscRes.QueueFileConflictWarning; } string dialogMessage = string.Format(dialogMessageTemplate, initialOutputPath); var conflictDialog = new CustomMessageDialogViewModel <FileConflictResolution>( MiscRes.FileConflictDialogTitle, dialogMessage, new List <CustomDialogButton <FileConflictResolution> > { new CustomDialogButton <FileConflictResolution>(FileConflictResolution.Overwrite, MiscRes.OverwriteButton, ButtonType.Default), new CustomDialogButton <FileConflictResolution>(FileConflictResolution.AutoRename, MiscRes.AutoRenameButton), new CustomDialogButton <FileConflictResolution>(FileConflictResolution.Cancel, CommonRes.Cancel, ButtonType.Cancel), }); Ioc.Get <IWindowManager>().OpenDialog(conflictDialog); switch (conflictDialog.Result) { case FileConflictResolution.Cancel: return(null); case FileConflictResolution.Overwrite: return(initialOutputPath); case FileConflictResolution.AutoRename: return(FileUtilities.CreateUniqueFileName(initialOutputPath, queuedFiles)); default: throw new ArgumentOutOfRangeException(); } }