Skip to content

Commit

Permalink
v2.4.0
Browse files Browse the repository at this point in the history
  • Loading branch information
Special-Niewbie committed Aug 23, 2024
1 parent cfaf663 commit f1a5642
Show file tree
Hide file tree
Showing 3 changed files with 74 additions and 54 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -46,23 +46,18 @@ public void IncreaseRAM(MessagesBoxImplementation messagesBoxImplementation)
return;
}

// Get total physical memory using Systeminfo
string output = ExecuteCmd("Systeminfo | find \"Total Physical Memory\"");
// Get total physical memory using PowerShell
string output = ExecuteCmd("powershell -command \"(Get-WmiObject -Class Win32_ComputerSystem | Select-Object -ExpandProperty TotalPhysicalMemory) / 1MB\"");

// Parsing the output to get the total RAM
string[] tokens = output.Split(new char[] { ' ', ',' }, StringSplitOptions.RemoveEmptyEntries);
if (tokens.Length >= 5)
if (double.TryParse(output.Trim(), out double RAM))
{
string ramString = tokens[3] + tokens[4]; // Merge tokens to get RAM without spaces and commas
ulong RAM = ulong.Parse(ramString);

ulong initialSize, maximumSize;

if (dialogResult == DialogResult.Yes)
{
// Calculate initialSize and maximumSize for VRAM+
initialSize = RAM * 3 / 2;
maximumSize = RAM * 3;
initialSize = (ulong)(RAM * 3 / 2);
maximumSize = (ulong)(RAM * 3);
}
else // DialogResult.No
{
Expand Down
111 changes: 68 additions & 43 deletions Console2Desk/Console2Desk/FuturesButtons/RAMChecker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,59 +17,53 @@ public async Task CheckVirtualMemorySettingsAsync(MessagesBoxImplementation mess
{
try
{
// Get the total physical memory
string output = await ExecuteCmdAsync("Systeminfo | find \"Total Physical Memory\"");
string[] tokens = output.Split(new char[] { ' ', ',' }, StringSplitOptions.RemoveEmptyEntries);
// Get the total physical memory using PowerShell
string output = await ExecutePowerShellCommandAsync("Get-WmiObject -Class Win32_ComputerSystem | Select-Object -ExpandProperty TotalPhysicalMemory");
string ramNumericString = new string(output.Where(char.IsDigit).ToArray());
ulong RAM = ulong.Parse(ramNumericString);

if (tokens.Length >= 5)
{
string ramString = tokens[3] + tokens[4];
string ramNumericString = new string(ramString.Where(char.IsDigit).ToArray());
ulong RAM = ulong.Parse(ramNumericString);

// Calculate initial and maximum size in MB
ulong initialSize = RAM * 3 / 2;
ulong maximumSize = RAM * 3;
// Calculate initial and maximum size in MB
ulong initialSize = RAM * 3 / 2 / 1024 / 1024;
ulong maximumSize = RAM * 3 / 1024 / 1024;

// Get the current paging file settings
string regOutput = await ExecuteCmdAsync("reg query \"HKLM\\SYSTEM\\CurrentControlSet\\Control\\Session Manager\\Memory Management\" /v PagingFiles");
string[] regLines = regOutput.Split(new[] { Environment.NewLine }, StringSplitOptions.RemoveEmptyEntries);
// Get the current paging file settings
string regOutput = await ExecuteCmdAsync("reg query \"HKLM\\SYSTEM\\CurrentControlSet\\Control\\Session Manager\\Memory Management\" /v PagingFiles");
string[] regLines = regOutput.Split(new[] { Environment.NewLine }, StringSplitOptions.RemoveEmptyEntries);

foreach (string line in regLines)
foreach (string line in regLines)
{
if (line.Contains("PagingFiles"))
{
if (line.Contains("PagingFiles"))
string[] regTokens = line.Split(new char[] { ' ', '\t' }, StringSplitOptions.RemoveEmptyEntries);
if (regTokens.Length >= 5)
{
string[] regTokens = line.Split(new char[] { ' ', '\t' }, StringSplitOptions.RemoveEmptyEntries);
if (regTokens.Length >= 5)
{
ulong currentInitialSize = ulong.Parse(regTokens[3]);
ulong currentMaximumSize = ulong.Parse(regTokens[4]);
ulong currentInitialSize = ulong.Parse(regTokens[3]);
ulong currentMaximumSize = ulong.Parse(regTokens[4]);

// Set icons based on VRAM settings
if (currentInitialSize == 16 && currentMaximumSize == 8192)
{
pictureBoxCheckVRAM.Visible = true;
pictureBoxCheckVRAM.Image = Properties.Resources.green_check_mark_icon_56x56;
}
else if (currentInitialSize == initialSize && currentMaximumSize == maximumSize)
{
pictureBoxVramPlus.Visible = true;
pictureBoxVramPlus.Image = Properties.Resources.vramPlus;
}
else
{
pictureBoxCheckVRAM.Visible = true;
pictureBoxCheckVRAM.Image = Properties.Resources.WarningInfo;
}
return;
// Set icons based on VRAM settings
if (currentInitialSize == 16 && currentMaximumSize == 8192)
{
pictureBoxCheckVRAM.Visible = true;
pictureBoxCheckVRAM.Image = Properties.Resources.green_check_mark_icon_56x56;
}
else if (currentInitialSize == initialSize && currentMaximumSize == maximumSize)
{
pictureBoxVramPlus.Visible = true;
pictureBoxVramPlus.Image = Properties.Resources.vramPlus;
}
else
{
pictureBoxCheckVRAM.Visible = true;
pictureBoxCheckVRAM.Image = Properties.Resources.WarningInfo;
}
return;
}
}

// Handle cases where the paging file settings could not be found
pictureBoxCheckVRAM.Visible = true;
pictureBoxCheckVRAM.Image = Properties.Resources.WarningInfo;
}

// Handle cases where the paging file settings could not be found
pictureBoxCheckVRAM.Visible = true;
pictureBoxCheckVRAM.Image = Properties.Resources.WarningInfo;
}
catch (Exception ex)
{
Expand Down Expand Up @@ -107,5 +101,36 @@ private async Task<string> ExecuteCmdAsync(string command)
return string.Empty;
}
}

private async Task<string> ExecutePowerShellCommandAsync(string command)
{
try
{
return await Task.Run(() =>
{
ProcessStartInfo psi = new ProcessStartInfo
{
FileName = "powershell.exe",
Arguments = $"-Command \"{command}\"",
RedirectStandardOutput = true,
UseShellExecute = false,
CreateNoWindow = true
};
using (Process process = Process.Start(psi))
{
using (StreamReader reader = process.StandardOutput)
{
return reader.ReadToEnd();
}
}
});
}
catch (Exception ex)
{
DependencyContainer.MessagesBoxImplementation.ShowMessage($"An error occurred while executing PowerShell command '{command}': {ex.Message}", "Error", MessageBoxButtons.OK);
return string.Empty;
}
}
}
}
2 changes: 1 addition & 1 deletion version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
2.3.0
2.4.0

0 comments on commit f1a5642

Please sign in to comment.