From 9e6454e82f8dadd2e4552ced4512c8788d6cbefd Mon Sep 17 00:00:00 2001 From: xEndless Date: Sun, 26 May 2024 09:01:16 -0400 Subject: [PATCH] v1.7 Added Start minimized to tray on windows startup --- MemoryCleaner/Form1.Designer.cs | 49 +++++++++++++++++++++--- MemoryCleaner/Form1.cs | 34 ++++++++++++++-- MemoryCleaner/Properties/AssemblyInfo.cs | 4 +- MemoryCleaner/SettingsHandler.cs | 11 ++++-- 4 files changed, 84 insertions(+), 14 deletions(-) diff --git a/MemoryCleaner/Form1.Designer.cs b/MemoryCleaner/Form1.Designer.cs index ea92243..0ada585 100644 --- a/MemoryCleaner/Form1.Designer.cs +++ b/MemoryCleaner/Form1.Designer.cs @@ -48,6 +48,8 @@ private void InitializeComponent() this.notifyIcon1 = new System.Windows.Forms.NotifyIcon(this.components); this.materialButton3 = new MaterialSkin.Controls.MaterialButton(); this.materialCheckbox3 = new MaterialSkin.Controls.MaterialCheckbox(); + this.materialCheckbox4 = new MaterialSkin.Controls.MaterialCheckbox(); + this.materialLabel5 = new MaterialSkin.Controls.MaterialLabel(); this.materialCard1.SuspendLayout(); this.SuspendLayout(); // @@ -59,12 +61,12 @@ private void InitializeComponent() this.materialCard1.Controls.Add(this.materialComboBox1); this.materialCard1.Depth = 0; this.materialCard1.ForeColor = System.Drawing.Color.FromArgb(((int)(((byte)(222)))), ((int)(((byte)(0)))), ((int)(((byte)(0)))), ((int)(((byte)(0))))); - this.materialCard1.Location = new System.Drawing.Point(248, 78); + this.materialCard1.Location = new System.Drawing.Point(248, 109); this.materialCard1.Margin = new System.Windows.Forms.Padding(14); this.materialCard1.MouseState = MaterialSkin.MouseState.HOVER; this.materialCard1.Name = "materialCard1"; this.materialCard1.Padding = new System.Windows.Forms.Padding(14); - this.materialCard1.Size = new System.Drawing.Size(252, 134); + this.materialCard1.Size = new System.Drawing.Size(252, 103); this.materialCard1.TabIndex = 1; // // materialLabel3 @@ -73,7 +75,7 @@ private void InitializeComponent() this.materialLabel3.Depth = 0; this.materialLabel3.Font = new System.Drawing.Font("Roboto", 24F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Pixel); this.materialLabel3.FontType = MaterialSkin.MaterialSkinManager.fontType.H5; - this.materialLabel3.Location = new System.Drawing.Point(150, 72); + this.materialLabel3.Location = new System.Drawing.Point(150, 54); this.materialLabel3.MouseState = MaterialSkin.MouseState.HOVER; this.materialLabel3.Name = "materialLabel3"; this.materialLabel3.Size = new System.Drawing.Size(87, 29); @@ -87,7 +89,7 @@ private void InitializeComponent() this.materialLabel1.Font = new System.Drawing.Font("Roboto", 24F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Pixel); this.materialLabel1.FontType = MaterialSkin.MaterialSkinManager.fontType.H5; this.materialLabel1.HighEmphasis = true; - this.materialLabel1.Location = new System.Drawing.Point(34, 18); + this.materialLabel1.Location = new System.Drawing.Point(34, 10); this.materialLabel1.MouseState = MaterialSkin.MouseState.HOVER; this.materialLabel1.Name = "materialLabel1"; this.materialLabel1.Size = new System.Drawing.Size(180, 29); @@ -118,7 +120,7 @@ private void InitializeComponent() "30", "45", "60"}); - this.materialComboBox1.Location = new System.Drawing.Point(17, 64); + this.materialComboBox1.Location = new System.Drawing.Point(17, 46); this.materialComboBox1.MaxDropDownItems = 4; this.materialComboBox1.MouseState = MaterialSkin.MouseState.OUT; this.materialComboBox1.Name = "materialComboBox1"; @@ -143,6 +145,7 @@ private void InitializeComponent() // this.materialDivider1.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(30)))), ((int)(((byte)(0)))), ((int)(((byte)(0)))), ((int)(((byte)(0))))); this.materialDivider1.Depth = 0; + this.materialDivider1.Enabled = false; this.materialDivider1.Location = new System.Drawing.Point(15, 160); this.materialDivider1.MouseState = MaterialSkin.MouseState.HOVER; this.materialDivider1.Name = "materialDivider1"; @@ -229,6 +232,7 @@ private void InitializeComponent() // this.materialDivider2.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(30)))), ((int)(((byte)(0)))), ((int)(((byte)(0)))), ((int)(((byte)(0))))); this.materialDivider2.Depth = 0; + this.materialDivider2.Enabled = false; this.materialDivider2.Location = new System.Drawing.Point(157, 80); this.materialDivider2.MouseState = MaterialSkin.MouseState.HOVER; this.materialDivider2.Name = "materialDivider2"; @@ -261,6 +265,7 @@ private void InitializeComponent() // this.materialDivider3.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(30)))), ((int)(((byte)(0)))), ((int)(((byte)(0)))), ((int)(((byte)(0))))); this.materialDivider3.Depth = 0; + this.materialDivider3.Enabled = false; this.materialDivider3.Location = new System.Drawing.Point(15, 202); this.materialDivider3.MouseState = MaterialSkin.MouseState.HOVER; this.materialDivider3.Name = "materialDivider3"; @@ -335,6 +340,36 @@ private void InitializeComponent() this.materialCheckbox3.UseVisualStyleBackColor = true; this.materialCheckbox3.CheckedChanged += new System.EventHandler(this.materialCheckbox3_CheckedChanged); // + // materialCheckbox4 + // + this.materialCheckbox4.Depth = 0; + this.materialCheckbox4.Location = new System.Drawing.Point(240, 75); + this.materialCheckbox4.Margin = new System.Windows.Forms.Padding(0); + this.materialCheckbox4.MouseLocation = new System.Drawing.Point(-1, -1); + this.materialCheckbox4.MouseState = MaterialSkin.MouseState.HOVER; + this.materialCheckbox4.Name = "materialCheckbox4"; + this.materialCheckbox4.ReadOnly = false; + this.materialCheckbox4.Ripple = true; + this.materialCheckbox4.Size = new System.Drawing.Size(168, 37); + this.materialCheckbox4.TabIndex = 15; + this.materialCheckbox4.Text = "Start Minimized"; + this.materialCheckbox4.TextAlign = System.Drawing.ContentAlignment.MiddleCenter; + this.materialCheckbox4.UseVisualStyleBackColor = true; + this.materialCheckbox4.CheckedChanged += new System.EventHandler(this.materialCheckbox4_CheckedChanged); + // + // materialLabel5 + // + this.materialLabel5.AutoSize = true; + this.materialLabel5.Depth = 0; + this.materialLabel5.Font = new System.Drawing.Font("Roboto", 34F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Pixel); + this.materialLabel5.FontType = MaterialSkin.MaterialSkinManager.fontType.H4; + this.materialLabel5.Location = new System.Drawing.Point(436, 71); + this.materialLabel5.MouseState = MaterialSkin.MouseState.HOVER; + this.materialLabel5.Name = "materialLabel5"; + this.materialLabel5.Size = new System.Drawing.Size(64, 41); + this.materialLabel5.TabIndex = 16; + this.materialLabel5.Text = "v0.0"; + // // Form1 // this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.None; @@ -352,6 +387,8 @@ private void InitializeComponent() this.Controls.Add(this.materialCheckbox2); this.Controls.Add(this.materialCheckbox1); this.Controls.Add(this.materialCheckbox3); + this.Controls.Add(this.materialCheckbox4); + this.Controls.Add(this.materialLabel5); this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon"))); this.MaximizeBox = false; this.Name = "Form1"; @@ -385,6 +422,8 @@ private void InitializeComponent() private System.Windows.Forms.NotifyIcon notifyIcon1; private MaterialSkin.Controls.MaterialButton materialButton3; public MaterialSkin.Controls.MaterialCheckbox materialCheckbox3; + public MaterialSkin.Controls.MaterialCheckbox materialCheckbox4; + private MaterialSkin.Controls.MaterialLabel materialLabel5; } } diff --git a/MemoryCleaner/Form1.cs b/MemoryCleaner/Form1.cs index 5aba44e..5cabb05 100644 --- a/MemoryCleaner/Form1.cs +++ b/MemoryCleaner/Form1.cs @@ -5,6 +5,7 @@ using System.Reflection; using System.Security.Principal; using System.Threading; +using System.Threading.Tasks; using System.Windows.Forms; namespace MemoryCleaner @@ -17,6 +18,7 @@ public partial class Form1 : MaterialSkin.Controls.MaterialForm public static Form1 CurrentForm; private bool AppStarted = false; private bool bypass = false; + private string appver = FileVersionInfo.GetVersionInfo(Assembly.GetExecutingAssembly().Location).FileVersion.Replace(".0.0", ""); // Ini Form public Form1() @@ -35,10 +37,28 @@ public Form1() SettingsHandler.ReadSettings(); // App Started Boolean AppStarted = true; + // Set Version + materialLabel5.Text = "v" + appver; // Restart as admin if clean cache is checked CheckCachedCleanPerm(); // Set Timer if any at start CheckForExistingTimer(); + // Set Minimized if config present + CheckForStartAsMinimized(); + } + + // Check Start as Minimized added for folks that wants to save 1 second of their time XD + private void CheckForStartAsMinimized() + { + if (materialCheckbox4.Checked) + { + notifyIcon1.Visible = true; + Task.Delay(50).ContinueWith(delegate + { + CheckForIllegalCrossThreadCalls = false; + this.Hide(); + }); + } } // Check Perms @@ -175,10 +195,8 @@ 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.6{Environment.NewLine}Run as admin for best results!"); - } + private void materialButton3_Click(object sender, EventArgs e) => + MaterialSkin.Controls.MaterialMessageBox.Show($"Made by Endless (Kogaruh){Environment.NewLine}Version: {appver}{Environment.NewLine}Run as admin for best results!"); // Toggle Standby Cache Memory Clear (with admin check) private void materialCheckbox3_CheckedChanged(object sender, EventArgs e) @@ -219,5 +237,13 @@ private void RestartAsAdmin(string exe) materialCheckbox3.Checked = false; } catch { materialCheckbox3.Checked = false; } } + + // Save start as minimized + private void materialCheckbox4_CheckedChanged(object sender, EventArgs e) + { + if (AppStarted) + // Save Setting + SettingsHandler.SaveSettings(); + } } } diff --git a/MemoryCleaner/Properties/AssemblyInfo.cs b/MemoryCleaner/Properties/AssemblyInfo.cs index e370173..9c69e5a 100644 --- a/MemoryCleaner/Properties/AssemblyInfo.cs +++ b/MemoryCleaner/Properties/AssemblyInfo.cs @@ -10,7 +10,7 @@ [assembly: AssemblyConfiguration("")] [assembly: AssemblyCompany("")] [assembly: AssemblyProduct("MemoryCleaner")] -[assembly: AssemblyCopyright("Copyright © 2023")] +[assembly: AssemblyCopyright("Copyright © 2024")] [assembly: AssemblyTrademark("")] [assembly: AssemblyCulture("")] @@ -33,4 +33,4 @@ // by using the '*' as shown below: // [assembly: AssemblyVersion("1.0.*")] [assembly: AssemblyVersion("1.0.0.0")] -[assembly: AssemblyFileVersion("1.6.0.0")] +[assembly: AssemblyFileVersion("1.7.0.0")] diff --git a/MemoryCleaner/SettingsHandler.cs b/MemoryCleaner/SettingsHandler.cs index 70a4d7b..fea88bf 100644 --- a/MemoryCleaner/SettingsHandler.cs +++ b/MemoryCleaner/SettingsHandler.cs @@ -12,7 +12,7 @@ namespace MemoryCleaner public static class SettingsHandler { static string default_path = Path.GetDirectoryName(Application.ExecutablePath) + "\\Settings.conf"; - static string default_text = $"Interval = OFF{Environment.NewLine}Startup = false{Environment.NewLine}Advanced = false{Environment.NewLine}Cached = true"; + static string default_text = $"Interval = OFF{Environment.NewLine}Startup = False{Environment.NewLine}Advanced = False{Environment.NewLine}Cached = True{Environment.NewLine}SMinimized = False"; // Initialize Settings public static void IniSettings() @@ -26,7 +26,7 @@ public static void IniSettings() public static void SaveSettings() { // Save Current Settings - File.WriteAllText(default_path, $"Interval = {Form1.CurrentForm.materialComboBox1.SelectedItem.ToString()}{Environment.NewLine}Startup = {Form1.CurrentForm.materialCheckbox1.Checked.ToString()}{Environment.NewLine}Advanced = {Form1.CurrentForm.materialCheckbox2.Checked.ToString()}{Environment.NewLine}Cached = {Form1.CurrentForm.materialCheckbox3.Checked.ToString()}"); + File.WriteAllText(default_path, $"Interval = {Form1.CurrentForm.materialComboBox1.SelectedItem.ToString()}{Environment.NewLine}Startup = {Form1.CurrentForm.materialCheckbox1.Checked.ToString()}{Environment.NewLine}Advanced = {Form1.CurrentForm.materialCheckbox2.Checked.ToString()}{Environment.NewLine}Cached = {Form1.CurrentForm.materialCheckbox3.Checked.ToString()}{Environment.NewLine}SMinimized = {Form1.CurrentForm.materialCheckbox4.Checked.ToString()}"); } // Read Settings @@ -52,11 +52,16 @@ public static void ReadSettings() _setting = setting.Replace("Advanced = ", ""); Form1.CurrentForm.materialCheckbox2.Checked = bool.Parse(_setting); } - if (settings.Contains("Cached = ")) // boolean + if (setting.Contains("Cached = ")) // boolean { _setting = setting.Replace("Cached = ", ""); Form1.CurrentForm.materialCheckbox3.Checked = bool.Parse(_setting); } + if (setting.Contains("SMinimized = ")) // boolean + { + _setting = setting.Replace("SMinimized = ", ""); + Form1.CurrentForm.materialCheckbox4.Checked = bool.Parse(_setting); + } } } }