diff --git a/Greenshot/Forms/MainForm.cs b/Greenshot/Forms/MainForm.cs index 13d90cfd4..475c81b9c 100644 --- a/Greenshot/Forms/MainForm.cs +++ b/Greenshot/Forms/MainForm.cs @@ -1179,6 +1179,10 @@ namespace Greenshot { /// /// private void BackgroundWorkerTimerTick(object sender, EventArgs e) { + if (conf.MinimizeWorkingSetSize) { + LOG.Info("Calling EmptyWorkingSet"); + PsAPI.EmptyWorkingSet(Process.GetCurrentProcess().Handle); + } if (UpdateHelper.IsUpdateCheckNeeded()) { LOG.Debug("BackgroundWorkerTimerTick checking for update"); // Start update check in the background diff --git a/Greenshot/Forms/SettingsForm.Designer.cs b/Greenshot/Forms/SettingsForm.Designer.cs index 5f6f151c3..fb7b5dad4 100644 --- a/Greenshot/Forms/SettingsForm.Designer.cs +++ b/Greenshot/Forms/SettingsForm.Designer.cs @@ -73,7 +73,7 @@ namespace Greenshot { this.groupbox_destination = new GreenshotPlugin.Controls.GreenshotGroupBox(); this.checkbox_picker = new GreenshotPlugin.Controls.GreenshotCheckBox(); this.listview_destinations = new System.Windows.Forms.ListView(); - this.destination = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader())); + this.destination = new System.Windows.Forms.ColumnHeader(); this.tabcontrol = new System.Windows.Forms.TabControl(); this.tab_general = new GreenshotPlugin.Controls.GreenshotTabPage(); this.groupbox_network = new GreenshotPlugin.Controls.GreenshotGroupBox(); @@ -124,6 +124,7 @@ namespace Greenshot { this.button_pluginconfigure = new GreenshotPlugin.Controls.GreenshotButton(); this.tab_expert = new GreenshotPlugin.Controls.GreenshotTabPage(); this.groupbox_expert = new GreenshotPlugin.Controls.GreenshotGroupBox(); + this.checkbox_checkunstableupdates = new GreenshotPlugin.Controls.GreenshotCheckBox(); this.checkbox_suppresssavedialogatclose = new GreenshotPlugin.Controls.GreenshotCheckBox(); this.label_counter = new GreenshotPlugin.Controls.GreenshotLabel(); this.textbox_counter = new GreenshotPlugin.Controls.GreenshotTextBox(); @@ -135,8 +136,8 @@ namespace Greenshot { this.label_clipboardformats = new GreenshotPlugin.Controls.GreenshotLabel(); this.checkbox_enableexpert = new GreenshotPlugin.Controls.GreenshotCheckBox(); this.listview_clipboardformats = new System.Windows.Forms.ListView(); - this.columnHeader1 = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader())); - this.checkbox_checkunstableupdates = new GreenshotPlugin.Controls.GreenshotCheckBox(); + this.columnHeader1 = new System.Windows.Forms.ColumnHeader(); + this.checkbox_minimizememoryfootprint = new GreenshotPlugin.Controls.GreenshotCheckBox(); this.groupbox_preferredfilesettings.SuspendLayout(); this.groupbox_applicationsettings.SuspendLayout(); this.groupbox_qualitysettings.SuspendLayout(); @@ -424,7 +425,7 @@ namespace Greenshot { this.listview_destinations.AutoArrange = false; this.listview_destinations.CheckBoxes = true; this.listview_destinations.Columns.AddRange(new System.Windows.Forms.ColumnHeader[] { - this.destination}); + this.destination}); this.listview_destinations.HeaderStyle = System.Windows.Forms.ColumnHeaderStyle.None; this.listview_destinations.LabelWrap = false; this.listview_destinations.Location = new System.Drawing.Point(6, 38); @@ -786,16 +787,16 @@ namespace Greenshot { // numericUpDownWaitTime // this.numericUpDownWaitTime.Increment = new decimal(new int[] { - 100, - 0, - 0, - 0}); + 100, + 0, + 0, + 0}); this.numericUpDownWaitTime.Location = new System.Drawing.Point(11, 69); this.numericUpDownWaitTime.Maximum = new decimal(new int[] { - 10000, - 0, - 0, - 0}); + 10000, + 0, + 0, + 0}); this.numericUpDownWaitTime.Name = "numericUpDownWaitTime"; this.numericUpDownWaitTime.Size = new System.Drawing.Size(57, 20); this.numericUpDownWaitTime.TabIndex = 24; @@ -984,9 +985,9 @@ namespace Greenshot { // // groupbox_plugins // - this.groupbox_plugins.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) - | System.Windows.Forms.AnchorStyles.Left) - | System.Windows.Forms.AnchorStyles.Right))); + this.groupbox_plugins.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) + | System.Windows.Forms.AnchorStyles.Left) + | System.Windows.Forms.AnchorStyles.Right))); this.groupbox_plugins.BackgroundImageLayout = System.Windows.Forms.ImageLayout.None; this.groupbox_plugins.Controls.Add(this.listview_plugins); this.groupbox_plugins.Controls.Add(this.button_pluginconfigure); @@ -1038,6 +1039,7 @@ namespace Greenshot { // // groupbox_expert // + this.groupbox_expert.Controls.Add(this.checkbox_minimizememoryfootprint); this.groupbox_expert.Controls.Add(this.checkbox_checkunstableupdates); this.groupbox_expert.Controls.Add(this.checkbox_suppresssavedialogatclose); this.groupbox_expert.Controls.Add(this.label_counter); @@ -1058,10 +1060,20 @@ namespace Greenshot { this.groupbox_expert.TabStop = false; this.groupbox_expert.Text = "Expert"; // + // checkbox_checkunstableupdates + // + this.checkbox_checkunstableupdates.LanguageKey = "expertsettings_checkunstableupdates"; + this.checkbox_checkunstableupdates.Location = new System.Drawing.Point(10, 191); + this.checkbox_checkunstableupdates.Name = "checkbox_checkunstableupdates"; + this.checkbox_checkunstableupdates.PropertyName = "CheckUnstable"; + this.checkbox_checkunstableupdates.Size = new System.Drawing.Size(394, 19); + this.checkbox_checkunstableupdates.TabIndex = 29; + this.checkbox_checkunstableupdates.UseVisualStyleBackColor = true; + // // checkbox_suppresssavedialogatclose // this.checkbox_suppresssavedialogatclose.LanguageKey = "expertsettings_suppresssavedialogatclose"; - this.checkbox_suppresssavedialogatclose.Location = new System.Drawing.Point(10, 182); + this.checkbox_suppresssavedialogatclose.Location = new System.Drawing.Point(10, 168); this.checkbox_suppresssavedialogatclose.Name = "checkbox_suppresssavedialogatclose"; this.checkbox_suppresssavedialogatclose.PropertyName = "SuppressSaveDialogAtClose"; this.checkbox_suppresssavedialogatclose.SectionName = "Editor"; @@ -1108,7 +1120,7 @@ namespace Greenshot { // checkbox_thumbnailpreview // this.checkbox_thumbnailpreview.LanguageKey = "expertsettings_thumbnailpreview"; - this.checkbox_thumbnailpreview.Location = new System.Drawing.Point(10, 163); + this.checkbox_thumbnailpreview.Location = new System.Drawing.Point(10, 149); this.checkbox_thumbnailpreview.Name = "checkbox_thumbnailpreview"; this.checkbox_thumbnailpreview.PropertyName = "ThumnailPreview"; this.checkbox_thumbnailpreview.Size = new System.Drawing.Size(394, 24); @@ -1119,7 +1131,7 @@ namespace Greenshot { // checkbox_optimizeforrdp // this.checkbox_optimizeforrdp.LanguageKey = "expertsettings_optimizeforrdp"; - this.checkbox_optimizeforrdp.Location = new System.Drawing.Point(10, 144); + this.checkbox_optimizeforrdp.Location = new System.Drawing.Point(10, 130); this.checkbox_optimizeforrdp.Name = "checkbox_optimizeforrdp"; this.checkbox_optimizeforrdp.PropertyName = "OptimizeForRDP"; this.checkbox_optimizeforrdp.Size = new System.Drawing.Size(394, 24); @@ -1130,7 +1142,7 @@ namespace Greenshot { // checkbox_autoreducecolors // this.checkbox_autoreducecolors.LanguageKey = "expertsettings_autoreducecolors"; - this.checkbox_autoreducecolors.Location = new System.Drawing.Point(10, 125); + this.checkbox_autoreducecolors.Location = new System.Drawing.Point(10, 111); this.checkbox_autoreducecolors.Name = "checkbox_autoreducecolors"; this.checkbox_autoreducecolors.PropertyName = "OutputFileAutoReduceColors"; this.checkbox_autoreducecolors.Size = new System.Drawing.Size(394, 24); @@ -1142,7 +1154,7 @@ namespace Greenshot { // this.label_clipboardformats.AutoSize = true; this.label_clipboardformats.LanguageKey = "expertsettings_clipboardformats"; - this.label_clipboardformats.Location = new System.Drawing.Point(7, 45); + this.label_clipboardformats.Location = new System.Drawing.Point(7, 39); this.label_clipboardformats.Name = "label_clipboardformats"; this.label_clipboardformats.Size = new System.Drawing.Size(88, 13); this.label_clipboardformats.TabIndex = 20; @@ -1165,13 +1177,13 @@ namespace Greenshot { this.listview_clipboardformats.AutoArrange = false; this.listview_clipboardformats.CheckBoxes = true; this.listview_clipboardformats.Columns.AddRange(new System.Windows.Forms.ColumnHeader[] { - this.columnHeader1}); + this.columnHeader1}); this.listview_clipboardformats.HeaderStyle = System.Windows.Forms.ColumnHeaderStyle.None; this.listview_clipboardformats.LabelWrap = false; - this.listview_clipboardformats.Location = new System.Drawing.Point(109, 44); + this.listview_clipboardformats.Location = new System.Drawing.Point(109, 38); this.listview_clipboardformats.Name = "listview_clipboardformats"; this.listview_clipboardformats.ShowGroups = false; - this.listview_clipboardformats.Size = new System.Drawing.Size(291, 80); + this.listview_clipboardformats.Size = new System.Drawing.Size(291, 72); this.listview_clipboardformats.Sorting = System.Windows.Forms.SortOrder.Ascending; this.listview_clipboardformats.TabIndex = 0; this.listview_clipboardformats.UseCompatibleStateImageBehavior = false; @@ -1182,15 +1194,15 @@ namespace Greenshot { this.columnHeader1.Text = "Destination"; this.columnHeader1.Width = 280; // - // checkbox_checkunstableupdates + // checkbox_minimizememoryfootprint // - this.checkbox_checkunstableupdates.LanguageKey = "expertsettings_checkunstableupdates"; - this.checkbox_checkunstableupdates.Location = new System.Drawing.Point(10, 201); - this.checkbox_checkunstableupdates.Name = "checkbox_checkunstableupdates"; - this.checkbox_checkunstableupdates.PropertyName = "CheckUnstable"; - this.checkbox_checkunstableupdates.Size = new System.Drawing.Size(394, 24); - this.checkbox_checkunstableupdates.TabIndex = 29; - this.checkbox_checkunstableupdates.UseVisualStyleBackColor = true; + this.checkbox_minimizememoryfootprint.LanguageKey = "expertsettings_minimizememoryfootprint"; + this.checkbox_minimizememoryfootprint.Location = new System.Drawing.Point(10, 211); + this.checkbox_minimizememoryfootprint.Name = "checkbox_minimizememoryfootprint"; + this.checkbox_minimizememoryfootprint.PropertyName = "MinimizeWorkingSetSize"; + this.checkbox_minimizememoryfootprint.Size = new System.Drawing.Size(394, 19); + this.checkbox_minimizememoryfootprint.TabIndex = 30; + this.checkbox_minimizememoryfootprint.UseVisualStyleBackColor = true; // // SettingsForm // @@ -1205,7 +1217,6 @@ namespace Greenshot { this.MaximizeBox = false; this.MinimizeBox = false; this.Name = "SettingsForm"; - this.Text = "Settings"; this.FormClosing += new System.Windows.Forms.FormClosingEventHandler(this.SettingsFormFormClosing); this.Shown += new System.EventHandler(this.SettingsFormShown); this.groupbox_preferredfilesettings.ResumeLayout(false); @@ -1239,8 +1250,8 @@ namespace Greenshot { this.groupbox_expert.ResumeLayout(false); this.groupbox_expert.PerformLayout(); this.ResumeLayout(false); - } + private GreenshotPlugin.Controls.GreenshotCheckBox checkbox_minimizememoryfootprint; private System.Windows.Forms.ColumnHeader destination; private GreenshotPlugin.Controls.GreenshotCheckBox checkbox_picker; private System.Windows.Forms.ListView listview_destinations; diff --git a/Greenshot/Forms/SettingsForm.cs b/Greenshot/Forms/SettingsForm.cs index ef0ba2193..bd16a083e 100644 --- a/Greenshot/Forms/SettingsForm.cs +++ b/Greenshot/Forms/SettingsForm.cs @@ -488,6 +488,7 @@ namespace Greenshot { textbox_counter.Enabled = state; checkbox_suppresssavedialogatclose.Enabled = state; checkbox_checkunstableupdates.Enabled = state; + checkbox_minimizememoryfootprint.Enabled = state; } /// diff --git a/Greenshot/Languages/language-en-US.xml b/Greenshot/Languages/language-en-US.xml index cd74331ec..4f5702a80 100644 --- a/Greenshot/Languages/language-en-US.xml +++ b/Greenshot/Languages/language-en-US.xml @@ -673,6 +673,9 @@ time, e.g. 11_58_32 (plus extension defined in the settings) Suppress the save dialog when closing the editor + + Minimize memory footprint, but with a performance penalty (not adviced). + As displayed diff --git a/GreenshotPlugin/Core/CoreConfiguration.cs b/GreenshotPlugin/Core/CoreConfiguration.cs index 4b40af827..d8d019d28 100644 --- a/GreenshotPlugin/Core/CoreConfiguration.cs +++ b/GreenshotPlugin/Core/CoreConfiguration.cs @@ -171,6 +171,8 @@ namespace GreenshotPlugin.Core { [IniProperty("OptimizeForRDP", Description="Make some optimizations for usage with remote desktop", DefaultValue="False")] public bool OptimizeForRDP; + [IniProperty("MinimizeWorkingSetSize", Description="Optimize memory footprint, but with a performance penalty!", DefaultValue="False")] + public bool MinimizeWorkingSetSize; // change to false for releases diff --git a/GreenshotPlugin/GreenshotPlugin.csproj b/GreenshotPlugin/GreenshotPlugin.csproj index e6758989a..96aef4a30 100644 --- a/GreenshotPlugin/GreenshotPlugin.csproj +++ b/GreenshotPlugin/GreenshotPlugin.csproj @@ -265,6 +265,7 @@ + diff --git a/GreenshotPlugin/UnmanagedHelpers/Kernel32.cs b/GreenshotPlugin/UnmanagedHelpers/Kernel32.cs index 83e05503e..856731233 100644 --- a/GreenshotPlugin/UnmanagedHelpers/Kernel32.cs +++ b/GreenshotPlugin/UnmanagedHelpers/Kernel32.cs @@ -66,12 +66,6 @@ namespace GreenshotPlugin.UnmanagedHelpers { [DllImport("kernel32", SetLastError = true)] public static extern bool CloseHandle(IntPtr hObject); - // TODO: Move to PSAPI.cs ?? - [DllImport("psapi", SetLastError = true)] - public static extern uint GetModuleFileNameEx(IntPtr hProcess, IntPtr hModule, StringBuilder lpFilename, uint nSize); - [DllImport("psapi", SetLastError = true)] - public static extern uint GetProcessImageFileName(IntPtr hProcess, StringBuilder lpImageFileName, uint nSize); - /// /// Method to get the process path /// @@ -85,7 +79,7 @@ namespace GreenshotPlugin.UnmanagedHelpers { IntPtr hprocess = Kernel32.OpenProcess(ProcessAccessFlags.QueryInformation | ProcessAccessFlags.VMRead, false, processid); if (hprocess != IntPtr.Zero) { try { - if (Kernel32.GetModuleFileNameEx(hprocess, IntPtr.Zero, _PathBuffer, (uint)_PathBuffer.Capacity) > 0) { + if (PsAPI.GetModuleFileNameEx(hprocess, IntPtr.Zero, _PathBuffer, (uint)_PathBuffer.Capacity) > 0) { return _PathBuffer.ToString(); } } finally { @@ -103,7 +97,7 @@ namespace GreenshotPlugin.UnmanagedHelpers { } // Try the GetProcessImageFileName method - if (Kernel32.GetProcessImageFileName(hprocess, _PathBuffer, (uint)_PathBuffer.Capacity) > 0) { + if (PsAPI.GetProcessImageFileName(hprocess, _PathBuffer, (uint)_PathBuffer.Capacity) > 0) { string dospath = _PathBuffer.ToString(); foreach (string drive in Environment.GetLogicalDrives()) { if (Kernel32.QueryDosDevice(drive.TrimEnd('\\'), _PathBuffer, (uint)_PathBuffer.Capacity) > 0) { diff --git a/GreenshotPlugin/UnmanagedHelpers/PsAPI.cs b/GreenshotPlugin/UnmanagedHelpers/PsAPI.cs new file mode 100644 index 000000000..4d2327d36 --- /dev/null +++ b/GreenshotPlugin/UnmanagedHelpers/PsAPI.cs @@ -0,0 +1,38 @@ +/* + * Greenshot - a free and open source screenshot tool + * Copyright (C) 2007-2012 Thomas Braun, Jens Klingen, Robin Krom + * + * For more information see: http://getgreenshot.org/ + * The Greenshot project is hosted on Sourceforge: http://sourceforge.net/projects/greenshot/ + * + * 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 1 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, see . + */ +using System; +using System.Runtime.InteropServices; +using System.Text; + +namespace GreenshotPlugin.UnmanagedHelpers { + /// + /// Description of PsAPI. + /// + public class PsAPI { + [DllImport("psapi", SetLastError = true)] + public static extern uint GetModuleFileNameEx(IntPtr hProcess, IntPtr hModule, StringBuilder lpFilename, uint nSize); + [DllImport("psapi", SetLastError = true)] + public static extern uint GetProcessImageFileName(IntPtr hProcess, StringBuilder lpImageFileName, uint nSize); + [DllImport("psapi")] + public static extern int EmptyWorkingSet(IntPtr hwProc); + + } +}