Skip to content

Commit a839fd8

Browse files
committed
* Added a setting to enable or disable RAM clearing statistics message
* Added 'Clear memory' button to the notifyicon
1 parent 4e3986d commit a839fd8

File tree

7 files changed

+72
-12
lines changed

7 files changed

+72
-12
lines changed

MemPlus/App.config

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,14 +68,17 @@
6868
<value>False</value>
6969
</setting>
7070
<setting name="WindowDragging" serializeAs="String">
71-
<value>True</value>
71+
<value>False</value>
7272
</setting>
7373
<setting name="AdministrativeWarning" serializeAs="String">
7474
<value>True</value>
7575
</setting>
7676
<setting name="EmptyWorkingSet" serializeAs="String">
7777
<value>True</value>
7878
</setting>
79+
<setting name="RamCleaningMessage" serializeAs="String">
80+
<value>True</value>
81+
</setting>
7982
</MemPlus.Properties.Settings>
8083
</userSettings>
8184
</configuration>

MemPlus/Properties/Settings.Designer.cs

Lines changed: 13 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

MemPlus/Properties/Settings.settings

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,13 +63,16 @@
6363
<Value Profile="(Default)">False</Value>
6464
</Setting>
6565
<Setting Name="WindowDragging" Type="System.Boolean" Scope="User">
66-
<Value Profile="(Default)">True</Value>
66+
<Value Profile="(Default)">False</Value>
6767
</Setting>
6868
<Setting Name="AdministrativeWarning" Type="System.Boolean" Scope="User">
6969
<Value Profile="(Default)">True</Value>
7070
</Setting>
7171
<Setting Name="EmptyWorkingSet" Type="System.Boolean" Scope="User">
7272
<Value Profile="(Default)">True</Value>
7373
</Setting>
74+
<Setting Name="RamCleaningMessage" Type="System.Boolean" Scope="User">
75+
<Value Profile="(Default)">True</Value>
76+
</Setting>
7477
</Settings>
7578
</SettingsFile>

MemPlus/Views/Windows/MainWindow.xaml

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,12 +30,18 @@
3030
<Image Width="16" Height="16" Source="/MemPlus;component/Resources/Images/ram.png" />
3131
</MenuItem.Icon>
3232
</MenuItem>
33+
<MenuItem Header="Clear memory" Click="BtnClearMemory_OnClick">
34+
<MenuItem.Icon>
35+
<Image Width="16" Height="16" Source="/MemPlus;component/Resources/Images/ram_tab.png" />
36+
</MenuItem.Icon>
37+
</MenuItem>
38+
<Separator />
3339
<MenuItem Header="Settings" Click="SettingsMenuItem_OnClick">
3440
<MenuItem.Icon>
3541
<Image Width="16" Height="16" Source="/MemPlus;component/Resources/Images/settings.png" />
3642
</MenuItem.Icon>
3743
</MenuItem>
38-
<Separator></Separator>
44+
<Separator />
3945
<MenuItem Header="Restart" Click="RestartMenuItem_OnClick">
4046
<MenuItem.Icon>
4147
<Image Width="16" Height="16" Source="/MemPlus;component/Resources/Images/paused.png" />
@@ -174,10 +180,6 @@
174180
Margin="5" MaxHeight="350" MaxWidth="350">
175181
<syncfusion:SfCircularGauge.Scales>
176182
<syncfusion:CircularScale>
177-
<syncfusion:CircularScale.Pointers>
178-
<syncfusion:CircularPointer PointerType="NeedlePointer"
179-
NeedlePointerType="Arrow"/>
180-
</syncfusion:CircularScale.Pointers>
181183
<syncfusion:CircularScale.Ranges>
182184
<syncfusion:CircularRange StartValue="0" EndValue="75" Stroke="#666666" />
183185
<syncfusion:CircularRange StartValue="75" EndValue="100" Stroke="Red" />
@@ -201,7 +203,7 @@
201203
<Label Grid.Row="2" Content="Used physical memory:" FontSize="14" Margin="10,5" />
202204
<Label Grid.Row="3" x:Name="LblAvailablePhysicalMemory" Content="" FontSize="14" Foreground="Red" Margin="10,5" />
203205

