From 3ae0eaf57c3c676be18a30f2940da4e4f391831c Mon Sep 17 00:00:00 2001 From: rinrab Date: Sun, 10 Sep 2023 21:40:32 +0200 Subject: [PATCH 1/7] Format code, remove/add linebrakes and sort usings. --- RunCat/Program.cs | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/RunCat/Program.cs b/RunCat/Program.cs index 4a1355f..9b4c7ee 100644 --- a/RunCat/Program.cs +++ b/RunCat/Program.cs @@ -12,15 +12,15 @@ // See the License for the specific language governing permissions and // limitations under the License. -using RunCat.Properties; using Microsoft.Win32; +using RunCat.Properties; using System; using System.Collections.Generic; -using System.Drawing; +using System.ComponentModel; using System.Diagnostics; -using System.Windows.Forms; +using System.Drawing; using System.Resources; -using System.ComponentModel; +using System.Windows.Forms; namespace RunCat { @@ -66,7 +66,6 @@ public class RunCatApplicationContext : ApplicationContext private Timer animateTimer = new Timer(); private Timer cpuTimer = new Timer(); - public RunCatApplicationContext() { UserSettings.Default.Reload(); @@ -174,6 +173,7 @@ public RunCatApplicationContext() current = 1; } + private void OnApplicationExit(object sender, EventArgs e) { UserSettings.Default.Runner = runner; @@ -216,8 +216,8 @@ private void SetIcons() if (runner.Equals("parrot")) { capacity = 10; - } - else if (runner.Equals("horse")) + } + else if (runner.Equals("horse")) { capacity = 14; } @@ -263,9 +263,9 @@ private void SetSpeed() else if (speed.Equals("cpu 20%")) minCPU = 50f; else if (speed.Equals("cpu 30%")) - minCPU = 33f; + minCPU = 33f; else if (speed.Equals("cpu 40%")) - minCPU = 25f; + minCPU = 25f; } private void SetSpeedLimit(object sender, EventArgs e) @@ -302,6 +302,7 @@ private void SetDarkIcons(object sender, EventArgs e) manualTheme = "dark"; SetIcons(); } + private void UserPreferenceChanged(object sender, UserPreferenceChangedEventArgs e) { if (e.Category == UserPreferenceCategory.General) UpdateThemeIcons(); @@ -350,7 +351,7 @@ private void SetAnimation() private void CPUTickSpeed() { if (!speed.Equals("default")) - { + { float manualInterval = (float)Math.Max(minCPU, interval); animateTimer.Stop(); animateTimer.Interval = (int)manualInterval; @@ -383,7 +384,7 @@ private void StartObserveCPU() cpuTimer.Tick += new EventHandler(ObserveCPUTick); cpuTimer.Start(); } - + private void HandleDoubleClick(object Sender, EventArgs e) { var startInfo = new ProcessStartInfo @@ -395,6 +396,5 @@ private void HandleDoubleClick(object Sender, EventArgs e) }; Process.Start(startInfo); } - } } From fcbebabf1fe8a53c62e00392111da8ec6828499c Mon Sep 17 00:00:00 2001 From: rinrab Date: Sun, 10 Sep 2023 21:42:19 +0200 Subject: [PATCH 2/7] Add readonly modifiers in RunCatApplicationContext where it posible. --- RunCat/Program.cs | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/RunCat/Program.cs b/RunCat/Program.cs index 9b4c7ee..eaacc13 100644 --- a/RunCat/Program.cs +++ b/RunCat/Program.cs @@ -49,12 +49,12 @@ public class RunCatApplicationContext : ApplicationContext { private const int CPU_TIMER_DEFAULT_INTERVAL = 3000; private const int ANIMATE_TIMER_DEFAULT_INTERVAL = 200; - private PerformanceCounter cpuUsage; - private ToolStripMenuItem runnerMenu; - private ToolStripMenuItem themeMenu; - private ToolStripMenuItem startupMenu; - private ToolStripMenuItem runnerSpeedLimit; - private NotifyIcon notifyIcon; + private readonly PerformanceCounter cpuUsage; + private readonly ToolStripMenuItem runnerMenu; + private readonly ToolStripMenuItem themeMenu; + private readonly ToolStripMenuItem startupMenu; + private readonly ToolStripMenuItem runnerSpeedLimit; + private readonly NotifyIcon notifyIcon; private string runner = ""; private int current = 0; private float minCPU; @@ -63,8 +63,8 @@ public class RunCatApplicationContext : ApplicationContext private string manualTheme = UserSettings.Default.Theme; private string speed = UserSettings.Default.Speed; private Icon[] icons; - private Timer animateTimer = new Timer(); - private Timer cpuTimer = new Timer(); + private readonly Timer animateTimer = new Timer(); + private readonly Timer cpuTimer = new Timer(); public RunCatApplicationContext() { From a569c7498b3e9fe0e24a52f7396c4ee1b6b35200 Mon Sep 17 00:00:00 2001 From: rinrab Date: Sun, 10 Sep 2023 21:43:51 +0200 Subject: [PATCH 3/7] Wrap and sort fields in RunCatApplicationContext. --- RunCat/Program.cs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/RunCat/Program.cs b/RunCat/Program.cs index eaacc13..992cadc 100644 --- a/RunCat/Program.cs +++ b/RunCat/Program.cs @@ -49,12 +49,15 @@ public class RunCatApplicationContext : ApplicationContext { private const int CPU_TIMER_DEFAULT_INTERVAL = 3000; private const int ANIMATE_TIMER_DEFAULT_INTERVAL = 200; + private readonly PerformanceCounter cpuUsage; private readonly ToolStripMenuItem runnerMenu; private readonly ToolStripMenuItem themeMenu; private readonly ToolStripMenuItem startupMenu; private readonly ToolStripMenuItem runnerSpeedLimit; private readonly NotifyIcon notifyIcon; + private Icon[] icons; + private string runner = ""; private int current = 0; private float minCPU; @@ -62,7 +65,7 @@ public class RunCatApplicationContext : ApplicationContext private string systemTheme = ""; private string manualTheme = UserSettings.Default.Theme; private string speed = UserSettings.Default.Speed; - private Icon[] icons; + private readonly Timer animateTimer = new Timer(); private readonly Timer cpuTimer = new Timer(); From e10f1b0ce8682a0012787272a21bf402f2997efc Mon Sep 17 00:00:00 2001 From: rinrab Date: Sun, 10 Sep 2023 22:29:58 +0200 Subject: [PATCH 4/7] Use shorter getting ProccessPath --- RunCat/Program.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/RunCat/Program.cs b/RunCat/Program.cs index 992cadc..66cc274 100644 --- a/RunCat/Program.cs +++ b/RunCat/Program.cs @@ -319,7 +319,7 @@ private void SetStartup(object sender, EventArgs e) { if (startupMenu.Checked) { - rKey.SetValue(Application.ProductName, Process.GetCurrentProcess().MainModule.FileName); + rKey.SetValue(Application.ProductName, Environment.ProcessPath); } else { From 90f955baa314fe89e58c15f46a7ccbc253e541e4 Mon Sep 17 00:00:00 2001 From: rinrab Date: Sun, 10 Sep 2023 22:38:12 +0200 Subject: [PATCH 5/7] Rename RunCatApplicationContext.current to RunCatApplicationContext.currentFrame. --- RunCat/Program.cs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/RunCat/Program.cs b/RunCat/Program.cs index 66cc274..1327e76 100644 --- a/RunCat/Program.cs +++ b/RunCat/Program.cs @@ -59,7 +59,7 @@ public class RunCatApplicationContext : ApplicationContext private Icon[] icons; private string runner = ""; - private int current = 0; + private int currentFrame = 0; private float minCPU; private float interval; private string systemTheme = ""; @@ -174,7 +174,7 @@ public RunCatApplicationContext() SetSpeed(); StartObserveCPU(); - current = 1; + currentFrame = 1; } private void OnApplicationExit(object sender, EventArgs e) @@ -340,9 +340,9 @@ private void Exit(object sender, EventArgs e) private void AnimationTick(object sender, EventArgs e) { - if (icons.Length <= current) current = 0; - notifyIcon.Icon = icons[current]; - current = (current + 1) % icons.Length; + if (icons.Length <= currentFrame) currentFrame = 0; + notifyIcon.Icon = icons[currentFrame]; + currentFrame = (currentFrame + 1) % icons.Length; } private void SetAnimation() From 55e665d59f3b26f5e68e8b5618a1214b6a49ac71 Mon Sep 17 00:00:00 2001 From: rinrab Date: Sun, 10 Sep 2023 22:43:25 +0200 Subject: [PATCH 6/7] Simplify IsStartUpEnabled code: return just null check, not conditional operator. --- RunCat/Program.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/RunCat/Program.cs b/RunCat/Program.cs index 1327e76..8f0fcfb 100644 --- a/RunCat/Program.cs +++ b/RunCat/Program.cs @@ -190,7 +190,7 @@ private bool IsStartupEnabled() string keyName = @"Software\Microsoft\Windows\CurrentVersion\Run"; using (RegistryKey rKey = Registry.CurrentUser.OpenSubKey(keyName)) { - return (rKey.GetValue(Application.ProductName) != null) ? true : false; + return rKey.GetValue(Application.ProductName) != null; } } From 1e258aa1872c7ac9e269c0c1c3638dc68eca57d5 Mon Sep 17 00:00:00 2001 From: rinrab Date: Mon, 11 Sep 2023 21:29:20 +0200 Subject: [PATCH 7/7] Run task manager without powershell. --- RunCat/Program.cs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/RunCat/Program.cs b/RunCat/Program.cs index 8f0fcfb..ab94361 100644 --- a/RunCat/Program.cs +++ b/RunCat/Program.cs @@ -19,6 +19,7 @@ using System.ComponentModel; using System.Diagnostics; using System.Drawing; +using System.IO; using System.Resources; using System.Windows.Forms; @@ -390,13 +391,12 @@ private void StartObserveCPU() private void HandleDoubleClick(object Sender, EventArgs e) { - var startInfo = new ProcessStartInfo + ProcessStartInfo startInfo = new ProcessStartInfo { - FileName = "powershell", - UseShellExecute = false, - Arguments = " -c Start-Process taskmgr.exe", - CreateNoWindow = true, + UseShellExecute = true, + FileName = Path.Combine(Environment.SystemDirectory, "taskmgr.exe"), }; + Process.Start(startInfo); } }