Skip to content

Commit d3ab718

Browse files
committed
* Code improvements
* Logging improvements
1 parent cfff286 commit d3ab718

File tree

6 files changed

+24
-7
lines changed

6 files changed

+24
-7
lines changed

MemPlus/Classes/GUI/StyleManager.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
using System.Windows.Media;
44
using Syncfusion.Windows.Shared;
55

6-
namespace MemPlus.Classes
6+
namespace MemPlus.Classes.GUI
77
{
88
/// <summary>
99
/// Static class to change the style of an object

MemPlus/Classes/RAM/RamController.cs

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,11 @@
99

1010
namespace MemPlus.Classes.RAM
1111
{
12+
/// <inheritdoc />
1213
/// <summary>
1314
/// Sealed class containing methods and interaction logic in terms of RAM
1415
/// </summary>
15-
internal sealed class RamController
16+
internal sealed class RamController : IDisposable
1617
{
1718
#region Variables
1819
/// <summary>
@@ -102,6 +103,11 @@ internal RamController(Dispatcher dispatcher, SfCircularGauge gauge, Label lblTo
102103
_logController.AddLog(new ApplicationLog("Done initializing RamController"));
103104
}
104105

106+
~RamController()
107+
{
108+
_ramTimer?.Dispose();
109+
}
110+
105111
/// <summary>
106112
/// Enable RAM usage monitoring
107113
/// </summary>
@@ -200,5 +206,10 @@ private void UpdateRamUsage()
200206

201207
_logController.AddLog(new ApplicationLog("Finished updating RAM usage"));
202208
}
209+
210+
public void Dispose()
211+
{
212+
_ramTimer?.Dispose();
213+
}
203214
}
204215
}

MemPlus/Classes/RAM/RamOptimizer.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ internal sealed class RamOptimizer
8989
/// <param name="lpName">A pointer to a null-terminated string that specifies the name of the privilege, as defined in the Winnt.h header file. For example, this parameter could specify the constant, SE_SECURITY_NAME, or its corresponding string, "SeSecurityPrivilege"</param>
9090
/// <param name="pluid">A pointer to a variable that receives the LUID by which the privilege is known on the system specified by the lpSystemName parameter.</param>
9191
/// <returns>If the function succeeds, the function returns nonzero. Otherwise, return value will be zero</returns>
92-
[DllImport("advapi32.dll", SetLastError = true)]
92+
[DllImport("advapi32.dll", SetLastError = true, CharSet = CharSet.Unicode)]
9393
private static extern bool LookupPrivilegeValue(string lpSystemName, string lpName, ref long pluid);
9494
/// <summary>
9595
/// Enables or disables privileges in the specified access token. Enabling or disabling privileges in an access token requires TOKEN_ADJUST_PRIVILEGES access

MemPlus/Windows/LogWindow.xaml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,14 @@
2323
</GridView>
2424
</ListView.View>
2525
</ListView>
26+
2627
<Grid Grid.Row="1">
2728
<Grid.ColumnDefinitions>
2829
<ColumnDefinition></ColumnDefinition>
2930
<ColumnDefinition></ColumnDefinition>
3031
</Grid.ColumnDefinitions>
3132

32-
<Button MinHeight="25" Margin="5" Content="Export" Click="BtnExport_OnClick" />
33+
<Button Grid.Column="0" MinHeight="25" Margin="5" Content="Export" Click="BtnExport_OnClick" />
3334
<Button Grid.Column="1" MinHeight="25" Margin="5" Content="Clear logs" Click="BtnClear_OnClick" />
3435
</Grid>
3536
</Grid>

MemPlus/Windows/LogWindow.xaml.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
using System.Windows;
55
using System.Windows.Controls;
66
using System.Windows.Controls.Primitives;
7-
using MemPlus.Classes;
7+
using MemPlus.Classes.GUI;
88
using MemPlus.Classes.LOG;
99

1010
namespace MemPlus.Windows

MemPlus/Windows/MainWindow.xaml.cs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
using System;
22
using System.Windows;
33
using System.Windows.Media;
4-
using MemPlus.Classes;
4+
using MemPlus.Classes.GUI;
55
using MemPlus.Classes.LOG;
66
using MemPlus.Classes.RAM;
77

@@ -70,17 +70,21 @@ private async void BtnClearMemory_OnClick(object sender, RoutedEventArgs e)
7070
double ramSavings = _ramController.RamSavings / 1024 / 1024;
7171
if (ramSavings < 0)
7272
{
73-
MessageBox.Show("Looks like your RAM usage has increased with " + Math.Abs(ramSavings).ToString("F2") + " MB!", "MemPlus", MessageBoxButton.OK, MessageBoxImage.Information);
73+
ramSavings = Math.Abs(ramSavings);
74+
_logController.AddLog(new ApplicationLog("RAM usage increase: " + ramSavings.ToString("F2") + " MB"));
75+
MessageBox.Show("Looks like your RAM usage has increased with " + ramSavings.ToString("F2") + " MB!", "MemPlus", MessageBoxButton.OK, MessageBoxImage.Information);
7476
}
7577
else
7678
{
79+
_logController.AddLog(new ApplicationLog("RAM usage decrease: " + ramSavings.ToString("F2") + " MB"));
7780
MessageBox.Show("You saved " + ramSavings.ToString("F2") + " MB of RAM!", "MemPlus", MessageBoxButton.OK, MessageBoxImage.Information);
7881
}
7982

8083
BtnClearMemory.IsEnabled = true;
8184
}
8285
catch (Exception ex)
8386
{
87+
_logController.AddLog(new ApplicationLog(ex.Message));
8488
MessageBox.Show(ex.Message, "MemPlus", MessageBoxButton.OK, MessageBoxImage.Error);
8589
}
8690

@@ -120,6 +124,7 @@ private void HomePageMenuItem_OnClick(object sender, RoutedEventArgs e)
120124
}
121125
catch (Exception ex)
122126
{
127+
_logController.AddLog(new ApplicationLog(ex.Message));
123128
MessageBox.Show(ex.Message, "MemPlus", MessageBoxButton.OK, MessageBoxImage.Error);
124129
}
125130
}

0 commit comments

Comments
 (0)