204-
<syncfusion:SplitButtonAdv Grid.Row="4" SmallIcon="../../Resources/Images/ram_tab.png" Label="Clear memory" x:Name="BtnClearMemory" Click="BtnClearMemory_OnClick" IsMultiLine="False">
206+
<syncfusion:SplitButtonAdv Grid.Row="4" FontSize="14" SmallIcon="../../Resources/Images/ram_tab.png" Label="Clear memory" x:Name="BtnClearMemory" Click="BtnClearMemory_OnClick" IsMultiLine="False">
205207
<syncfusion:DropDownMenuGroup>
206208
<syncfusion:DropDownMenuItem Header="Clear Working sets" Click="ClearWorkingSetsDropDownMenuItem_OnClick"/>
207209
<syncfusion:DropDownMenuItem Header="Clear FileSystem cache" Click="ClearFileSystemCacheDropDownMenuItem_OnClick"/>

MemPlus/Views/Windows/MainWindow.xaml.cs

Lines changed: 38 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,14 @@ public partial class MainWindow
3232
/// The LogController object that can be used to add new logs
3333
/// </summary>
3434
private readonly LogController _logController;
35+
/// <summary>
36+
/// A boolean to indicate whether RAM statistics should be displayed after clearing the memory
37+
/// </summary>
38+
private bool _statisticsMessage;
39+
/// <summary>
40+
/// A boolean to indicate whether RAM cleaning is currently in progress
41+
/// </summary>
42+
private bool _clearingMemory;
3543
#endregion
3644

3745
/// <inheritdoc />
@@ -42,7 +50,9 @@ public MainWindow()
4250
{
4351
_logController = new LogController(600000);
4452
_logController.AddLog(new ApplicationLog("Initializing MainWindow"));
53+
4554
_updateManager = new UpdateManager.Classes.UpdateManager(Assembly.GetExecutingAssembly().GetName().Version, "https://codedead.com/Software/MemPlus/update.xml", "MemPlus", "Information", "Cancel", "Download", "No new version is currently available.");
55+
_clearingMemory = false;
4656

4757
InitializeComponent();
4858
ChangeVisualStyle();
@@ -123,6 +133,7 @@ internal void LoadProperties()
123133

124134
try
125135
{
136+
_statisticsMessage = Properties.Settings.Default.RamCleaningMessage;
126137
MniDisableInactive.IsChecked = Properties.Settings.Default.DisableOnInactive;
127138
MniOnTop.IsChecked = Properties.Settings.Default.Topmost;
128139
MniRamMonitor.IsChecked = Properties.Settings.Default.RamMonitor;
@@ -649,24 +660,42 @@ private void RestartMenuItem_OnClick(object sender, RoutedEventArgs e)
649660
}
650661
}
651662

663+
/// <summary>
664+
/// Method that is called when the working set of processes should be cleared
665+
/// </summary>
666+
/// <param name="sender">The object that called this method</param>
667+
/// <param name="e">The RoutedEventArgs</param>
652668
private void ClearWorkingSetsDropDownMenuItem_OnClick(object sender, RoutedEventArgs e)
653669
{
654670
ClearMemory(1);
655671
}
656672

673+
/// <summary>
674+
/// Method that is called when the FileSystem cache should be cleared
675+
/// </summary>
676+
/// <param name="sender">The object that called this method</param>
677+
/// <param name="e">The RoutedEventArgs</param>
657678
private void ClearFileSystemCacheDropDownMenuItem_OnClick(object sender, RoutedEventArgs e)
658679
{
659680
ClearMemory(2);
660681
}
661682

