Skip to content

Commit

Permalink
v1.6
Browse files Browse the repository at this point in the history
Added admin check perms for standby (cache) memory clearing to prevent issues. Will prompt for admin check when checking it too and on boot.
  • Loading branch information
RedDot-3ND7355 committed Dec 17, 2023
1 parent 067d74a commit a5faf8e
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 3 deletions.
49 changes: 47 additions & 2 deletions MemoryCleaner/Form1.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
using IWshRuntimeLibrary;
using MaterialSkin;
using System;
using System.Diagnostics;
using System.Reflection;
using System.Security.Principal;
using System.Threading;
using System.Windows.Forms;

Expand Down Expand Up @@ -32,10 +35,20 @@ public Form1()
SettingsHandler.ReadSettings();
// App Started Boolean
AppStarted = true;
// Restart as admin if clean cache is checked
CheckCachedCleanPerm();
// Set Timer if any at start
CheckForExistingTimer();
}

// Check Perms
private void CheckCachedCleanPerm()
{
// Check required perms
if (materialCheckbox3.Checked && !IsAdministrator())
RestartAsAdmin(Assembly.GetExecutingAssembly().Location);
}

// Completely forgot about it, teehee. Function is pretty self explanatory.
private void CheckForExistingTimer()
{
Expand Down Expand Up @@ -164,15 +177,47 @@ private void notifyIcon1_MouseClick(object sender, MouseEventArgs e)
// About
private void materialButton3_Click(object sender, EventArgs e)
{
MaterialSkin.Controls.MaterialMessageBox.Show($"Made by Endless (Kogaruh){Environment.NewLine}Version: 1.1{Environment.NewLine}Run as admin for best results!");
MaterialSkin.Controls.MaterialMessageBox.Show($"Made by Endless (Kogaruh){Environment.NewLine}Version: 1.6{Environment.NewLine}Run as admin for best results!");
}

// Toggle Standby Cache Memory Clear
// Toggle Standby Cache Memory Clear (with admin check)
private void materialCheckbox3_CheckedChanged(object sender, EventArgs e)
{
if (AppStarted)
// Save Setting
SettingsHandler.SaveSettings();

// Check required perms
CheckCachedCleanPerm();
}

// Check if ran as admin
private static bool IsAdministrator()
{
var identity = WindowsIdentity.GetCurrent();
var principal = new WindowsPrincipal(identity);
return principal.IsInRole(WindowsBuiltInRole.Administrator);
}

// Restart as admin
private void RestartAsAdmin(string exe)
{
var proc = new Process
{
StartInfo =
{
FileName = exe,
UseShellExecute = true,
Verb = "runas"
}
};
try
{
if (proc.Start())
Process.GetCurrentProcess().Kill();
else
materialCheckbox3.Checked = false;
} catch { materialCheckbox3.Checked = false; }
}
}
}
2 changes: 1 addition & 1 deletion MemoryCleaner/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,4 @@
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.2.0.0")]
[assembly: AssemblyFileVersion("1.6.0.0")]

0 comments on commit a5faf8e

Please sign in to comment.