From 5253cf43adbb5e884fb1786adb367494dda696ee Mon Sep 17 00:00:00 2001 From: Jaex Date: Thu, 13 Mar 2014 11:13:02 +0200 Subject: [PATCH] Adding file exist actions --- HelpersLib/Helpers/Helpers.cs | 28 ++--- ShareX/Enums.cs | 12 ++ ShareX/Forms/FileExistForm.Designer.cs | 110 +++++++++++++++++++ ShareX/Forms/FileExistForm.cs | 73 +++++++++++++ ShareX/Forms/FileExistForm.resx | 120 ++++++++++++++++++++ ShareX/Forms/TaskSettingsForm.Designer.cs | 127 +++++++++++++--------- ShareX/Forms/TaskSettingsForm.cs | 10 +- ShareX/ShareX.csproj | 9 ++ ShareX/TaskHelpers.cs | 14 +++ ShareX/TaskSettings.cs | 5 +- ShareX/UploadTask.cs | 1 + 11 files changed, 438 insertions(+), 71 deletions(-) create mode 100644 ShareX/Forms/FileExistForm.Designer.cs create mode 100644 ShareX/Forms/FileExistForm.cs create mode 100644 ShareX/Forms/FileExistForm.resx diff --git a/HelpersLib/Helpers/Helpers.cs b/HelpersLib/Helpers/Helpers.cs index 40dc8b909..89a009cd9 100644 --- a/HelpersLib/Helpers/Helpers.cs +++ b/HelpersLib/Helpers/Helpers.cs @@ -516,33 +516,27 @@ public static bool IsValidURLRegex(string url) return Regex.IsMatch(url.Trim(), pattern, RegexOptions.IgnoreCase); } - public static string GetUniqueFilePath(string folder, string filename) + public static string GetUniqueFilePath(string filepath) { - string filepath = Path.Combine(folder, filename); - if (File.Exists(filepath)) { - string filenameWithoutExt, ext; - int num; + string folder = Path.GetDirectoryName(filepath); + string filename = Path.GetFileNameWithoutExtension(filepath); + string extension = Path.GetExtension(filepath); + int number = 1; - GroupCollection groups = Regex.Match(filepath, @"(.+ \()(\d+)(\)\.\w+)").Groups; + Match regex = Regex.Match(filepath, @"(.+) \((\d+)\)\.\w+"); - if (string.IsNullOrEmpty(groups[2].Value)) + if (regex.Success) { - filenameWithoutExt = Path.GetFileNameWithoutExtension(filename) + " ("; - num = 1; - ext = ")" + Path.GetExtension(filename); - } - else - { - filenameWithoutExt = groups[1].Value; - num = int.Parse(groups[2].Value); - ext = groups[3].Value; + filename = regex.Groups[1].Value; + number = int.Parse(regex.Groups[2].Value); } do { - filepath = filenameWithoutExt + ++num + ext; + number++; + filepath = Path.Combine(folder, string.Format("{0} ({1}){2}", filename, number, extension)); } while (File.Exists(filepath)); } diff --git a/ShareX/Enums.cs b/ShareX/Enums.cs index 7a6ce3ec4..8ed2f2e5a 100644 --- a/ShareX/Enums.cs +++ b/ShareX/Enums.cs @@ -184,4 +184,16 @@ public enum PopUpNotificationType [Description("Show toast notification with preview")] ToastNotification } + + public enum FileExistAction + { + [Description("Ask what to do")] + Ask, + [Description("Overwrite file")] + Overwrite, + [Description("Add number end of file name")] + NewName, + [Description("Don't save")] + Cancel + } } \ No newline at end of file diff --git a/ShareX/Forms/FileExistForm.Designer.cs b/ShareX/Forms/FileExistForm.Designer.cs new file mode 100644 index 000000000..2651f3d70 --- /dev/null +++ b/ShareX/Forms/FileExistForm.Designer.cs @@ -0,0 +1,110 @@ +namespace ShareX +{ + partial class FileExistForm + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + this.lblTitle = new System.Windows.Forms.Label(); + this.btnOverwrite = new System.Windows.Forms.Button(); + this.btnCancel = new System.Windows.Forms.Button(); + this.btnNewName = new System.Windows.Forms.Button(); + this.SuspendLayout(); + // + // lblTitle + // + this.lblTitle.AutoSize = true; + this.lblTitle.Font = new System.Drawing.Font("Microsoft Sans Serif", 9.75F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(162))); + this.lblTitle.Location = new System.Drawing.Point(8, 8); + this.lblTitle.Name = "lblTitle"; + this.lblTitle.Size = new System.Drawing.Size(346, 16); + this.lblTitle.TabIndex = 0; + this.lblTitle.Text = "There is already a file with the same name in this location."; + // + // btnOverwrite + // + this.btnOverwrite.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) + | System.Windows.Forms.AnchorStyles.Right))); + this.btnOverwrite.Location = new System.Drawing.Point(8, 32); + this.btnOverwrite.Name = "btnOverwrite"; + this.btnOverwrite.Size = new System.Drawing.Size(352, 32); + this.btnOverwrite.TabIndex = 1; + this.btnOverwrite.Text = "Overwrite: "; + this.btnOverwrite.TextAlign = System.Drawing.ContentAlignment.MiddleLeft; + this.btnOverwrite.UseVisualStyleBackColor = true; + this.btnOverwrite.Click += new System.EventHandler(this.btnOverwrite_Click); + // + // btnCancel + // + this.btnCancel.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) + | System.Windows.Forms.AnchorStyles.Right))); + this.btnCancel.Location = new System.Drawing.Point(8, 112); + this.btnCancel.Name = "btnCancel"; + this.btnCancel.Size = new System.Drawing.Size(352, 32); + this.btnCancel.TabIndex = 2; + this.btnCancel.Text = "Don\'t save"; + this.btnCancel.TextAlign = System.Drawing.ContentAlignment.MiddleLeft; + this.btnCancel.UseVisualStyleBackColor = true; + this.btnCancel.Click += new System.EventHandler(this.btnCancel_Click); + // + // btnNewName + // + this.btnNewName.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) + | System.Windows.Forms.AnchorStyles.Right))); + this.btnNewName.Location = new System.Drawing.Point(8, 72); + this.btnNewName.Name = "btnNewName"; + this.btnNewName.Size = new System.Drawing.Size(352, 32); + this.btnNewName.TabIndex = 3; + this.btnNewName.Text = "Save with new name: "; + this.btnNewName.TextAlign = System.Drawing.ContentAlignment.MiddleLeft; + this.btnNewName.UseVisualStyleBackColor = true; + this.btnNewName.Click += new System.EventHandler(this.btnNewName_Click); + // + // FileExistForm + // + this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(369, 154); + this.Controls.Add(this.btnNewName); + this.Controls.Add(this.btnCancel); + this.Controls.Add(this.btnOverwrite); + this.Controls.Add(this.lblTitle); + this.Name = "FileExistForm"; + this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen; + this.Text = "ShareX - How to save?"; + this.ResumeLayout(false); + this.PerformLayout(); + + } + + #endregion + + private System.Windows.Forms.Label lblTitle; + private System.Windows.Forms.Button btnOverwrite; + private System.Windows.Forms.Button btnCancel; + private System.Windows.Forms.Button btnNewName; + } +} \ No newline at end of file diff --git a/ShareX/Forms/FileExistForm.cs b/ShareX/Forms/FileExistForm.cs new file mode 100644 index 000000000..803787b24 --- /dev/null +++ b/ShareX/Forms/FileExistForm.cs @@ -0,0 +1,73 @@ +#region License Information (GPL v3) + +/* + ShareX - A program that allows you to take screenshots and share any file type + Copyright (C) 2008-2014 ShareX Developers + + This program is free software; you can redistribute it and/or + modify it under the terms of the GNU General Public License + as published by the Free Software Foundation; either version 2 + of the License, or (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + + Optionally you can also view the license at . +*/ + +#endregion License Information (GPL v3) + +using HelpersLib; +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Drawing; +using System.IO; +using System.Linq; +using System.Text; +using System.Windows.Forms; + +namespace ShareX +{ + public partial class FileExistForm : Form + { + public string Filepath { get; private set; } + + private string uniqueFilepath; + + public FileExistForm(string filepath) + { + InitializeComponent(); + Icon = ShareXResources.Icon; + + Filepath = filepath; + btnOverwrite.Text += Path.GetFileName(Filepath); + uniqueFilepath = Helpers.GetUniqueFilePath(Filepath); + btnNewName.Text += Path.GetFileName(uniqueFilepath); + } + + private void btnOverwrite_Click(object sender, EventArgs e) + { + Close(); + } + + private void btnNewName_Click(object sender, EventArgs e) + { + Filepath = uniqueFilepath; + Close(); + } + + private void btnCancel_Click(object sender, EventArgs e) + { + Filepath = string.Empty; + Close(); + } + } +} \ No newline at end of file diff --git a/ShareX/Forms/FileExistForm.resx b/ShareX/Forms/FileExistForm.resx new file mode 100644 index 000000000..7080a7d11 --- /dev/null +++ b/ShareX/Forms/FileExistForm.resx @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/ShareX/Forms/TaskSettingsForm.Designer.cs b/ShareX/Forms/TaskSettingsForm.Designer.cs index 00ec6c859..6cfee725b 100644 --- a/ShareX/Forms/TaskSettingsForm.Designer.cs +++ b/ShareX/Forms/TaskSettingsForm.Designer.cs @@ -44,6 +44,12 @@ private void InitializeComponent() this.btnAfterCapture = new HelpersLib.MenuButton(); this.btnAfterUpload = new HelpersLib.MenuButton(); this.btnDestinations = new HelpersLib.MenuButton(); + this.cmsDestinations = new System.Windows.Forms.ContextMenuStrip(this.components); + this.tsmiImageUploaders = new System.Windows.Forms.ToolStripMenuItem(); + this.tsmiTextUploaders = new System.Windows.Forms.ToolStripMenuItem(); + this.tsmiFileUploaders = new System.Windows.Forms.ToolStripMenuItem(); + this.tsmiURLShorteners = new System.Windows.Forms.ToolStripMenuItem(); + this.tsmiSocialServices = new System.Windows.Forms.ToolStripMenuItem(); this.btnTask = new HelpersLib.MenuButton(); this.tpGeneral = new System.Windows.Forms.TabPage(); this.panelGeneral = new System.Windows.Forms.Panel(); @@ -147,14 +153,11 @@ private void InitializeComponent() this.tpAdvanced = new System.Windows.Forms.TabPage(); this.pgTaskSettings = new System.Windows.Forms.PropertyGrid(); this.chkUseDefaultAdvancedSettings = new System.Windows.Forms.CheckBox(); - this.cmsDestinations = new System.Windows.Forms.ContextMenuStrip(this.components); - this.tsmiImageUploaders = new System.Windows.Forms.ToolStripMenuItem(); - this.tsmiTextUploaders = new System.Windows.Forms.ToolStripMenuItem(); - this.tsmiFileUploaders = new System.Windows.Forms.ToolStripMenuItem(); - this.tsmiURLShorteners = new System.Windows.Forms.ToolStripMenuItem(); - this.tsmiSocialServices = new System.Windows.Forms.ToolStripMenuItem(); + this.lblImageFileExist = new System.Windows.Forms.Label(); + this.cbImageFileExist = new System.Windows.Forms.ComboBox(); this.tcHotkeySettings.SuspendLayout(); this.tpTask.SuspendLayout(); + this.cmsDestinations.SuspendLayout(); this.tpGeneral.SuspendLayout(); this.panelGeneral.SuspendLayout(); this.tpImage.SuspendLayout(); @@ -184,7 +187,6 @@ private void InitializeComponent() this.tpUploadClipboard.SuspendLayout(); this.tpIndexer.SuspendLayout(); this.tpAdvanced.SuspendLayout(); - this.cmsDestinations.SuspendLayout(); this.SuspendLayout(); // // cmsAfterCapture @@ -349,6 +351,52 @@ private void InitializeComponent() this.btnDestinations.UseMnemonic = false; this.btnDestinations.UseVisualStyleBackColor = true; // + // cmsDestinations + // + this.cmsDestinations.Items.AddRange(new System.Windows.Forms.ToolStripItem[] { + this.tsmiImageUploaders, + this.tsmiTextUploaders, + this.tsmiFileUploaders, + this.tsmiURLShorteners, + this.tsmiSocialServices}); + this.cmsDestinations.Name = "cmsDestinations"; + this.cmsDestinations.Size = new System.Drawing.Size(213, 114); + // + // tsmiImageUploaders + // + this.tsmiImageUploaders.Image = global::ShareX.Properties.Resources.image; + this.tsmiImageUploaders.Name = "tsmiImageUploaders"; + this.tsmiImageUploaders.Size = new System.Drawing.Size(212, 22); + this.tsmiImageUploaders.Text = "Image uploaders"; + // + // tsmiTextUploaders + // + this.tsmiTextUploaders.Image = global::ShareX.Properties.Resources.notebook; + this.tsmiTextUploaders.Name = "tsmiTextUploaders"; + this.tsmiTextUploaders.Size = new System.Drawing.Size(212, 22); + this.tsmiTextUploaders.Text = "Text uploaders"; + // + // tsmiFileUploaders + // + this.tsmiFileUploaders.Image = global::ShareX.Properties.Resources.application_block; + this.tsmiFileUploaders.Name = "tsmiFileUploaders"; + this.tsmiFileUploaders.Size = new System.Drawing.Size(212, 22); + this.tsmiFileUploaders.Text = "File uploaders"; + // + // tsmiURLShorteners + // + this.tsmiURLShorteners.Image = global::ShareX.Properties.Resources.edit_scale; + this.tsmiURLShorteners.Name = "tsmiURLShorteners"; + this.tsmiURLShorteners.Size = new System.Drawing.Size(212, 22); + this.tsmiURLShorteners.Text = "URL shorteners"; + // + // tsmiSocialServices + // + this.tsmiSocialServices.Image = global::ShareX.Properties.Resources.globe_share; + this.tsmiSocialServices.Name = "tsmiSocialServices"; + this.tsmiSocialServices.Size = new System.Drawing.Size(212, 22); + this.tsmiSocialServices.Text = "Social networking services"; + // // btnTask // this.btnTask.Location = new System.Drawing.Point(6, 37); @@ -503,6 +551,8 @@ private void InitializeComponent() // // tpQuality // + this.tpQuality.Controls.Add(this.cbImageFileExist); + this.tpQuality.Controls.Add(this.lblImageFileExist); this.tpQuality.Controls.Add(this.lblImageFormat); this.tpQuality.Controls.Add(this.lblUseImageFormat2AfterHint); this.tpQuality.Controls.Add(this.cbImageFormat); @@ -520,7 +570,7 @@ private void InitializeComponent() this.tpQuality.Padding = new System.Windows.Forms.Padding(3); this.tpQuality.Size = new System.Drawing.Size(506, 301); this.tpQuality.TabIndex = 0; - this.tpQuality.Text = "Quality"; + this.tpQuality.Text = "General"; this.tpQuality.UseVisualStyleBackColor = true; // // lblImageFormat @@ -1564,51 +1614,24 @@ private void InitializeComponent() this.chkUseDefaultAdvancedSettings.UseVisualStyleBackColor = true; this.chkUseDefaultAdvancedSettings.CheckedChanged += new System.EventHandler(this.chkUseDefaultAdvancedSettings_CheckedChanged); // - // cmsDestinations + // lblImageFileExist // - this.cmsDestinations.Items.AddRange(new System.Windows.Forms.ToolStripItem[] { - this.tsmiImageUploaders, - this.tsmiTextUploaders, - this.tsmiFileUploaders, - this.tsmiURLShorteners, - this.tsmiSocialServices}); - this.cmsDestinations.Name = "cmsDestinations"; - this.cmsDestinations.Size = new System.Drawing.Size(213, 114); + this.lblImageFileExist.AutoSize = true; + this.lblImageFileExist.Location = new System.Drawing.Point(16, 176); + this.lblImageFileExist.Name = "lblImageFileExist"; + this.lblImageFileExist.Size = new System.Drawing.Size(56, 13); + this.lblImageFileExist.TabIndex = 12; + this.lblImageFileExist.Text = "If file exist:"; // - // tsmiImageUploaders + // cbImageFileExist // - this.tsmiImageUploaders.Image = global::ShareX.Properties.Resources.image; - this.tsmiImageUploaders.Name = "tsmiImageUploaders"; - this.tsmiImageUploaders.Size = new System.Drawing.Size(212, 22); - this.tsmiImageUploaders.Text = "Image uploaders"; - // - // tsmiTextUploaders - // - this.tsmiTextUploaders.Image = global::ShareX.Properties.Resources.notebook; - this.tsmiTextUploaders.Name = "tsmiTextUploaders"; - this.tsmiTextUploaders.Size = new System.Drawing.Size(212, 22); - this.tsmiTextUploaders.Text = "Text uploaders"; - // - // tsmiFileUploaders - // - this.tsmiFileUploaders.Image = global::ShareX.Properties.Resources.application_block; - this.tsmiFileUploaders.Name = "tsmiFileUploaders"; - this.tsmiFileUploaders.Size = new System.Drawing.Size(212, 22); - this.tsmiFileUploaders.Text = "File uploaders"; - // - // tsmiURLShorteners - // - this.tsmiURLShorteners.Image = global::ShareX.Properties.Resources.edit_scale; - this.tsmiURLShorteners.Name = "tsmiURLShorteners"; - this.tsmiURLShorteners.Size = new System.Drawing.Size(212, 22); - this.tsmiURLShorteners.Text = "URL shorteners"; - // - // tsmiSocialServices - // - this.tsmiSocialServices.Image = global::ShareX.Properties.Resources.globe_share; - this.tsmiSocialServices.Name = "tsmiSocialServices"; - this.tsmiSocialServices.Size = new System.Drawing.Size(212, 22); - this.tsmiSocialServices.Text = "Social networking services"; + this.cbImageFileExist.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList; + this.cbImageFileExist.FormattingEnabled = true; + this.cbImageFileExist.Location = new System.Drawing.Point(104, 172); + this.cbImageFileExist.Name = "cbImageFileExist"; + this.cbImageFileExist.Size = new System.Drawing.Size(176, 21); + this.cbImageFileExist.TabIndex = 13; + this.cbImageFileExist.SelectedIndexChanged += new System.EventHandler(this.cbImageFileExist_SelectedIndexChanged); // // TaskSettingsForm // @@ -1628,6 +1651,7 @@ private void InitializeComponent() this.tcHotkeySettings.ResumeLayout(false); this.tpTask.ResumeLayout(false); this.tpTask.PerformLayout(); + this.cmsDestinations.ResumeLayout(false); this.tpGeneral.ResumeLayout(false); this.tpGeneral.PerformLayout(); this.panelGeneral.ResumeLayout(false); @@ -1673,7 +1697,6 @@ private void InitializeComponent() this.tpIndexer.PerformLayout(); this.tpAdvanced.ResumeLayout(false); this.tpAdvanced.PerformLayout(); - this.cmsDestinations.ResumeLayout(false); this.ResumeLayout(false); } @@ -1804,6 +1827,8 @@ private void InitializeComponent() private System.Windows.Forms.ToolStripMenuItem tsmiFileUploaders; private System.Windows.Forms.ToolStripMenuItem tsmiURLShorteners; private System.Windows.Forms.ToolStripMenuItem tsmiSocialServices; + private System.Windows.Forms.ComboBox cbImageFileExist; + private System.Windows.Forms.Label lblImageFileExist; diff --git a/ShareX/Forms/TaskSettingsForm.cs b/ShareX/Forms/TaskSettingsForm.cs index fb9fb4a6c..2ea3716c7 100644 --- a/ShareX/Forms/TaskSettingsForm.cs +++ b/ShareX/Forms/TaskSettingsForm.cs @@ -121,12 +121,15 @@ public TaskSettingsForm(TaskSettings hotkeySetting, bool isDefault = false) cboPopUpNotification.SelectedIndex = (int)TaskSettings.GeneralSettings.PopUpNotification; cbHistorySave.Checked = TaskSettings.GeneralSettings.SaveHistory; - // Image - Quality + // Image - General cbImageFormat.SelectedIndex = (int)TaskSettings.ImageSettings.ImageFormat; nudImageJPEGQuality.Value = TaskSettings.ImageSettings.ImageJPEGQuality; cbImageGIFQuality.SelectedIndex = (int)TaskSettings.ImageSettings.ImageGIFQuality; nudUseImageFormat2After.Value = TaskSettings.ImageSettings.ImageSizeLimit; cbImageFormat2.SelectedIndex = (int)TaskSettings.ImageSettings.ImageFormat2; + cbImageFileExist.Items.Clear(); + cbImageFileExist.Items.AddRange(Helpers.GetEnumDescriptions()); + cbImageFileExist.SelectedIndex = (int)TaskSettings.ImageSettings.FileExistAction; // Image - Effects chkShowImageEffectsWindowAfterCapture.Checked = TaskSettings.ImageSettings.ShowImageEffectsWindowAfterCapture; @@ -512,6 +515,11 @@ private void nudUseImageFormat2After_ValueChanged(object sender, EventArgs e) TaskSettings.ImageSettings.ImageSizeLimit = (int)nudUseImageFormat2After.Value; } + private void cbImageFileExist_SelectedIndexChanged(object sender, EventArgs e) + { + TaskSettings.ImageSettings.FileExistAction = (FileExistAction)cbImageFileExist.SelectedIndex; + } + private void btnWatermarkSettings_Click(object sender, EventArgs e) { using (WatermarkForm watermarkForm = new WatermarkForm(TaskSettings.ImageSettings.WatermarkConfig) { Icon = Icon }) diff --git a/ShareX/ShareX.csproj b/ShareX/ShareX.csproj index 62e753991..82a210565 100644 --- a/ShareX/ShareX.csproj +++ b/ShareX/ShareX.csproj @@ -110,6 +110,12 @@ ExternalProgramForm.cs + + Form + + + FileExistForm.cs + Form @@ -230,6 +236,9 @@ ExternalProgramForm.cs + + FileExistForm.cs + ScreenColorPicker.cs diff --git a/ShareX/TaskHelpers.cs b/ShareX/TaskHelpers.cs index fb5bc008d..9a9fb5465 100644 --- a/ShareX/TaskHelpers.cs +++ b/ShareX/TaskHelpers.cs @@ -353,6 +353,20 @@ public static UpdateChecker CheckUpdate() return updateChecker; } + + public static string CheckFilename(string filepath, TaskSettings taskSettings) + { + if (File.Exists(filepath)) + { + using (FileExistForm form = new FileExistForm(filepath)) + { + form.ShowDialog(); + filepath = form.Filepath; + } + } + + return filepath; + } } public class PointInfo diff --git a/ShareX/TaskSettings.cs b/ShareX/TaskSettings.cs index 5b7eef999..5d0b16ee3 100644 --- a/ShareX/TaskSettings.cs +++ b/ShareX/TaskSettings.cs @@ -207,15 +207,16 @@ public class TaskSettingsGeneral public class TaskSettingsImage { - #region Image / Quality + #region Image / General public EImageFormat ImageFormat = EImageFormat.PNG; public int ImageJPEGQuality = 90; public GIFQuality ImageGIFQuality = GIFQuality.Default; public int ImageSizeLimit = 1024; public EImageFormat ImageFormat2 = EImageFormat.JPEG; + public FileExistAction FileExistAction = FileExistAction.Ask; - #endregion Image / Quality + #endregion Image / General #region Image / Effects diff --git a/ShareX/UploadTask.cs b/ShareX/UploadTask.cs index e2dd88944..78b914b3a 100644 --- a/ShareX/UploadTask.cs +++ b/ShareX/UploadTask.cs @@ -405,6 +405,7 @@ private void DoAfterCaptureJobs() if (Info.TaskSettings.AfterCaptureJob.HasFlag(AfterCaptureTasks.SaveImageToFile)) { Info.FilePath = Path.Combine(Program.ScreenshotsPath, Info.FileName); + Info.FilePath = TaskHelpers.CheckFilename(Info.FilePath, Info.TaskSettings); imageData.Write(Info.FilePath); DebugHelper.WriteLine("SaveImageToFile: " + Info.FilePath); }