diff --git a/ShareX/ApplicationConfig.cs b/ShareX/ApplicationConfig.cs
index de57ea27d..2452e63b8 100644
--- a/ShareX/ApplicationConfig.cs
+++ b/ShareX/ApplicationConfig.cs
@@ -108,6 +108,14 @@ public ApplicationConfig()
#endregion Paths
+ #region Settings
+
+ public bool AutoCleanupBackupFiles = false;
+ public bool AutoCleanupLogFiles = false;
+ public int CleanupKeepFileCount = 10;
+
+ #endregion
+
#region Proxy
public ProxyInfo ProxySettings = new ProxyInfo();
diff --git a/ShareX/CleanupManager.cs b/ShareX/CleanupManager.cs
new file mode 100644
index 000000000..054f265cf
--- /dev/null
+++ b/ShareX/CleanupManager.cs
@@ -0,0 +1,106 @@
+#region License Information (GPL v3)
+
+/*
+ ShareX - A program that allows you to take screenshots and share any file type
+ Copyright (c) 2007-2020 ShareX Team
+
+ 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 ShareX.HelpersLib;
+using System;
+using System.Collections.Generic;
+using System.IO;
+using System.Linq;
+using System.Threading.Tasks;
+
+namespace ShareX
+{
+ public static class CleanupManager
+ {
+ public static void Cleanup()
+ {
+ if (Program.Settings == null) return;
+
+ int keepFileCount = Math.Max(Program.Settings.CleanupKeepFileCount, 0);
+
+ try
+ {
+ CleanupAppTempFolder();
+
+ if (Program.Settings.AutoCleanupBackupFiles)
+ {
+ CleanupFolder(SettingManager.BackupFolder, "ApplicationConfig-*.json", keepFileCount);
+ CleanupFolder(SettingManager.BackupFolder, "HotkeysConfig-*.json", keepFileCount);
+ CleanupFolder(SettingManager.BackupFolder, "UploadersConfig-*.json", keepFileCount);
+ CleanupFolder(SettingManager.BackupFolder, "History-*.json", keepFileCount);
+ }
+
+ if (Program.Settings.AutoCleanupLogFiles)
+ {
+ CleanupFolder(Program.LogsFolder, "ShareX-Log-*.txt", keepFileCount);
+ }
+ }
+ catch (Exception e)
+ {
+ DebugHelper.WriteException(e);
+ }
+ }
+
+ public static void CleanupAsync()
+ {
+ Task.Run(() =>
+ {
+ Cleanup();
+ });
+ }
+
+ private static void CleanupFolder(string folderPath, string fileNamePattern, int keepFileCount)
+ {
+ DirectoryInfo directoryInfo = new DirectoryInfo(folderPath);
+
+ IEnumerable files = directoryInfo.GetFiles(fileNamePattern).
+ OrderByDescending(f => f.LastWriteTime.Year <= 1601 ? f.CreationTime : f.LastWriteTime).Skip(keepFileCount);
+
+ foreach (FileInfo file in files)
+ {
+ file.Delete();
+
+ DebugHelper.WriteLine($"File deleted: {file.FullName}");
+ }
+ }
+
+ private static void CleanupAppTempFolder()
+ {
+ string tempFolder = Path.GetTempPath();
+
+ if (!string.IsNullOrEmpty(tempFolder))
+ {
+ string folderPath = Path.Combine(tempFolder, "ShareX");
+
+ if (Directory.Exists(folderPath))
+ {
+ Directory.Delete(folderPath, true);
+
+ DebugHelper.WriteLine($"ShareX temp folder cleaned: {folderPath}");
+ }
+ }
+ }
+ }
+}
\ No newline at end of file
diff --git a/ShareX/Forms/ApplicationSettingsForm.Designer.cs b/ShareX/Forms/ApplicationSettingsForm.Designer.cs
index 2cbee8650..0f7da08d3 100644
--- a/ShareX/Forms/ApplicationSettingsForm.Designer.cs
+++ b/ShareX/Forms/ApplicationSettingsForm.Designer.cs
@@ -45,7 +45,6 @@ private void InitializeComponent()
this.btnEditQuickTaskMenu = new System.Windows.Forms.Button();
this.cbShowTray = new System.Windows.Forms.CheckBox();
this.cbTrayIconProgressEnabled = new System.Windows.Forms.CheckBox();
- this.btnLanguages = new ShareX.HelpersLib.MenuButton();
this.cmsLanguages = new System.Windows.Forms.ContextMenuStrip(this.components);
this.cbRememberMainFormPosition = new System.Windows.Forms.CheckBox();
this.cbSilentRun = new System.Windows.Forms.CheckBox();
@@ -54,7 +53,6 @@ private void InitializeComponent()
this.lblLanguage = new System.Windows.Forms.Label();
this.tpTheme = new System.Windows.Forms.TabPage();
this.btnThemeReset = new System.Windows.Forms.Button();
- this.eiTheme = new ShareX.HelpersLib.ExportImportControl();
this.btnThemeRemove = new System.Windows.Forms.Button();
this.btnThemeAdd = new System.Windows.Forms.Button();
this.cbThemes = new System.Windows.Forms.ComboBox();
@@ -110,19 +108,10 @@ private void InitializeComponent()
this.btnClipboardFormatEdit = new System.Windows.Forms.Button();
this.btnClipboardFormatRemove = new System.Windows.Forms.Button();
this.btnClipboardFormatAdd = new System.Windows.Forms.Button();
- this.lvClipboardFormats = new ShareX.HelpersLib.MyListView();
- this.chDescription = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader()));
- this.chFormat = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader()));
this.tpUploadRetry = new System.Windows.Forms.TabPage();
this.gbSecondaryFileUploaders = new System.Windows.Forms.GroupBox();
- this.lvSecondaryFileUploaders = new ShareX.HelpersLib.MyListView();
- this.chSecondaryFileUploaders = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader()));
this.gbSecondaryImageUploaders = new System.Windows.Forms.GroupBox();
- this.lvSecondaryImageUploaders = new ShareX.HelpersLib.MyListView();
- this.chSecondaryImageUploaders = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader()));
this.gbSecondaryTextUploaders = new System.Windows.Forms.GroupBox();
- this.lvSecondaryTextUploaders = new ShareX.HelpersLib.MyListView();
- this.chSecondaryTextUploaders = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader()));
this.chkUseSecondaryUploaders = new System.Windows.Forms.CheckBox();
this.cbIfUploadFailRetryOnce = new System.Windows.Forms.Label();
this.nudRetryUpload = new System.Windows.Forms.NumericUpDown();
@@ -154,6 +143,21 @@ private void InitializeComponent()
this.txtProxyUsername = new System.Windows.Forms.TextBox();
this.tpAdvanced = new System.Windows.Forms.TabPage();
this.pgSettings = new System.Windows.Forms.PropertyGrid();
+ this.cbAutomaticallyCleanupBackupFiles = new System.Windows.Forms.CheckBox();
+ this.lblCleanupKeepFileCount = new System.Windows.Forms.Label();
+ this.nudCleanupKeepFileCount = new System.Windows.Forms.NumericUpDown();
+ this.cbAutomaticallyCleanupLogFiles = new System.Windows.Forms.CheckBox();
+ this.btnLanguages = new ShareX.HelpersLib.MenuButton();
+ this.eiTheme = new ShareX.HelpersLib.ExportImportControl();
+ this.lvClipboardFormats = new ShareX.HelpersLib.MyListView();
+ this.chDescription = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader()));
+ this.chFormat = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader()));
+ this.lvSecondaryFileUploaders = new ShareX.HelpersLib.MyListView();
+ this.chSecondaryFileUploaders = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader()));
+ this.lvSecondaryImageUploaders = new ShareX.HelpersLib.MyListView();
+ this.chSecondaryImageUploaders = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader()));
+ this.lvSecondaryTextUploaders = new ShareX.HelpersLib.MyListView();
+ this.chSecondaryTextUploaders = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader()));
this.tttvMain = new ShareX.HelpersLib.TabToTreeView();
this.tcSettings.SuspendLayout();
this.tpGeneral.SuspendLayout();
@@ -185,6 +189,7 @@ private void InitializeComponent()
this.tpProxy.SuspendLayout();
((System.ComponentModel.ISupportInitialize)(this.nudProxyPort)).BeginInit();
this.tpAdvanced.SuspendLayout();
+ ((System.ComponentModel.ISupportInitialize)(this.nudCleanupKeepFileCount)).BeginInit();
this.SuspendLayout();
//
// tcSettings
@@ -308,13 +313,6 @@ private void InitializeComponent()
this.cbTrayIconProgressEnabled.UseVisualStyleBackColor = true;
this.cbTrayIconProgressEnabled.CheckedChanged += new System.EventHandler(this.cbTrayIconProgressEnabled_CheckedChanged);
//
- // btnLanguages
- //
- resources.ApplyResources(this.btnLanguages, "btnLanguages");
- this.btnLanguages.Menu = this.cmsLanguages;
- this.btnLanguages.Name = "btnLanguages";
- this.btnLanguages.UseVisualStyleBackColor = true;
- //
// cmsLanguages
//
this.cmsLanguages.Name = "cmsLanguages";
@@ -356,12 +354,12 @@ private void InitializeComponent()
// tpTheme
//
this.tpTheme.Controls.Add(this.btnThemeReset);
- this.tpTheme.Controls.Add(this.eiTheme);
this.tpTheme.Controls.Add(this.btnThemeRemove);
this.tpTheme.Controls.Add(this.btnThemeAdd);
this.tpTheme.Controls.Add(this.cbThemes);
this.tpTheme.Controls.Add(this.pgTheme);
this.tpTheme.Controls.Add(this.cbUseCustomTheme);
+ this.tpTheme.Controls.Add(this.eiTheme);
resources.ApplyResources(this.tpTheme, "tpTheme");
this.tpTheme.Name = "tpTheme";
this.tpTheme.UseVisualStyleBackColor = true;
@@ -373,16 +371,6 @@ private void InitializeComponent()
this.btnThemeReset.UseVisualStyleBackColor = true;
this.btnThemeReset.Click += new System.EventHandler(this.BtnThemeReset_Click);
//
- // eiTheme
- //
- this.eiTheme.DefaultFileName = null;
- resources.ApplyResources(this.eiTheme, "eiTheme");
- this.eiTheme.Name = "eiTheme";
- this.eiTheme.ObjectType = null;
- this.eiTheme.SerializationBinder = null;
- this.eiTheme.ExportRequested += new ShareX.HelpersLib.ExportImportControl.ExportEventHandler(this.EiTheme_ExportRequested);
- this.eiTheme.ImportRequested += new ShareX.HelpersLib.ExportImportControl.ImportEventHandler(this.EiTheme_ImportRequested);
- //
// btnThemeRemove
//
resources.ApplyResources(this.btnThemeRemove, "btnThemeRemove");
@@ -628,6 +616,10 @@ private void InitializeComponent()
// tpSettings
//
this.tpSettings.BackColor = System.Drawing.SystemColors.Window;
+ this.tpSettings.Controls.Add(this.cbAutomaticallyCleanupLogFiles);
+ this.tpSettings.Controls.Add(this.nudCleanupKeepFileCount);
+ this.tpSettings.Controls.Add(this.lblCleanupKeepFileCount);
+ this.tpSettings.Controls.Add(this.cbAutomaticallyCleanupBackupFiles);
this.tpSettings.Controls.Add(this.pbExportImportNote);
this.tpSettings.Controls.Add(this.cbExportHistory);
this.tpSettings.Controls.Add(this.cbExportSettings);
@@ -801,28 +793,6 @@ private void InitializeComponent()
this.btnClipboardFormatAdd.UseVisualStyleBackColor = true;
this.btnClipboardFormatAdd.Click += new System.EventHandler(this.btnAddClipboardFormat_Click);
//
- // lvClipboardFormats
- //
- resources.ApplyResources(this.lvClipboardFormats, "lvClipboardFormats");
- this.lvClipboardFormats.AutoFillColumn = true;
- this.lvClipboardFormats.Columns.AddRange(new System.Windows.Forms.ColumnHeader[] {
- this.chDescription,
- this.chFormat});
- this.lvClipboardFormats.FullRowSelect = true;
- this.lvClipboardFormats.HideSelection = false;
- this.lvClipboardFormats.Name = "lvClipboardFormats";
- this.lvClipboardFormats.UseCompatibleStateImageBehavior = false;
- this.lvClipboardFormats.View = System.Windows.Forms.View.Details;
- this.lvClipboardFormats.MouseDoubleClick += new System.Windows.Forms.MouseEventHandler(this.lvClipboardFormats_MouseDoubleClick);
- //
- // chDescription
- //
- resources.ApplyResources(this.chDescription, "chDescription");
- //
- // chFormat
- //
- resources.ApplyResources(this.chFormat, "chFormat");
- //
// tpUploadRetry
//
this.tpUploadRetry.BackColor = System.Drawing.SystemColors.Window;
@@ -842,24 +812,6 @@ private void InitializeComponent()
this.gbSecondaryFileUploaders.Name = "gbSecondaryFileUploaders";
this.gbSecondaryFileUploaders.TabStop = false;
//
- // lvSecondaryFileUploaders
- //
- this.lvSecondaryFileUploaders.AllowDrop = true;
- this.lvSecondaryFileUploaders.AllowItemDrag = true;
- this.lvSecondaryFileUploaders.AutoFillColumn = true;
- this.lvSecondaryFileUploaders.BorderStyle = System.Windows.Forms.BorderStyle.None;
- this.lvSecondaryFileUploaders.Columns.AddRange(new System.Windows.Forms.ColumnHeader[] {
- this.chSecondaryFileUploaders});
- resources.ApplyResources(this.lvSecondaryFileUploaders, "lvSecondaryFileUploaders");
- this.lvSecondaryFileUploaders.FullRowSelect = true;
- this.lvSecondaryFileUploaders.HeaderStyle = System.Windows.Forms.ColumnHeaderStyle.None;
- this.lvSecondaryFileUploaders.HideSelection = false;
- this.lvSecondaryFileUploaders.MultiSelect = false;
- this.lvSecondaryFileUploaders.Name = "lvSecondaryFileUploaders";
- this.lvSecondaryFileUploaders.UseCompatibleStateImageBehavior = false;
- this.lvSecondaryFileUploaders.View = System.Windows.Forms.View.Details;
- this.lvSecondaryFileUploaders.MouseUp += new System.Windows.Forms.MouseEventHandler(this.lvSecondaryUploaders_MouseUp);
- //
// gbSecondaryImageUploaders
//
this.gbSecondaryImageUploaders.Controls.Add(this.lvSecondaryImageUploaders);
@@ -867,24 +819,6 @@ private void InitializeComponent()
this.gbSecondaryImageUploaders.Name = "gbSecondaryImageUploaders";
this.gbSecondaryImageUploaders.TabStop = false;
//
- // lvSecondaryImageUploaders
- //
- this.lvSecondaryImageUploaders.AllowDrop = true;
- this.lvSecondaryImageUploaders.AllowItemDrag = true;
- this.lvSecondaryImageUploaders.AutoFillColumn = true;
- this.lvSecondaryImageUploaders.BorderStyle = System.Windows.Forms.BorderStyle.None;
- this.lvSecondaryImageUploaders.Columns.AddRange(new System.Windows.Forms.ColumnHeader[] {
- this.chSecondaryImageUploaders});
- resources.ApplyResources(this.lvSecondaryImageUploaders, "lvSecondaryImageUploaders");
- this.lvSecondaryImageUploaders.FullRowSelect = true;
- this.lvSecondaryImageUploaders.HeaderStyle = System.Windows.Forms.ColumnHeaderStyle.None;
- this.lvSecondaryImageUploaders.HideSelection = false;
- this.lvSecondaryImageUploaders.MultiSelect = false;
- this.lvSecondaryImageUploaders.Name = "lvSecondaryImageUploaders";
- this.lvSecondaryImageUploaders.UseCompatibleStateImageBehavior = false;
- this.lvSecondaryImageUploaders.View = System.Windows.Forms.View.Details;
- this.lvSecondaryImageUploaders.MouseUp += new System.Windows.Forms.MouseEventHandler(this.lvSecondaryUploaders_MouseUp);
- //
// gbSecondaryTextUploaders
//
this.gbSecondaryTextUploaders.Controls.Add(this.lvSecondaryTextUploaders);
@@ -892,24 +826,6 @@ private void InitializeComponent()
this.gbSecondaryTextUploaders.Name = "gbSecondaryTextUploaders";
this.gbSecondaryTextUploaders.TabStop = false;
//
- // lvSecondaryTextUploaders
- //
- this.lvSecondaryTextUploaders.AllowDrop = true;
- this.lvSecondaryTextUploaders.AllowItemDrag = true;
- this.lvSecondaryTextUploaders.AutoFillColumn = true;
- this.lvSecondaryTextUploaders.BorderStyle = System.Windows.Forms.BorderStyle.None;
- this.lvSecondaryTextUploaders.Columns.AddRange(new System.Windows.Forms.ColumnHeader[] {
- this.chSecondaryTextUploaders});
- resources.ApplyResources(this.lvSecondaryTextUploaders, "lvSecondaryTextUploaders");
- this.lvSecondaryTextUploaders.FullRowSelect = true;
- this.lvSecondaryTextUploaders.HeaderStyle = System.Windows.Forms.ColumnHeaderStyle.None;
- this.lvSecondaryTextUploaders.HideSelection = false;
- this.lvSecondaryTextUploaders.MultiSelect = false;
- this.lvSecondaryTextUploaders.Name = "lvSecondaryTextUploaders";
- this.lvSecondaryTextUploaders.UseCompatibleStateImageBehavior = false;
- this.lvSecondaryTextUploaders.View = System.Windows.Forms.View.Details;
- this.lvSecondaryTextUploaders.MouseUp += new System.Windows.Forms.MouseEventHandler(this.lvSecondaryUploaders_MouseUp);
- //
// chkUseSecondaryUploaders
//
resources.ApplyResources(this.chkUseSecondaryUploaders, "chkUseSecondaryUploaders");
@@ -1147,6 +1063,134 @@ private void InitializeComponent()
this.pgSettings.PropertySort = System.Windows.Forms.PropertySort.Categorized;
this.pgSettings.ToolbarVisible = false;
//
+ // cbAutomaticallyCleanupBackupFiles
+ //
+ resources.ApplyResources(this.cbAutomaticallyCleanupBackupFiles, "cbAutomaticallyCleanupBackupFiles");
+ this.cbAutomaticallyCleanupBackupFiles.Name = "cbAutomaticallyCleanupBackupFiles";
+ this.cbAutomaticallyCleanupBackupFiles.UseVisualStyleBackColor = true;
+ this.cbAutomaticallyCleanupBackupFiles.CheckedChanged += new System.EventHandler(this.cbAutomaticallyCleanupBackupFiles_CheckedChanged);
+ //
+ // lblCleanupKeepFileCount
+ //
+ resources.ApplyResources(this.lblCleanupKeepFileCount, "lblCleanupKeepFileCount");
+ this.lblCleanupKeepFileCount.Name = "lblCleanupKeepFileCount";
+ //
+ // nudCleanupKeepFileCount
+ //
+ resources.ApplyResources(this.nudCleanupKeepFileCount, "nudCleanupKeepFileCount");
+ this.nudCleanupKeepFileCount.Minimum = new decimal(new int[] {
+ 1,
+ 0,
+ 0,
+ 0});
+ this.nudCleanupKeepFileCount.Name = "nudCleanupKeepFileCount";
+ this.nudCleanupKeepFileCount.Value = new decimal(new int[] {
+ 1,
+ 0,
+ 0,
+ 0});
+ this.nudCleanupKeepFileCount.ValueChanged += new System.EventHandler(this.nudCleanupKeepFileCount_ValueChanged);
+ //
+ // cbAutomaticallyCleanupLogFiles
+ //
+ resources.ApplyResources(this.cbAutomaticallyCleanupLogFiles, "cbAutomaticallyCleanupLogFiles");
+ this.cbAutomaticallyCleanupLogFiles.Name = "cbAutomaticallyCleanupLogFiles";
+ this.cbAutomaticallyCleanupLogFiles.UseVisualStyleBackColor = true;
+ this.cbAutomaticallyCleanupLogFiles.CheckedChanged += new System.EventHandler(this.cbAutomaticallyCleanupLogFiles_CheckedChanged);
+ //
+ // btnLanguages
+ //
+ resources.ApplyResources(this.btnLanguages, "btnLanguages");
+ this.btnLanguages.Menu = this.cmsLanguages;
+ this.btnLanguages.Name = "btnLanguages";
+ this.btnLanguages.UseVisualStyleBackColor = true;
+ //
+ // eiTheme
+ //
+ this.eiTheme.DefaultFileName = null;
+ resources.ApplyResources(this.eiTheme, "eiTheme");
+ this.eiTheme.Name = "eiTheme";
+ this.eiTheme.ObjectType = null;
+ this.eiTheme.SerializationBinder = null;
+ this.eiTheme.ExportRequested += new ShareX.HelpersLib.ExportImportControl.ExportEventHandler(this.EiTheme_ExportRequested);
+ this.eiTheme.ImportRequested += new ShareX.HelpersLib.ExportImportControl.ImportEventHandler(this.EiTheme_ImportRequested);
+ //
+ // lvClipboardFormats
+ //
+ resources.ApplyResources(this.lvClipboardFormats, "lvClipboardFormats");
+ this.lvClipboardFormats.AutoFillColumn = true;
+ this.lvClipboardFormats.Columns.AddRange(new System.Windows.Forms.ColumnHeader[] {
+ this.chDescription,
+ this.chFormat});
+ this.lvClipboardFormats.FullRowSelect = true;
+ this.lvClipboardFormats.HideSelection = false;
+ this.lvClipboardFormats.Name = "lvClipboardFormats";
+ this.lvClipboardFormats.UseCompatibleStateImageBehavior = false;
+ this.lvClipboardFormats.View = System.Windows.Forms.View.Details;
+ this.lvClipboardFormats.MouseDoubleClick += new System.Windows.Forms.MouseEventHandler(this.lvClipboardFormats_MouseDoubleClick);
+ //
+ // chDescription
+ //
+ resources.ApplyResources(this.chDescription, "chDescription");
+ //
+ // chFormat
+ //
+ resources.ApplyResources(this.chFormat, "chFormat");
+ //
+ // lvSecondaryFileUploaders
+ //
+ this.lvSecondaryFileUploaders.AllowDrop = true;
+ this.lvSecondaryFileUploaders.AllowItemDrag = true;
+ this.lvSecondaryFileUploaders.AutoFillColumn = true;
+ this.lvSecondaryFileUploaders.BorderStyle = System.Windows.Forms.BorderStyle.None;
+ this.lvSecondaryFileUploaders.Columns.AddRange(new System.Windows.Forms.ColumnHeader[] {
+ this.chSecondaryFileUploaders});
+ resources.ApplyResources(this.lvSecondaryFileUploaders, "lvSecondaryFileUploaders");
+ this.lvSecondaryFileUploaders.FullRowSelect = true;
+ this.lvSecondaryFileUploaders.HeaderStyle = System.Windows.Forms.ColumnHeaderStyle.None;
+ this.lvSecondaryFileUploaders.HideSelection = false;
+ this.lvSecondaryFileUploaders.MultiSelect = false;
+ this.lvSecondaryFileUploaders.Name = "lvSecondaryFileUploaders";
+ this.lvSecondaryFileUploaders.UseCompatibleStateImageBehavior = false;
+ this.lvSecondaryFileUploaders.View = System.Windows.Forms.View.Details;
+ this.lvSecondaryFileUploaders.MouseUp += new System.Windows.Forms.MouseEventHandler(this.lvSecondaryUploaders_MouseUp);
+ //
+ // lvSecondaryImageUploaders
+ //
+ this.lvSecondaryImageUploaders.AllowDrop = true;
+ this.lvSecondaryImageUploaders.AllowItemDrag = true;
+ this.lvSecondaryImageUploaders.AutoFillColumn = true;
+ this.lvSecondaryImageUploaders.BorderStyle = System.Windows.Forms.BorderStyle.None;
+ this.lvSecondaryImageUploaders.Columns.AddRange(new System.Windows.Forms.ColumnHeader[] {
+ this.chSecondaryImageUploaders});
+ resources.ApplyResources(this.lvSecondaryImageUploaders, "lvSecondaryImageUploaders");
+ this.lvSecondaryImageUploaders.FullRowSelect = true;
+ this.lvSecondaryImageUploaders.HeaderStyle = System.Windows.Forms.ColumnHeaderStyle.None;
+ this.lvSecondaryImageUploaders.HideSelection = false;
+ this.lvSecondaryImageUploaders.MultiSelect = false;
+ this.lvSecondaryImageUploaders.Name = "lvSecondaryImageUploaders";
+ this.lvSecondaryImageUploaders.UseCompatibleStateImageBehavior = false;
+ this.lvSecondaryImageUploaders.View = System.Windows.Forms.View.Details;
+ this.lvSecondaryImageUploaders.MouseUp += new System.Windows.Forms.MouseEventHandler(this.lvSecondaryUploaders_MouseUp);
+ //
+ // lvSecondaryTextUploaders
+ //
+ this.lvSecondaryTextUploaders.AllowDrop = true;
+ this.lvSecondaryTextUploaders.AllowItemDrag = true;
+ this.lvSecondaryTextUploaders.AutoFillColumn = true;
+ this.lvSecondaryTextUploaders.BorderStyle = System.Windows.Forms.BorderStyle.None;
+ this.lvSecondaryTextUploaders.Columns.AddRange(new System.Windows.Forms.ColumnHeader[] {
+ this.chSecondaryTextUploaders});
+ resources.ApplyResources(this.lvSecondaryTextUploaders, "lvSecondaryTextUploaders");
+ this.lvSecondaryTextUploaders.FullRowSelect = true;
+ this.lvSecondaryTextUploaders.HeaderStyle = System.Windows.Forms.ColumnHeaderStyle.None;
+ this.lvSecondaryTextUploaders.HideSelection = false;
+ this.lvSecondaryTextUploaders.MultiSelect = false;
+ this.lvSecondaryTextUploaders.Name = "lvSecondaryTextUploaders";
+ this.lvSecondaryTextUploaders.UseCompatibleStateImageBehavior = false;
+ this.lvSecondaryTextUploaders.View = System.Windows.Forms.View.Details;
+ this.lvSecondaryTextUploaders.MouseUp += new System.Windows.Forms.MouseEventHandler(this.lvSecondaryUploaders_MouseUp);
+ //
// tttvMain
//
resources.ApplyResources(this.tttvMain, "tttvMain");
@@ -1154,6 +1198,7 @@ private void InitializeComponent()
this.tttvMain.LeftPanelBackColor = System.Drawing.SystemColors.Window;
this.tttvMain.MainTabControl = null;
this.tttvMain.Name = "tttvMain";
+ this.tttvMain.SeparatorColor = System.Drawing.SystemColors.ControlDark;
this.tttvMain.TreeViewFont = new System.Drawing.Font("Microsoft Sans Serif", 9.75F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(162)));
this.tttvMain.TreeViewSize = 175;
this.tttvMain.TabChanged += new ShareX.HelpersLib.TabToTreeView.TabChangedEventHandler(this.tttvMain_TabChanged);
@@ -1213,6 +1258,7 @@ private void InitializeComponent()
this.tpProxy.PerformLayout();
((System.ComponentModel.ISupportInitialize)(this.nudProxyPort)).EndInit();
this.tpAdvanced.ResumeLayout(false);
+ ((System.ComponentModel.ISupportInitialize)(this.nudCleanupKeepFileCount)).EndInit();
this.ResumeLayout(false);
}
@@ -1345,5 +1391,9 @@ private void InitializeComponent()
private System.Windows.Forms.CheckBox cbExportHistory;
private System.Windows.Forms.CheckBox cbExportSettings;
private System.Windows.Forms.PictureBox pbExportImportNote;
+ private System.Windows.Forms.CheckBox cbAutomaticallyCleanupBackupFiles;
+ private System.Windows.Forms.NumericUpDown nudCleanupKeepFileCount;
+ private System.Windows.Forms.Label lblCleanupKeepFileCount;
+ private System.Windows.Forms.CheckBox cbAutomaticallyCleanupLogFiles;
}
}
\ No newline at end of file
diff --git a/ShareX/Forms/ApplicationSettingsForm.cs b/ShareX/Forms/ApplicationSettingsForm.cs
index 4ff6246ac..3ea59f46d 100644
--- a/ShareX/Forms/ApplicationSettingsForm.cs
+++ b/ShareX/Forms/ApplicationSettingsForm.cs
@@ -156,6 +156,11 @@ private void UpdateControls()
txtCustomScreenshotsPath.Text = Program.Settings.CustomScreenshotsPath;
txtSaveImageSubFolderPattern.Text = Program.Settings.SaveImageSubFolderPattern;
+ // Settings
+ cbAutomaticallyCleanupBackupFiles.Checked = Program.Settings.AutoCleanupBackupFiles;
+ cbAutomaticallyCleanupLogFiles.Checked = Program.Settings.AutoCleanupLogFiles;
+ nudCleanupKeepFileCount.SetValue(Program.Settings.CleanupKeepFileCount);
+
// Proxy
cbProxyMethod.SelectedIndex = (int)Program.Settings.ProxySettings.ProxyMethod;
txtProxyUsername.Text = Program.Settings.ProxySettings.Username;
@@ -684,7 +689,7 @@ private void btnOpenScreenshotsFolder_Click(object sender, EventArgs e)
#endregion Paths
- #region Export / Import
+ #region Settings
private void cbExportSettings_CheckedChanged(object sender, EventArgs e)
{
@@ -798,7 +803,22 @@ private void btnResetSettings_Click(object sender, EventArgs e)
}
}
- #endregion Export / Import
+ private void cbAutomaticallyCleanupBackupFiles_CheckedChanged(object sender, EventArgs e)
+ {
+ Program.Settings.AutoCleanupBackupFiles = cbAutomaticallyCleanupBackupFiles.Checked;
+ }
+
+ private void cbAutomaticallyCleanupLogFiles_CheckedChanged(object sender, EventArgs e)
+ {
+ Program.Settings.AutoCleanupLogFiles = cbAutomaticallyCleanupLogFiles.Checked;
+ }
+
+ private void nudCleanupKeepFileCount_ValueChanged(object sender, EventArgs e)
+ {
+ Program.Settings.CleanupKeepFileCount = (int)nudCleanupKeepFileCount.Value;
+ }
+
+ #endregion Settings
#region Proxy
diff --git a/ShareX/Forms/ApplicationSettingsForm.resx b/ShareX/Forms/ApplicationSettingsForm.resx
index 6e85e073e..3c085cda5 100644
--- a/ShareX/Forms/ApplicationSettingsForm.resx
+++ b/ShareX/Forms/ApplicationSettingsForm.resx
@@ -487,7 +487,7 @@
btnLanguages
- ShareX.HelpersLib.MenuButton, ShareX.HelpersLib, Version=13.3.1.0, Culture=neutral, PublicKeyToken=null
+ ShareX.HelpersLib.MenuButton, ShareX.HelpersLib, Version=13.4.0.0, Culture=neutral, PublicKeyToken=null
tpGeneral
@@ -672,6 +672,9 @@
0
+
+ NoControl
+
400, 40
@@ -696,27 +699,6 @@
0
-
- 208, 40
-
-
- 185, 24
-
-
- 4
-
-
- eiTheme
-
-
- ShareX.HelpersLib.ExportImportControl, ShareX.HelpersLib, Version=13.3.1.0, Culture=neutral, PublicKeyToken=null
-
-
- tpTheme
-
-
- 1
-
NoControl
@@ -742,7 +724,7 @@
tpTheme
- 2
+ 1
NoControl
@@ -769,7 +751,7 @@
tpTheme
- 3
+ 2
208, 14
@@ -790,7 +772,7 @@
tpTheme
- 4
+ 3
False
@@ -814,7 +796,7 @@
tpTheme
- 5
+ 4
True
@@ -844,6 +826,27 @@
tpTheme
+ 5
+
+
+ 208, 40
+
+
+ 185, 24
+
+
+ 4
+
+
+ eiTheme
+
+
+ ShareX.HelpersLib.ExportImportControl, ShareX.HelpersLib, Version=13.4.0.0, Culture=neutral, PublicKeyToken=null
+
+
+ tpTheme
+
+
6
@@ -853,7 +856,7 @@
3, 3, 3, 3
- 550, 370
+ 556, 376
9
@@ -1237,7 +1240,7 @@
3, 3, 3, 3
- 550, 370
+ 556, 376
6
@@ -1612,7 +1615,7 @@
3, 3, 3, 3
- 550, 370
+ 556, 376
1
@@ -1632,6 +1635,123 @@
3
+
+ True
+
+
+ NoControl
+
+
+ 16, 240
+
+
+ 184, 17
+
+
+ 11
+
+
+ Automatically cleanup old log files
+
+
+ cbAutomaticallyCleanupLogFiles
+
+
+ System.Windows.Forms.CheckBox, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
+
+
+ tpSettings
+
+
+ 0
+
+
+ 16, 280
+
+
+ 72, 20
+
+
+ 10
+
+
+ Center
+
+
+ nudCleanupKeepFileCount
+
+
+ System.Windows.Forms.NumericUpDown, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
+
+
+ tpSettings
+
+
+ 1
+
+
+ True
+
+
+ NoControl
+
+
+ 13, 264
+
+
+ 119, 13
+
+
+ 9
+
+
+ Number of files to keep:
+
+
+ lblCleanupKeepFileCount
+
+
+ System.Windows.Forms.Label, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
+
+
+ tpSettings
+
+
+ 2
+
+
+ True
+
+
+ NoControl
+
+
+ 16, 216
+
+
+ 206, 17
+
+
+ 8
+
+
+ Automatically cleanup old backup files
+
+
+ cbAutomaticallyCleanupBackupFiles
+
+
+ System.Windows.Forms.CheckBox, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
+
+
+ tpSettings
+
+
+ 3
+
+
+ NoControl
+
16, 16
@@ -1654,11 +1774,14 @@
tpSettings
- 0
+ 4
True
+
+ NoControl
+
16, 88
@@ -1681,11 +1804,14 @@
tpSettings
- 1
+ 5
True
+
+ NoControl
+
16, 64
@@ -1708,7 +1834,10 @@
tpSettings
- 2
+ 6
+
+
+ NoControl
56, 16
@@ -1735,7 +1864,7 @@
tpSettings
- 3
+ 7
NoControl
@@ -1762,7 +1891,7 @@
tpSettings
- 4
+ 8
NoControl
@@ -1789,7 +1918,7 @@
tpSettings
- 5
+ 9
NoControl
@@ -1816,7 +1945,7 @@
tpSettings
- 6
+ 10
NoControl
@@ -1843,7 +1972,7 @@
tpSettings
- 7
+ 11
4, 22
@@ -1852,7 +1981,7 @@
3, 3, 3, 3
- 550, 370
+ 556, 376
7
@@ -2014,7 +2143,7 @@
3, 3, 3, 3
- 536, 338
+ 542, 344
0
@@ -2143,7 +2272,7 @@
lvClipboardFormats
- ShareX.HelpersLib.MyListView, ShareX.HelpersLib, Version=13.3.1.0, Culture=neutral, PublicKeyToken=null
+ ShareX.HelpersLib.MyListView, ShareX.HelpersLib, Version=13.4.0.0, Culture=neutral, PublicKeyToken=null
gbClipboardFormats
@@ -2182,7 +2311,7 @@
3, 3, 3, 3
- 536, 338
+ 542, 344
1
@@ -2218,7 +2347,7 @@
lvSecondaryFileUploaders
- ShareX.HelpersLib.MyListView, ShareX.HelpersLib, Version=13.3.1.0, Culture=neutral, PublicKeyToken=null
+ ShareX.HelpersLib.MyListView, ShareX.HelpersLib, Version=13.4.0.0, Culture=neutral, PublicKeyToken=null
gbSecondaryFileUploaders
@@ -2269,7 +2398,7 @@
lvSecondaryImageUploaders
- ShareX.HelpersLib.MyListView, ShareX.HelpersLib, Version=13.3.1.0, Culture=neutral, PublicKeyToken=null
+ ShareX.HelpersLib.MyListView, ShareX.HelpersLib, Version=13.4.0.0, Culture=neutral, PublicKeyToken=null
gbSecondaryImageUploaders
@@ -2320,7 +2449,7 @@
lvSecondaryTextUploaders
- ShareX.HelpersLib.MyListView, ShareX.HelpersLib, Version=13.3.1.0, Culture=neutral, PublicKeyToken=null
+ ShareX.HelpersLib.MyListView, ShareX.HelpersLib, Version=13.4.0.0, Culture=neutral, PublicKeyToken=null
gbSecondaryTextUploaders
@@ -2446,7 +2575,7 @@
3, 3, 3, 3
- 536, 338
+ 542, 344
2
@@ -2473,7 +2602,7 @@
3, 3
- 544, 364
+ 550, 370
0
@@ -2497,7 +2626,7 @@
3, 3, 3, 3
- 550, 370
+ 556, 376
3
@@ -2806,7 +2935,7 @@
3, 3, 3, 3
- 550, 370
+ 556, 376
8
@@ -2920,7 +3049,7 @@
3, 3, 3, 3
- 550, 370
+ 556, 376
4
@@ -3205,7 +3334,7 @@
5, 5, 5, 5
- 550, 370
+ 556, 376
2
@@ -3232,7 +3361,7 @@
3, 3
- 544, 364
+ 550, 370
0
@@ -3256,7 +3385,7 @@
3, 3, 3, 3
- 550, 370
+ 556, 376
5
@@ -3319,7 +3448,7 @@
tttvMain
- ShareX.HelpersLib.TabToTreeView, ShareX.HelpersLib, Version=13.3.1.0, Culture=neutral, PublicKeyToken=null
+ ShareX.HelpersLib.TabToTreeView, ShareX.HelpersLib, Version=13.4.0.0, Culture=neutral, PublicKeyToken=null
$this
@@ -3336,6 +3465,9 @@
737, 402
+
+ NoControl
+
640, 440
diff --git a/ShareX/Program.cs b/ShareX/Program.cs
index fcde3e58a..1a052cbb5 100644
--- a/ShareX/Program.cs
+++ b/ShareX/Program.cs
@@ -32,7 +32,6 @@ You should have received a copy of the GNU General Public License
using System.IO;
using System.Text;
using System.Threading;
-using System.Threading.Tasks;
using System.Windows.Forms;
#if WindowsStore
@@ -328,13 +327,13 @@ private static void Run()
RegisterExtensions();
CheckPuushMode();
DebugWriteFlags();
- CleanTempFiles();
SettingManager.LoadInitialSettings();
Uploader.UpdateServicePointManager();
UpdateManager = new GitHubUpdateManager("ShareX", "ShareX", Dev, Portable);
LanguageHelper.ChangeLanguage(Settings.Language);
+ CleanupManager.CleanupAsync();
Helpers.TryFixHandCursor();
DebugHelper.WriteLine("MainForm init started.");
@@ -665,32 +664,5 @@ private static void DebugWriteFlags()
DebugHelper.WriteLine("Flags: " + output);
}
}
-
- private static void CleanTempFiles()
- {
- Task.Run(() =>
- {
- try
- {
- string tempFolder = Path.GetTempPath();
-
- if (!string.IsNullOrEmpty(tempFolder))
- {
- string folderPath = Path.Combine(tempFolder, "ShareX");
-
- if (Directory.Exists(folderPath))
- {
- Directory.Delete(folderPath, true);
-
- DebugHelper.WriteLine($"Temp files cleaned: {folderPath}");
- }
- }
- }
- catch (Exception e)
- {
- DebugHelper.WriteException(e);
- }
- });
- }
}
}
\ No newline at end of file
diff --git a/ShareX/ShareX.csproj b/ShareX/ShareX.csproj
index 0bc69de6d..c4eb181d1 100644
--- a/ShareX/ShareX.csproj
+++ b/ShareX/ShareX.csproj
@@ -150,6 +150,7 @@
+
UserControl