Skip to content

Commit 97359e9

Browse files
committed
* Fixed an issue with process exclusions
* Added code behind settings to exclude processes
1 parent de988d6 commit 97359e9

File tree

3 files changed

+74
-11
lines changed

3 files changed

+74
-11
lines changed

MemPlus/Classes/RAM/RamOptimizer.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,11 @@ internal void EmptyWorkingSetFunction(List<string> processExceptions)
138138
{
139139
_logController.AddLog(new RamLog("Emptying working set"));
140140

141+
if (processExceptions != null && processExceptions.Count > 0)
142+
{
143+
processExceptions = processExceptions.ConvertAll(d => d.ToLower());
144+
}
145+
141146
foreach (Process process in Process.GetProcesses())
142147
{
143148
try

MemPlus/Windows/SettingsWindow.xaml

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -88,21 +88,21 @@
8888
<RowDefinition></RowDefinition>
8989
<RowDefinition Height="Auto"></RowDefinition>
9090
</Grid.RowDefinitions>
91-
<ListView Margin="3" Height="100">
91+
<ListView x:Name="LsvExclusions" Margin="3" Height="100" Width="250">
9292
<ListView.ContextMenu>
9393
<ContextMenu>
94-
<MenuItem Header="Copy">
94+
<MenuItem Header="Copy" Click="CopyExclusionMenuItem_OnClick">
9595
<MenuItem.Icon>
9696
<Image Width="16" Height="16" Source="/MemPlus;component/Resources/Images/log.png" ></Image>
9797
</MenuItem.Icon>
9898
</MenuItem>
9999
<Separator />
100-
<MenuItem Header="Delete">
100+
<MenuItem Header="Delete" Click="DeleteExclusionMenuItem_OnClick">
101101
<MenuItem.Icon>
102102
<Image Width="16" Height="16" Source="/MemPlus;component/Resources/Images/delete.png" ></Image>
103103
</MenuItem.Icon>
104104
</MenuItem>
105-
<MenuItem Header="Clear">
105+
<MenuItem Header="Clear" Click="ClearExclusionsMenuItem_OnClick">
106106
<MenuItem.Icon>
107107
<Image Width="16" Height="16" Source="/MemPlus;component/Resources/Images/exit.png" ></Image>
108108
</MenuItem.Icon>
@@ -113,13 +113,13 @@
113113

114114
<Grid Grid.Row="1">
115115
<Grid.ColumnDefinitions>
116-
<ColumnDefinition></ColumnDefinition>
117-
<ColumnDefinition Width="Auto"></ColumnDefinition>
118116
<ColumnDefinition Width="Auto"></ColumnDefinition>
117+
<ColumnDefinition></ColumnDefinition>
118+
<ColumnDefinition></ColumnDefinition>
119119
</Grid.ColumnDefinitions>
120-
<TextBox Margin="3"></TextBox>
121-
<Button Grid.Column="1" Content="..." Margin="3" MinWidth="35" />
122-
<Button Grid.Column="2" Content="Add" Margin="3" MinWidth="35" />
120+
<TextBox x:Name="TxtExclusion" Margin="3" Width="150"></TextBox>
121+
<Button Grid.Column="1" Content="..." Margin="3" MinWidth="35" Click="BtnFileView_OnClick" />
122+
<Button Grid.Column="2" Content="Add" Margin="3" MinWidth="35" Click="BtnAddExclusion_OnClick" />
123123
</Grid>
124124
</Grid>
125125
</GroupBox>

MemPlus/Windows/SettingsWindow.xaml.cs

Lines changed: 60 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
1-
using System.Windows;
1+
using System.Collections.Generic;
2+
using System.Linq;
3+
using System.Windows;
24
using MemPlus.Classes.GUI;
35
using MemPlus.Classes.LOG;
6+
using Microsoft.Win32;
47

58
namespace MemPlus.Windows
69
{
@@ -62,6 +65,17 @@ private void LoadProperties()
6265

6366
ChbFileSystemCache.IsChecked = Properties.Settings.Default.FileSystemCache;
6467
ChbStandByCache.IsChecked = Properties.Settings.Default.StandByCache;
68+
if (Properties.Settings.Default.ProcessExceptions != null)
69+
{
70+
foreach (string s in Properties.Settings.Default.ProcessExceptions)
71+
{
72+
LsvExclusions.Items.Add(s);
73+
}
74+
}
75+
else
76+
{
77+
LsvExclusions.Items.Clear();
78+
}
6579

6680
//Theme
6781
CboStyle.Text = Properties.Settings.Default.VisualStyle;
@@ -81,11 +95,13 @@ private void SaveProperties()
8195
if (ChbTopmost.IsChecked != null) Properties.Settings.Default.Topmost = ChbTopmost.IsChecked.Value;
8296
if (ChbRamMonitor.IsChecked != null) Properties.Settings.Default.RamMonitor = ChbRamMonitor.IsChecked.Value;
8397
if (ChbDisableInactive.IsChecked != null) Properties.Settings.Default.DisableOnInactive = ChbDisableInactive.IsChecked.Value;
84-
if (ItbRamMonitorTimeout.Value != null) Properties.Settings.Default.RamMonitorInterval = (int) ItbRamMonitorTimeout.Value;
98+
if (ItbRamMonitorTimeout.Value != null) Properties.Settings.Default.RamMonitorInterval = (int)ItbRamMonitorTimeout.Value;
8599

86100
//RAM Optimizer
87101
if (ChbFileSystemCache.IsChecked != null) Properties.Settings.Default.FileSystemCache = ChbFileSystemCache.IsChecked.Value;
88102
if (ChbStandByCache.IsChecked != null) Properties.Settings.Default.StandByCache = ChbStandByCache.IsChecked.Value;
103+
List<string> exclusionList = LsvExclusions.Items.Cast<string>().ToList();
104+
Properties.Settings.Default.ProcessExceptions = exclusionList;
89105

90106
//Theme
91107
Properties.Settings.Default.VisualStyle = CboStyle.Text;
@@ -129,5 +145,47 @@ private void BtnSave_OnClick(object sender, RoutedEventArgs e)
129145
{
130146
SaveProperties();
131147
}
148+
149+
private void BtnFileView_OnClick(object sender, RoutedEventArgs e)
150+
{
151+
OpenFileDialog ofd = new OpenFileDialog { Filter = "All files (*.*)|*.*" };
152+
153+
if (ofd.ShowDialog() == true)
154+
{
155+
TxtExclusion.Text = ofd.FileName;
156+
}
157+
}
158+
159+
private void BtnAddExclusion_OnClick(object sender, RoutedEventArgs e)
160+
{
161+
if (TxtExclusion.Text.Length == 0) return;
162+
163+
if (System.IO.File.Exists(TxtExclusion.Text))
164+
{
165+
LsvExclusions.Items.Add(TxtExclusion.Text);
166+
TxtExclusion.Text = "";
167+
}
168+
else
169+
{
170+
MessageBox.Show("The selected file does not exist!", "MemPlus", MessageBoxButton.OK, MessageBoxImage.Error);
171+
}
172+
}
173+
174+
private void CopyExclusionMenuItem_OnClick(object sender, RoutedEventArgs e)
175+
{
176+
if (LsvExclusions.SelectedItems.Count == 0) return;
177+
Clipboard.SetText(LsvExclusions.SelectedItem.ToString());
178+
}
179+
180+
private void DeleteExclusionMenuItem_OnClick(object sender, RoutedEventArgs e)
181+
{
182+
if (LsvExclusions.SelectedItems.Count == 0) return;
183+
LsvExclusions.Items.Remove(LsvExclusions.SelectedItem);
184+
}
185+
186+
private void ClearExclusionsMenuItem_OnClick(object sender, RoutedEventArgs e)
187+
{
188+
LsvExclusions.Items.Clear();
189+
}
132190
}
133191
}

0 commit comments

Comments
 (0)