683+
/// <summary>
684+
/// Clear the memory
685+
/// </summary>
686+
/// <param name="index">The type of memory that needs to be cleared</param>
662687
private async void ClearMemory(int index)
663688
{
689+
if (_clearingMemory) return;
690+
664691
_logController.AddLog(new ApplicationLog("Clearing RAM Memory"));
692+
_clearingMemory = true;
665693

666694
try
667695
{
668696
BtnClearMemory.IsEnabled = false;
669697

698+
// ReSharper disable once SwitchStatementMissingSomeCases
670699
switch (index)
671700
{
672701
case 0:
@@ -685,12 +714,18 @@ private async void ClearMemory(int index)
685714
{
686715
ramSavings = Math.Abs(ramSavings);
687716
_logController.AddLog(new RamLog("RAM usage increase: " + ramSavings.ToString("F2") + " MB"));
688-
MessageBox.Show("Looks like your RAM usage has increased with " + ramSavings.ToString("F2") + " MB!", "MemPlus", MessageBoxButton.OK, MessageBoxImage.Information);
717+
if (_statisticsMessage)
718+
{
719+
MessageBox.Show("Looks like your RAM usage has increased with " + ramSavings.ToString("F2") + " MB!", "MemPlus", MessageBoxButton.OK, MessageBoxImage.Information);
720+
}
689721
}
690722
else
691723
{
692724
_logController.AddLog(new RamLog("RAM usage decrease: " + ramSavings.ToString("F2") + " MB"));
693-
MessageBox.Show("You saved " + ramSavings.ToString("F2") + " MB of RAM!", "MemPlus", MessageBoxButton.OK, MessageBoxImage.Information);
725+
if (_statisticsMessage)
726+
{
727+
MessageBox.Show("You saved " + ramSavings.ToString("F2") + " MB of RAM!", "MemPlus", MessageBoxButton.OK, MessageBoxImage.Information);
728+
}
694729
}
695730

696731
BtnClearMemory.IsEnabled = true;
@@ -701,6 +736,7 @@ private async void ClearMemory(int index)
701736
MessageBox.Show(ex.Message, "MemPlus", MessageBoxButton.OK, MessageBoxImage.Error);
702737
}
703738

739+
_clearingMemory = false;
704740
_logController.AddLog(new ApplicationLog("Done clearing RAM memory"));
705741
}
706742
}

MemPlus/Views/Windows/SettingsWindow.xaml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
UseLayoutRounding="True"
1010
TitleTextAlignment="Center"
1111
WindowStartupLocation="CenterScreen"
12-
Title="MemPlus - Settings" Height="350" Width="450" Icon="/MemPlus;component/Resources/Images/ram.png">
12+
Title="MemPlus - Settings" Height="380" Width="450" Icon="/MemPlus;component/Resources/Images/ram.png">
1313
<Grid>
1414
<Grid.RowDefinitions>
1515
<RowDefinition></RowDefinition>
@@ -36,6 +36,7 @@
3636
<RowDefinition Height="Auto" />
3737
<RowDefinition Height="Auto" />
3838
<RowDefinition Height="Auto" />
39+
<RowDefinition Height="Auto" />
3940
</Grid.RowDefinitions>
4041

4142
<CheckBox Grid.Row="0" x:Name="ChbAutoStart" Content="Automatic start MemPlus when Windows starts" Margin="3" />
@@ -46,6 +47,7 @@
4647
<CheckBox Grid.Row="5" x:Name="ChbNotifyIcon" Content="Display notifyicon" Margin="3" />
4748
<CheckBox Grid.Row="6" x:Name="ChbWindowDraggable" Content="Allow windows to be dragged by clicking anywhere" Margin="3" />
4849
<CheckBox Grid.Row="7" x:Name="ChbAdminWarning" Content="Display administrative rights warning" Margin="3" />
50+
<CheckBox Grid.Row="8" x:Name="ChbRamClearingMessage" Content="Display information after clearing RAM" Margin="3" />
4951
</Grid>
5052
</GroupBox>
5153
</Grid>

MemPlus/Views/Windows/SettingsWindow.xaml.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@ private void LoadProperties()
9494
ChbWindowDraggable.IsChecked = false;
9595
}
9696
ChbAdminWarning.IsChecked = Properties.Settings.Default.AdministrativeWarning;
97+
ChbRamClearingMessage.IsChecked = Properties.Settings.Default.RamCleaningMessage;
9798

9899
//RAM Monitor
99100
ChbRamMonitor.IsChecked = Properties.Settings.Default.RamMonitor;
@@ -211,6 +212,7 @@ private void SaveProperties()
211212
if (ChbNotifyIcon.IsChecked != null) Properties.Settings.Default.NotifyIcon = ChbNotifyIcon.IsChecked.Value;
212213
if (ChbWindowDraggable.IsChecked != null) Properties.Settings.Default.WindowDragging = ChbWindowDraggable.IsChecked.Value;
213214
if (ChbAdminWarning.IsChecked != null) Properties.Settings.Default.AdministrativeWarning = ChbAdminWarning.IsChecked.Value;
215+
if (ChbRamClearingMessage.IsChecked != null) Properties.Settings.Default.RamCleaningMessage = ChbRamClearingMessage.IsChecked.Value;
214216
if (ChbStartHidden.IsChecked != null) Properties.Settings.Default.HideOnStart = ChbStartHidden.IsChecked.Value;
215217
if (ChbStartMinimized.IsChecked != null) Properties.Settings.Default.StartMinimized = ChbStartMinimized.IsChecked.Value;
216218

0 commit comments

Comments
 (0)