/// <summary> /// Begins an asynchronous Save operation, including downloading the full size image. /// The operation is synchronous until download begins, then asynch. /// </summary> internal void Save(Window dialogOwner) { var filePath = FilePath; if (String.IsNullOrEmpty(filePath)) { SaveAs(dialogOwner); return; } //Check that it is possible to save to FilePath try { //Check if FilePath already exists if (File.Exists(filePath)) { //Confirm overwrite filePath = OverwriteExistingWarning.Show(filePath, CreateSaveAsDialog(), dialogOwner); if (filePath == null) //Cancelled { return; } if (filePath != FilePath) { // Update the file path to indicate where it was actually saved FilePath = filePath; } } DirectoryInfo folder = new DirectoryInfo(Path.GetDirectoryName(filePath)); if (!folder.Exists) { folder.Create(); } //Create a dummy file so that other save operations will notice if they would overwrite them File.Create(filePath, 1).Close(); } catch (Exception e) { MessageBox.Show(dialogOwner, String.Format("Could not save image '{0}':\n\n{1}", filePath, e.Message), "Album Art Downloader", MessageBoxButton.OK, MessageBoxImage.Error); return; } IsSaving = true; //Pass the current filepath as a variable so that if the FilePath property changes, it will still be this filepath that's saved to, not the new one. RetrieveFullSizeImage(new WaitCallback(delegate { SaveInternal(filePath); })); }
private void SaveAs_Click(object sender, RoutedEventArgs e) { SaveAsDialog.FileName = Filename; if (SaveAsDialog.ShowDialog(Owner).GetValueOrDefault(false)) { Filename = SaveAsDialog.FileName; if (!SaveAsDialog.CheckFileExists && File.Exists(Filename)) { // Reshow the warning dialog for the new filename, which also needs overwrite confirmation Filename = OverwriteExistingWarning.Show(Filename, SaveAsDialog, Owner); } DialogResult = true; } }
private void UseSuggestion_Click(object sender, RoutedEventArgs e) { if (String.IsNullOrEmpty(SuggestedFilename)) { //Wait for a suggested filename to present itself this.Cursor = Cursors.Wait; this.IsEnabled = false; PropertyChanged += WaitForSuggestedFilename; return; } Filename = SuggestedFilename; if (File.Exists(Filename)) { // Reshow the warning dialog for the new filename, which also needs overwrite confirmation Filename = OverwriteExistingWarning.Show(Filename, SaveAsDialog, Owner); } DialogResult = true; }
public static string Show(string filename, SaveFileDialog saveAsDialog, Window owner) { var dialog = new OverwriteExistingWarning { Filename = filename, SaveAsDialog = saveAsDialog, Owner = owner }; dialog.InitializeComponent(); dialog.LoadSettings(); dialog.mDefaultButton.Focus(); ThreadPool.QueueUserWorkItem(dialog.GetExistingFileDetails); dialog.StartFilenameSuggestionWorker(); // Do this after LoadSettings, so the mSuggestedFilenamePattern.PathPattern is already present if (dialog.ShowDialog().GetValueOrDefault(false)) { return(dialog.Filename); } return(null); }