From 7792e7d244eaeedd1ffdfa5c7beb79623fa55fcc Mon Sep 17 00:00:00 2001 From: Jaex Date: Sat, 11 Dec 2021 23:32:48 +0300 Subject: [PATCH] fixed #228: Added screenshot sub folder pattern for window, that way process name or window title can be used in folder names --- ShareX/ApplicationConfig.cs | 1 + .../Forms/ApplicationSettingsForm.Designer.cs | 25 +++++- ShareX/Forms/ApplicationSettingsForm.cs | 7 ++ ShareX/Forms/ApplicationSettingsForm.resx | 80 +++++++++++++++---- ShareX/ScreenRecordManager.cs | 4 +- ShareX/TaskHelpers.cs | 17 +++- ShareX/WorkerTask.cs | 6 +- 7 files changed, 112 insertions(+), 28 deletions(-) diff --git a/ShareX/ApplicationConfig.cs b/ShareX/ApplicationConfig.cs index 69da5f11e..f3a6b2e8a 100644 --- a/ShareX/ApplicationConfig.cs +++ b/ShareX/ApplicationConfig.cs @@ -93,6 +93,7 @@ public ApplicationConfig() public string CustomScreenshotsPath = ""; public string SaveImageSubFolderPattern = "%y-%mo"; + public string SaveImageSubFolderPatternWindow = ""; #endregion Paths diff --git a/ShareX/Forms/ApplicationSettingsForm.Designer.cs b/ShareX/Forms/ApplicationSettingsForm.Designer.cs index b4c69a02c..4ca87a153 100644 --- a/ShareX/Forms/ApplicationSettingsForm.Designer.cs +++ b/ShareX/Forms/ApplicationSettingsForm.Designer.cs @@ -123,6 +123,7 @@ private void InitializeComponent() this.cbMainWindowTaskViewMode = new System.Windows.Forms.ComboBox(); this.lblMainWindowTaskViewMode = new System.Windows.Forms.Label(); this.tpClipboardFormats = new System.Windows.Forms.TabPage(); + this.lblClipboardFormatsTip = new System.Windows.Forms.Label(); this.btnClipboardFormatEdit = new System.Windows.Forms.Button(); this.btnClipboardFormatRemove = new System.Windows.Forms.Button(); this.btnClipboardFormatAdd = new System.Windows.Forms.Button(); @@ -178,7 +179,8 @@ private void InitializeComponent() this.tpAdvanced = new System.Windows.Forms.TabPage(); this.pgSettings = new System.Windows.Forms.PropertyGrid(); this.tttvMain = new ShareX.HelpersLib.TabToTreeView(); - this.lblClipboardFormatsTip = new System.Windows.Forms.Label(); + this.lblSaveImageSubFolderPatternWindow = new System.Windows.Forms.Label(); + this.txtSaveImageSubFolderPatternWindow = new System.Windows.Forms.TextBox(); this.tcSettings.SuspendLayout(); this.tpGeneral.SuspendLayout(); this.tpTheme.SuspendLayout(); @@ -557,6 +559,8 @@ private void InitializeComponent() // tpPaths // this.tpPaths.BackColor = System.Drawing.SystemColors.Window; + this.tpPaths.Controls.Add(this.txtSaveImageSubFolderPatternWindow); + this.tpPaths.Controls.Add(this.lblSaveImageSubFolderPatternWindow); this.tpPaths.Controls.Add(this.btnPersonalFolderPathApply); this.tpPaths.Controls.Add(this.btnOpenScreenshotsFolder); this.tpPaths.Controls.Add(this.lblPreviewPersonalFolderPath); @@ -958,6 +962,11 @@ private void InitializeComponent() this.tpClipboardFormats.Name = "tpClipboardFormats"; this.tpClipboardFormats.UseVisualStyleBackColor = true; // + // lblClipboardFormatsTip + // + resources.ApplyResources(this.lblClipboardFormatsTip, "lblClipboardFormatsTip"); + this.lblClipboardFormatsTip.Name = "lblClipboardFormatsTip"; + // // btnClipboardFormatEdit // resources.ApplyResources(this.btnClipboardFormatEdit, "btnClipboardFormatEdit"); @@ -1394,10 +1403,16 @@ private void InitializeComponent() this.tttvMain.TreeViewSize = 175; this.tttvMain.TabChanged += new ShareX.HelpersLib.TabToTreeView.TabChangedEventHandler(this.tttvMain_TabChanged); // - // lblClipboardFormatsTip + // lblSaveImageSubFolderPatternWindow // - resources.ApplyResources(this.lblClipboardFormatsTip, "lblClipboardFormatsTip"); - this.lblClipboardFormatsTip.Name = "lblClipboardFormatsTip"; + resources.ApplyResources(this.lblSaveImageSubFolderPatternWindow, "lblSaveImageSubFolderPatternWindow"); + this.lblSaveImageSubFolderPatternWindow.Name = "lblSaveImageSubFolderPatternWindow"; + // + // txtSaveImageSubFolderPatternWindow + // + resources.ApplyResources(this.txtSaveImageSubFolderPatternWindow, "txtSaveImageSubFolderPatternWindow"); + this.txtSaveImageSubFolderPatternWindow.Name = "txtSaveImageSubFolderPatternWindow"; + this.txtSaveImageSubFolderPatternWindow.TextChanged += new System.EventHandler(this.txtSaveImageSubFolderPatternWindow_TextChanged); // // ApplicationSettingsForm // @@ -1615,5 +1630,7 @@ private void InitializeComponent() private System.Windows.Forms.Button btnThumbnailViewThumbnailSizeReset; private System.Windows.Forms.TabPage tpClipboardFormats; private System.Windows.Forms.Label lblClipboardFormatsTip; + private System.Windows.Forms.TextBox txtSaveImageSubFolderPatternWindow; + private System.Windows.Forms.Label lblSaveImageSubFolderPatternWindow; } } \ No newline at end of file diff --git a/ShareX/Forms/ApplicationSettingsForm.cs b/ShareX/Forms/ApplicationSettingsForm.cs index 37d94cb2a..be5c6c7ae 100644 --- a/ShareX/Forms/ApplicationSettingsForm.cs +++ b/ShareX/Forms/ApplicationSettingsForm.cs @@ -90,6 +90,7 @@ private void InitializeControls() eiTheme.ObjectType = typeof(ShareXTheme); CodeMenu.Create(txtSaveImageSubFolderPattern, CodeMenuEntryFilename.t, CodeMenuEntryFilename.pn, CodeMenuEntryFilename.i, CodeMenuEntryFilename.width, CodeMenuEntryFilename.height, CodeMenuEntryFilename.n); + CodeMenu.Create(txtSaveImageSubFolderPatternWindow, CodeMenuEntryFilename.i, CodeMenuEntryFilename.n); cbProxyMethod.Items.AddRange(Helpers.GetLocalizedEnumDescriptions()); @@ -169,6 +170,7 @@ private void UpdateControls() cbUseCustomScreenshotsPath.Checked = Program.Settings.UseCustomScreenshotsPath; txtCustomScreenshotsPath.Text = Program.Settings.CustomScreenshotsPath; txtSaveImageSubFolderPattern.Text = Program.Settings.SaveImageSubFolderPattern; + txtSaveImageSubFolderPatternWindow.Text = Program.Settings.SaveImageSubFolderPatternWindow; // Settings cbAutomaticallyCleanupBackupFiles.Checked = Program.Settings.AutoCleanupBackupFiles; @@ -715,6 +717,11 @@ private void btnOpenScreenshotsFolder_Click(object sender, EventArgs e) Helpers.OpenFolder(lblSaveImageSubFolderPatternPreview.Text); } + private void txtSaveImageSubFolderPatternWindow_TextChanged(object sender, EventArgs e) + { + Program.Settings.SaveImageSubFolderPatternWindow = Helpers.GetValidFolderPath(txtSaveImageSubFolderPatternWindow.Text); + } + #endregion Paths #region Settings diff --git a/ShareX/Forms/ApplicationSettingsForm.resx b/ShareX/Forms/ApplicationSettingsForm.resx index 6e4739a19..6e814284e 100644 --- a/ShareX/Forms/ApplicationSettingsForm.resx +++ b/ShareX/Forms/ApplicationSettingsForm.resx @@ -1260,6 +1260,54 @@ 2 + + 16, 232 + + + 408, 20 + + + 14 + + + txtSaveImageSubFolderPatternWindow + + + System.Windows.Forms.TextBox, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + tpPaths + + + 0 + + + True + + + 13, 216 + + + 148, 13 + + + 13 + + + Sub folder pattern for window: + + + lblSaveImageSubFolderPatternWindow + + + System.Windows.Forms.Label, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + tpPaths + + + 1 + NoControl @@ -1270,7 +1318,7 @@ 96, 23 - 13 + 3 Apply @@ -1285,7 +1333,7 @@ tpPaths - 0 + 2 NoControl @@ -1312,7 +1360,7 @@ tpPaths - 1 + 3 True @@ -1327,7 +1375,7 @@ 16, 13 - 4 + 5 ... @@ -1342,7 +1390,7 @@ tpPaths - 2 + 4 NoControl @@ -1369,7 +1417,7 @@ tpPaths - 3 + 5 True @@ -1399,7 +1447,7 @@ tpPaths - 4 + 6 16, 32 @@ -1420,7 +1468,7 @@ tpPaths - 5 + 7 NoControl @@ -1447,7 +1495,7 @@ tpPaths - 6 + 8 NoControl @@ -1459,7 +1507,7 @@ 96, 23 - 3 + 4 Open... @@ -1474,7 +1522,7 @@ tpPaths - 7 + 9 16, 112 @@ -1495,7 +1543,7 @@ tpPaths - 8 + 10 True @@ -1525,7 +1573,7 @@ tpPaths - 9 + 11 True @@ -1555,7 +1603,7 @@ tpPaths - 10 + 12 True @@ -1585,7 +1633,7 @@ tpPaths - 11 + 13 16, 160 @@ -1606,7 +1654,7 @@ tpPaths - 12 + 14 4, 22 diff --git a/ShareX/ScreenRecordManager.cs b/ShareX/ScreenRecordManager.cs index d2c792e9b..9c7dcb190 100644 --- a/ShareX/ScreenRecordManager.cs +++ b/ShareX/ScreenRecordManager.cs @@ -189,7 +189,7 @@ private static void StartRecording(ScreenRecordOutput outputType, TaskSettings t { extension = taskSettings.CaptureSettings.FFmpegOptions.Extension; } - string screenshotsFolder = TaskHelpers.GetScreenshotsFolder(taskSettings); + string screenshotsFolder = TaskHelpers.GetScreenshotsFolder(taskSettings, metadata); string fileName = TaskHelpers.GetFilename(taskSettings, extension, metadata); path = TaskHelpers.HandleExistsFile(screenshotsFolder, fileName, taskSettings); @@ -321,7 +321,7 @@ private static void ScreenRecorder_EncodingProgressChanged(int progress) private static string ProcessTwoPassEncoding(string input, TaskMetadata metadata, TaskSettings taskSettings, bool deleteInputFile = true) { - string screenshotsFolder = TaskHelpers.GetScreenshotsFolder(taskSettings); + string screenshotsFolder = TaskHelpers.GetScreenshotsFolder(taskSettings, metadata); string fileName = TaskHelpers.GetFilename(taskSettings, taskSettings.CaptureSettings.FFmpegOptions.Extension, metadata); string output = Path.Combine(screenshotsFolder, fileName); diff --git a/ShareX/TaskHelpers.cs b/ShareX/TaskHelpers.cs index 030272697..6d1a42f51 100644 --- a/ShareX/TaskHelpers.cs +++ b/ShareX/TaskHelpers.cs @@ -416,7 +416,7 @@ public static string GetFilename(TaskSettings taskSettings, string extension = n nameParser.ProcessName = metadata.ProcessName; } - if (!string.IsNullOrEmpty(nameParser.WindowText)) + if (!string.IsNullOrEmpty(taskSettings.UploadSettings.NameFormatPatternActiveWindow) && !string.IsNullOrEmpty(nameParser.WindowText)) { filename = nameParser.Parse(taskSettings.UploadSettings.NameFormatPatternActiveWindow); } @@ -459,8 +459,19 @@ public static string GetScreenshotsFolder(TaskSettings taskSettings = null, Task } else { - string subFolderPattern = nameParser.Parse(Program.Settings.SaveImageSubFolderPattern); - screenshotsFolder = Path.Combine(Program.ScreenshotsParentFolder, subFolderPattern); + string subFolderPattern; + + if (!string.IsNullOrEmpty(Program.Settings.SaveImageSubFolderPatternWindow) && !string.IsNullOrEmpty(nameParser.WindowText)) + { + subFolderPattern = Program.Settings.SaveImageSubFolderPatternWindow; + } + else + { + subFolderPattern = Program.Settings.SaveImageSubFolderPattern; + } + + string subFolderPath = nameParser.Parse(subFolderPattern); + screenshotsFolder = Path.Combine(Program.ScreenshotsParentFolder, subFolderPath); } return Helpers.GetAbsolutePath(screenshotsFolder); diff --git a/ShareX/WorkerTask.cs b/ShareX/WorkerTask.cs index 19b4c6f41..9eb08caff 100644 --- a/ShareX/WorkerTask.cs +++ b/ShareX/WorkerTask.cs @@ -632,7 +632,7 @@ private bool DoAfterCaptureJobs() if (Info.TaskSettings.AfterCaptureJob.HasFlag(AfterCaptureTasks.SaveImageToFile)) { - string screenshotsFolder = TaskHelpers.GetScreenshotsFolder(Info.TaskSettings); + string screenshotsFolder = TaskHelpers.GetScreenshotsFolder(Info.TaskSettings, Info.Metadata); string filePath = TaskHelpers.HandleExistsFile(screenshotsFolder, Info.FileName, Info.TaskSettings); if (!string.IsNullOrEmpty(filePath)) @@ -655,7 +655,7 @@ private bool DoAfterCaptureJobs() } else { - initialDirectory = TaskHelpers.GetScreenshotsFolder(Info.TaskSettings); + initialDirectory = TaskHelpers.GetScreenshotsFolder(Info.TaskSettings, Info.Metadata); } bool imageSaved; @@ -699,7 +699,7 @@ private bool DoAfterCaptureJobs() else { thumbnailFilename = Info.FileName; - thumbnailFolder = TaskHelpers.GetScreenshotsFolder(Info.TaskSettings); + thumbnailFolder = TaskHelpers.GetScreenshotsFolder(Info.TaskSettings, Info.Metadata); } Info.ThumbnailFilePath = TaskHelpers.CreateThumbnail(Image, thumbnailFolder, thumbnailFilename, Info.TaskSettings);