From 64648cf64031541fd236cb989b222194c8497a04 Mon Sep 17 00:00:00 2001 From: Hypn0tick Date: Fri, 9 Feb 2024 12:33:02 -0300 Subject: [PATCH 1/2] Altered the CustomRamLimiter function to allow pulling from an external file, and added an option for users to select this file. --- Program.cs | 50 +++++++++++++++++++++++++++++++++++++++++++------- 1 file changed, 43 insertions(+), 7 deletions(-) diff --git a/Program.cs b/Program.cs index d67a0c7..3b3179a 100644 --- a/Program.cs +++ b/Program.cs @@ -1,6 +1,7 @@ using System; using System.Collections.Generic; using System.Diagnostics; +using System.IO; using System.Linq; using System.Management; using System.Runtime.InteropServices; @@ -21,13 +22,43 @@ public static List GetCustom(string processName) return Process.GetProcessesByName(processName).ToList(); } - // Method to limit RAM usage of multiple custom processes - static void CustomRamLimiter(int min, int max) + // Method to limit RAM usage of multiple custom processes - modified by Hypn0tick + static void CustomRamLimiter(int min, int max, bool useConfig = false, string configFile = "RAMLimiter.ini") { - Console.WriteLine("Type Process Names Separated by Commas (e.g., chrome,obs,discord):"); - string processNamesInput = Console.ReadLine(); - List processNames = processNamesInput.Split(',').Select(p => p.Trim().ToLower()).ToList(); - + List processNames = null; + if (useConfig) + { + configInput: + if (configFile == null) + { + Console.WriteLine("Input the name of a configuration file to be read:\nNOTE: This file should contain a list of processes to limit, with one name on each line."); + configFile = Console.ReadLine(); + } + string configDir = Path.GetDirectoryName(Process.GetCurrentProcess().MainModule.FileName); + Console.WriteLine(configDir + configFile); + if (File.Exists(configFile)) + { + var lines = File.ReadLines(configFile); + string processNamesInput = null; + foreach (var line in lines) + { + processNamesInput = line + "," + processNamesInput; + } + processNames = processNamesInput.Split(',').Select(p => p.Trim().ToLower()).ToList(); + } + else + { + Console.WriteLine("ERROR: Could not find the " + configFile + " configuration file.\n"); + configFile = null; + goto configInput; + } + } + else + { + Console.WriteLine("Type Process Names Separated by Commas (e.g., chrome,obs,discord):"); + string processNamesInput = Console.ReadLine(); + processNames = processNamesInput.Split(',').Select(p => p.Trim().ToLower()).ToList(); + } List processesToLimit = new List(); foreach (var processName in processNames) { @@ -66,7 +97,6 @@ static void CustomRamLimiter(int min, int max) } }).Start(); } - Thread.Sleep(-1); } @@ -349,6 +379,7 @@ static void Main(string[] args) Console.WriteLine("Just Limit OBS: 3"); Console.WriteLine("Limit Discord & Chrome: 4"); Console.WriteLine("Limit Custom: 5"); + Console.WriteLine("Limit Custom (External List): 6"); ConsoleKey response = Console.ReadKey(true).Key; Console.WriteLine(); if (response == ConsoleKey.D1) @@ -376,6 +407,11 @@ static void Main(string[] args) Console.Clear(); CustomRamLimiter(-1, -1); } + else if (response == ConsoleKey.D6) + { + Console.Clear(); + CustomRamLimiter(-1, -1, true); + } else { Console.Clear(); From 79fbb47a0f802ee27e9d8519610a8e23f87cd413 Mon Sep 17 00:00:00 2001 From: hypn0tick Date: Sun, 11 Feb 2024 14:45:02 -0300 Subject: [PATCH 2/2] Modified to allow for comments in the configuration file. --- Program.cs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Program.cs b/Program.cs index 3b3179a..3158910 100644 --- a/Program.cs +++ b/Program.cs @@ -42,7 +42,8 @@ static void CustomRamLimiter(int min, int max, bool useConfig = false, string co string processNamesInput = null; foreach (var line in lines) { - processNamesInput = line + "," + processNamesInput; + string output = Regex.Replace(line, "//.*", ""); + processNamesInput = output + "," + processNamesInput; } processNames = processNamesInput.Split(',').Select(p => p.Trim().ToLower()).ToList(); }