From 631c7c1983274930e92894b518c62eddf3a46e30 Mon Sep 17 00:00:00 2001 From: Mario Pistrich Date: Sat, 31 Oct 2015 17:01:49 +0100 Subject: [PATCH 1/2] Reopen save as dialog on errors after capture --- ShareX/WorkerTask.cs | 46 +++++++++++++++++++++++++++++--------------- 1 file changed, 30 insertions(+), 16 deletions(-) diff --git a/ShareX/WorkerTask.cs b/ShareX/WorkerTask.cs index 84cb017d2..89c53efad 100644 --- a/ShareX/WorkerTask.cs +++ b/ShareX/WorkerTask.cs @@ -561,24 +561,38 @@ private bool DoAfterCaptureJobs() { using (SaveFileDialog sfd = new SaveFileDialog()) { - if (string.IsNullOrEmpty(lastSaveAsFolder) || !Directory.Exists(lastSaveAsFolder)) - { - lastSaveAsFolder = Info.TaskSettings.CaptureFolder; - } + bool imageSaved = false; - sfd.InitialDirectory = lastSaveAsFolder; - sfd.FileName = Info.FileName; - sfd.DefaultExt = Path.GetExtension(Info.FileName).Substring(1); - sfd.Filter = string.Format("*{0}|*{0}|All files (*.*)|*.*", Path.GetExtension(Info.FileName)); - sfd.Title = Resources.UploadTask_DoAfterCaptureJobs_Choose_a_folder_to_save + " " + Path.GetFileName(Info.FileName); - - if (sfd.ShowDialog() == DialogResult.OK && !string.IsNullOrEmpty(sfd.FileName)) + do { - Info.FilePath = sfd.FileName; - lastSaveAsFolder = Path.GetDirectoryName(Info.FilePath); - imageData.Write(Info.FilePath); - DebugHelper.WriteLine("Image saved to file with dialog: " + Info.FilePath); - } + if (string.IsNullOrEmpty(lastSaveAsFolder) || !Directory.Exists(lastSaveAsFolder)) + { + lastSaveAsFolder = Info.TaskSettings.CaptureFolder; + } + + sfd.InitialDirectory = lastSaveAsFolder; + sfd.FileName = Info.FileName; + sfd.DefaultExt = Path.GetExtension(Info.FileName).Substring(1); + sfd.Filter = string.Format("*{0}|*{0}|All files (*.*)|*.*", Path.GetExtension(Info.FileName)); + sfd.Title = Resources.UploadTask_DoAfterCaptureJobs_Choose_a_folder_to_save + " " + Path.GetFileName(Info.FileName); + + if (sfd.ShowDialog() == DialogResult.OK && !string.IsNullOrEmpty(sfd.FileName)) + { + Info.FilePath = sfd.FileName; + lastSaveAsFolder = Path.GetDirectoryName(Info.FilePath); + imageSaved = imageData.Write(Info.FilePath) == Info.FilePath; + + if (imageSaved) + { + DebugHelper.WriteLine("Image saved to file with dialog: " + Info.FilePath); + } + } + else + { + // User cancelled the dialog - stop image saving retries. + break; + } + } while (!imageSaved); } } From a1281c5061337f56ff98288c469be78744e91b3d Mon Sep 17 00:00:00 2001 From: Mario Pistrich Date: Sat, 31 Oct 2015 20:40:37 +0100 Subject: [PATCH 2/2] Add message box when image write fails. --- ShareX/ImageData.cs | 5 +++++ ShareX/Properties/Resources.Designer.cs | 9 +++++++++ ShareX/Properties/Resources.resx | 3 +++ ShareX/WorkerTask.cs | 2 +- 4 files changed, 18 insertions(+), 1 deletion(-) diff --git a/ShareX/ImageData.cs b/ShareX/ImageData.cs index e0bd5fc3c..6d10e6272 100644 --- a/ShareX/ImageData.cs +++ b/ShareX/ImageData.cs @@ -24,8 +24,10 @@ You should have received a copy of the GNU General Public License #endregion License Information (GPL v3) using ShareX.HelpersLib; +using ShareX.Properties; using System; using System.IO; +using System.Windows.Forms; namespace ShareX { @@ -46,6 +48,9 @@ public string Write(string filePath) catch (Exception e) { DebugHelper.WriteException(e); + MessageBox.Show(new Form() { WindowState = FormWindowState.Maximized, TopMost = true }, + string.Format(Resources.ImageData_Write_Error + "\r\n\r\n" + e, filePath), "ShareX", + MessageBoxButtons.OK, MessageBoxIcon.Error); } return string.Empty; diff --git a/ShareX/Properties/Resources.Designer.cs b/ShareX/Properties/Resources.Designer.cs index 1fc1f6d72..21b2a8285 100644 --- a/ShareX/Properties/Resources.Designer.cs +++ b/ShareX/Properties/Resources.Designer.cs @@ -1035,6 +1035,15 @@ public static System.Drawing.Bitmap image_saturation { } } + /// + /// Looks up a localized string similar to Could not write image to path {0}.. + /// + public static string ImageData_Write_Error { + get { + return ResourceManager.GetString("ImageData_Write_Error", resourceCulture); + } + } + /// /// Looks up a localized resource of type System.Drawing.Bitmap. /// diff --git a/ShareX/Properties/Resources.resx b/ShareX/Properties/Resources.resx index 74643a801..a76d495bf 100644 --- a/ShareX/Properties/Resources.resx +++ b/ShareX/Properties/Resources.resx @@ -811,4 +811,7 @@ Would you like to restart ShareX? ..\Resources\vn.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a + + Could not write image to path {0}. + \ No newline at end of file diff --git a/ShareX/WorkerTask.cs b/ShareX/WorkerTask.cs index 89c53efad..ffae9a0fe 100644 --- a/ShareX/WorkerTask.cs +++ b/ShareX/WorkerTask.cs @@ -590,7 +590,7 @@ private bool DoAfterCaptureJobs() else { // User cancelled the dialog - stop image saving retries. - break; + return false; } } while (!imageSaved); }