2
0
deadmoon 2 жил өмнө
parent
commit
45102d156e

+ 1 - 11
CONFS.md

@@ -48,17 +48,7 @@
 - ```optimizer.exe /disable=indicium,uwp,hosts```
 
 ## Reset Optimizer configuration might fix it when can't open ##
-```optimizer.exe /reset```
-
-## How to disable/enable Windows Hibernate function from command-line ##
-
-- ```optimizer.exe /disablehibernate```
-- ```optimizer.exe /enablehibernate```
-
-## How to add or delete Optimizer from Windows startup ##
-
-- ```optimizer.exe /addstartup```
-- ```optimizer.exe /deletestartup```
+```optimizer.exe /repair```
 
 ## How to disable/enable HPET (High Precision Event Timer) in order to gain a boost when gaming [use at your own risk!] ##
 

+ 1 - 1
Optimizer/Controls/MoonTabs.cs

@@ -68,7 +68,7 @@ namespace Optimizer
 
             // Send TCM_SETMINTABWIDTH
             string maxTitle = string.Empty;
-            foreach(TabPage x in this.TabPages)
+            foreach (TabPage x in this.TabPages)
             {
                 if (x.Text.Length > maxTitle.Length) maxTitle = x.Text;
             }

+ 0 - 1
Optimizer/Optimize.cs

@@ -2,7 +2,6 @@
 using System;
 using System.Diagnostics;
 using System.IO;
-using static System.Windows.Forms.VisualStyles.VisualStyleElement.Rebar;
 
 namespace Optimizer
 {

+ 1 - 0
Optimizer/Options.cs

@@ -291,6 +291,7 @@ namespace Optimizer
                 CurrentOptions = JsonConvert.DeserializeObject<SettingsJson>(File.ReadAllText(SettingsFile));
             }
 
+            // prevent options from corruption
             if (CurrentOptions.Theme == Color.Empty || CurrentOptions.Theme == Color.FromArgb(0, 0, 0, 0))
             {
                 CurrentOptions.Theme = Color.FromArgb(153, 102, 204);

+ 223 - 272
Optimizer/Program.cs

@@ -69,296 +69,227 @@ namespace Optimizer
             Application.EnableVisualStyles();
             Application.SetCompatibleTextRenderingDefault(false);
 
-            // prompt to change filename to 'Optimizer' (skip if experimental build)
-            // annoying?
+            // single-instance mechanism
+            MUTEX = new Mutex(true, MUTEX_GUID, out _notRunning);
 
-            //if (!EXPERIMENTAL_BUILD && Path.GetFileNameWithoutExtension(Assembly.GetEntryAssembly().Location) != "Optimizer")
-            //{
-            //    MessageBox.Show(string.Format(_renameAppMessage, Path.GetFileNameWithoutExtension(Assembly.GetEntryAssembly().Location)), "Optimizer", MessageBoxButtons.OK, MessageBoxIcon.Information);
-            //    Environment.Exit(0);
-            //}
+            if (!_notRunning)
+            {
+                MessageBox.Show(_alreadyRunningMsg, "Optimizer", MessageBoxButtons.OK, MessageBoxIcon.Information);
+                Environment.Exit(0);
+                return;
+            }
 
-            // single-instance mechanism
-            using (MUTEX = new Mutex(true, MUTEX_GUID, out _notRunning))
+            if (!Utilities.IsAdmin())
+            {
+                string file = Process.GetCurrentProcess().MainModule.FileName;
+                ProcessStartInfo p = new ProcessStartInfo(file);
+                p.Verb = "runas";
+                p.Arguments = string.Join(" ", switches);
+                Process.Start(p);
+                Environment.Exit(0);
+                return;
+            }
+
+            if (!Utilities.IsCompatible())
+            {
+                HelperForm f = new HelperForm(null, MessageType.Error, _unsupportedMessage);
+                f.ShowDialog();
+                Environment.Exit(0);
+                return;
+            }
+
+            Required.Deploy();
+            FontHelper.LoadFont();
+
+            if (switches.Length == 1)
             {
-                if (!_notRunning)
+                string arg = switches[0].Trim().ToLowerInvariant();
+
+                // UNSAFE mode switch (allows running on Windows Server 2008+)
+                if (arg == "/unsafe")
                 {
-                    MessageBox.Show(_alreadyRunningMsg, "Optimizer", MessageBoxButtons.OK, MessageBoxIcon.Information);
+                    UNSAFE_MODE = true;
+                    StartMainForm();
+                    return;
+                }
+
+                if (arg == "/disablehpet")
+                {
+                    Utilities.DisableHPET();
                     Environment.Exit(0);
+                    return;
                 }
-                else
+                if (arg == "/enablehpet")
+                {
+                    Utilities.EnableHPET();
+                    Environment.Exit(0);
+                    return;
+                }
+
+                // [!!!] unlock all cores instruction 
+                if (arg == "/unlockcores")
+                {
+                    Utilities.UnlockAllCores();
+                    Environment.Exit(0);
+                    return;
+                }
+
+                if (arg == "/repair")
+                {
+                    Utilities.Repair(true);
+                    return;
+                }
+
+                if (arg == "/version")
+                {
+                    if (!EXPERIMENTAL_BUILD) MessageBox.Show($"Optimizer: {GetCurrentVersionTostring()}\n\nCoded by: deadmoon © ∞\n\nhttps://github.com/hellzerg/optimizer", "Optimizer", MessageBoxButtons.OK, MessageBoxIcon.Information);
+                    else MessageBox.Show("Optimizer: EXPERIMENTAL BUILD. PLEASE DELETE AFTER TESTING.\n\nCoded by: deadmoon © ∞\n\nhttps://github.com/hellzerg/optimizer", "Optimizer", MessageBoxButtons.OK, MessageBoxIcon.Information);
+
+                    Environment.Exit(0);
+                    return;
+                }
+
+                // instruct to restart in safe-mode
+                if (arg == "/restart=safemode")
+                {
+                    RestartInSafeMode();
+                }
+
+                // instruct to restart normally
+                if (arg == "/restart=normal")
+                {
+                    RestartInNormalMode();
+                }
+
+                // disable defender automatically
+                if (arg == "/restart=disabledefender")
+                {
+                    // set RunOnce instruction
+                    Microsoft.Win32.Registry.SetValue(@"HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\RunOnce", "*OptimizerDisableDefender", Assembly.GetExecutingAssembly().Location + " /silentdisabledefender", Microsoft.Win32.RegistryValueKind.String);
+                    RestartInSafeMode();
+                }
+
+                // enable defender automatically
+                if (arg == "/restart=enabledefender")
                 {
-                    // Restart process with admin rights, preserving arguments
-                    if (!Utilities.IsAdmin())
+                    // set RunOnce instruction
+                    Microsoft.Win32.Registry.SetValue(@"HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\RunOnce", "*OptimizerEnableDefender", Assembly.GetExecutingAssembly().Location + " /silentenabledefender", Microsoft.Win32.RegistryValueKind.String);
+                    RestartInSafeMode();
+                }
+
+                // return from safe-mode automatically
+                if (arg == "/silentdisabledefender")
+                {
+                    DisableDefenderInSafeMode();
+                    RestartInNormalMode();
+                }
+
+                if (arg == "/silentenabledefender")
+                {
+                    EnableDefenderInSafeMode();
+                    RestartInNormalMode();
+                }
+
+                // disables Defender in SAFE MODE (for Windows 10 1903+ / works in Windows 11 as well)
+                if (arg == "/disabledefender")
+                {
+                    DisableDefenderInSafeMode();
+
+                    MessageBox.Show("Windows Defender has been completely disabled successfully.", "Optimizer", MessageBoxButtons.OK, MessageBoxIcon.Information);
+                    Environment.Exit(0);
+                    return;
+                }
+
+                // other options for disabling specific tools
+                if (arg.StartsWith("/disable="))
+                {
+                    string x = arg.Replace("/disable=", string.Empty);
+                    string[] opts = x.Split(',');
+
+                    bool[] codes =
                     {
-                        string file = Process.GetCurrentProcess().MainModule.FileName;
-                        ProcessStartInfo p = new ProcessStartInfo(file);
-                        p.Verb = "runas";
-                        p.Arguments = string.Join(" ", switches);
-                        Process.Start(p);
+                        opts.Contains("indicium"),
+                        opts.Contains("uwp"),
+                        opts.Contains("apps"),
+                        opts.Contains("hosts"),
+                        opts.Contains("startup"),
+                        opts.Contains("cleaner"),
+                        opts.Contains("integrator"),
+                        opts.Contains("pinger")
+                    };
+
+                    StartMainForm(codes);
+                    return;
+                }
+
+                if (arg.StartsWith("/config="))
+                {
+                    string fileName = arg.Replace("/config=", string.Empty);
+
+                    if (!File.Exists(fileName))
+                    {
+                        MessageBox.Show(_confNotFoundMsg, "Optimizer", MessageBoxButtons.OK, MessageBoxIcon.Information);
+                        Environment.Exit(0);
+                        return;
+                    }
 
+                    SilentOps.GetSilentConfig(fileName);
+                    if (SilentOps.CurrentSilentConfig == null)
+                    {
+                        MessageBox.Show(_confInvalidFormatMsg, "Optimizer", MessageBoxButtons.OK, MessageBoxIcon.Information);
                         Environment.Exit(0);
+                        return;
+                    }
+
+                    if (SilentOps.CurrentSilentConfig.WindowsVersion == 7 && Utilities.CurrentWindowsVersion == WindowsVersion.Windows7)
+                    {
+                        LoadSettings();
+                        SilentOps.ProcessSilentConfigGeneral();
+                        SilentOps.SilentUpdateOptionsGeneral();
+                        Options.SaveSettings();
+                    }
+                    else if (SilentOps.CurrentSilentConfig.WindowsVersion == 8 && Utilities.CurrentWindowsVersion == WindowsVersion.Windows8)
+                    {
+                        LoadSettings();
+                        SilentOps.ProcessSilentConfigGeneral();
+                        SilentOps.ProcessSilentConfigWindows8();
+                        SilentOps.SilentUpdateOptionsGeneral();
+                        SilentOps.SilentUpdateOptions8();
+                        Options.SaveSettings();
+                    }
+                    else if (SilentOps.CurrentSilentConfig.WindowsVersion == 10 && Utilities.CurrentWindowsVersion == WindowsVersion.Windows10)
+                    {
+                        LoadSettings();
+                        SilentOps.ProcessSilentConfigGeneral();
+                        SilentOps.ProcessSilentConfigWindows10();
+                        SilentOps.SilentUpdateOptionsGeneral();
+                        SilentOps.SilentUpdateOptions10();
+                        Options.SaveSettings();
+                    }
+                    else if (SilentOps.CurrentSilentConfig.WindowsVersion == 11 && Utilities.CurrentWindowsVersion == WindowsVersion.Windows11)
+                    {
+                        LoadSettings();
+                        SilentOps.ProcessSilentConfigGeneral();
+                        SilentOps.ProcessSilentConfigWindows10();
+                        SilentOps.ProcessSilentConfigWindows11();
+                        SilentOps.SilentUpdateOptionsGeneral();
+                        SilentOps.SilentUpdateOptions10();
+                        SilentOps.SilentUpdateOptions11();
+                        Options.SaveSettings();
                     }
                     else
                     {
-                        if (Utilities.IsCompatible())
-                        {
-                            Required.Deploy();
-
-                            FontHelper.LoadFont();
-
-                            for (int z = 0; z < switches.Length; z++) switches[z] = switches[z].ToLowerInvariant();
-
-                            // checking for silent config argument
-                            if (switches.Length == 1)
-                            {
-                                string arg = switches[0].Trim();
-
-                                // UNSAFE mode switch (allows running on Windows Server 2008+)
-                                if (arg == "/unsafe")
-                                {
-                                    UNSAFE_MODE = true;
-
-                                    LoadSettings();
-                                    StartSplashForm();
-
-                                    _MainForm = new MainForm(_SplashForm);
-                                    _MainForm.Load += MainForm_Load;
-                                    Application.Run(_MainForm);
-
-                                    return;
-                                }
-
-                                if (arg == "/disablehpet")
-                                {
-                                    Utilities.DisableHPET();
-                                    Environment.Exit(0);
-                                }
-                                if (arg == "/enablehpet")
-                                {
-                                    Utilities.EnableHPET();
-                                    Environment.Exit(0);
-                                }
-
-                                if (arg == "/addstartup")
-                                {
-                                    Utilities.RegisterAutoStart();
-                                    Environment.Exit(0);
-                                }
-
-                                if (arg == "/deletestartup")
-                                {
-                                    Utilities.UnregisterAutoStart();
-                                    Environment.Exit(0);
-                                }
-
-                                // [!!!] unlock all cores instruction 
-                                if (arg == "/unlockcores")
-                                {
-                                    Utilities.UnlockAllCores();
-                                    Environment.Exit(0);
-                                }
-
-                                // repairs corrupted configuration
-                                if (arg == "/reset")
-                                {
-                                    Utilities.Repair(true);
-                                    return;
-                                }
-
-                                // displays build info
-                                if (arg == "/version")
-                                {
-                                    if (!EXPERIMENTAL_BUILD) MessageBox.Show($"Optimizer: {GetCurrentVersionTostring()}\n\nCoded by: deadmoon © ∞\n\nhttps://github.com/hellzerg/optimizer", "Optimizer", MessageBoxButtons.OK, MessageBoxIcon.Information);
-                                    else MessageBox.Show("Optimizer: EXPERIMENTAL BUILD. PLEASE DELETE AFTER TESTING.\n\nCoded by: deadmoon © ∞\n\nhttps://github.com/hellzerg/optimizer", "Optimizer", MessageBoxButtons.OK, MessageBoxIcon.Information);
-
-                                    Environment.Exit(0);
-                                }
-
-                                // hibernation switches
-                                if (arg == "/disablehibernate")
-                                {
-                                    Utilities.DisableHibernation();
-                                    Environment.Exit(0);
-                                }
-                                if (arg == "/enablehibernate")
-                                {
-                                    Utilities.EnableHibernation();
-                                    Environment.Exit(0);
-                                }
-
-                                // instruct to restart in safe-mode
-                                if (arg == "/restart=safemode")
-                                {
-                                    RestartInSafeMode();
-                                }
-
-                                // instruct to restart normally
-                                if (arg == "/restart=normal")
-                                {
-                                    RestartInNormalMode();
-                                }
-
-                                // disable defender automatically
-                                if (arg == "/restart=disabledefender")
-                                {
-                                    // set RunOnce instruction
-                                    Microsoft.Win32.Registry.SetValue(@"HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\RunOnce", "*OptimizerDisableDefender", Assembly.GetExecutingAssembly().Location + " /silentdisabledefender", Microsoft.Win32.RegistryValueKind.String);
-                                    RestartInSafeMode();
-                                }
-
-                                // enable defender automatically
-                                if (arg == "/restart=enabledefender")
-                                {
-                                    // set RunOnce instruction
-                                    Microsoft.Win32.Registry.SetValue(@"HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\RunOnce", "*OptimizerEnableDefender", Assembly.GetExecutingAssembly().Location + " /silentenabledefender", Microsoft.Win32.RegistryValueKind.String);
-                                    RestartInSafeMode();
-                                }
-
-                                // return from safe-mode automatically
-                                if (arg == "/silentdisabledefender")
-                                {
-                                    DisableDefenderInSafeMode();
-                                    RestartInNormalMode();
-                                }
-
-                                if (arg == "/silentenabledefender")
-                                {
-                                    EnableDefenderInSafeMode();
-                                    RestartInNormalMode();
-                                }
-
-                                // other options for disabling specific tools
-                                if (arg.StartsWith("/disable="))
-                                {
-                                    string x = arg.Replace("/disable=", string.Empty);
-                                    string[] opts = x.Split(',');
-
-                                    bool disableIndicium = opts.Contains("indicium");
-                                    bool disableUWPTool = opts.Contains("uwp");
-                                    bool disableAppsTool = opts.Contains("apps");
-                                    bool disableHostsEditor = opts.Contains("hosts");
-                                    bool disableStartupTool = opts.Contains("startup");
-                                    bool disableCleaner = opts.Contains("cleaner");
-                                    bool disableIntegrator = opts.Contains("integrator");
-                                    bool disablePinger = opts.Contains("pinger");
-
-                                    LoadSettings();
-                                    StartSplashForm();
-
-                                    _MainForm = new MainForm(_SplashForm, disableIndicium, disableHostsEditor, disableAppsTool, disableUWPTool, disableStartupTool, disableCleaner, disableIntegrator, disablePinger);
-                                    _MainForm.Load += MainForm_Load;
-                                    Application.Run(_MainForm);
-
-                                    return;
-                                }
-
-                                // disables Defender in SAFE MODE (for Windows 10 1903+ / works in Windows 11 as well)
-                                if (arg == "/disabledefender")
-                                {
-                                    DisableDefenderInSafeMode();
-
-                                    MessageBox.Show("Windows Defender has been completely disabled successfully.", "Optimizer", MessageBoxButtons.OK, MessageBoxIcon.Information);
-                                    Environment.Exit(0);
-                                    return;
-                                }
-
-                                if (arg.StartsWith("/"))
-                                {
-                                    if (File.Exists(arg.Remove(0, 1)))
-                                    {
-                                        SilentOps.GetSilentConfig(arg.Remove(0, 1));
-
-                                        if (SilentOps.CurrentSilentConfig != null)
-                                        { 
-                                            if (SilentOps.CurrentSilentConfig.WindowsVersion == 7 && Utilities.CurrentWindowsVersion == WindowsVersion.Windows7)
-                                            {
-                                                LoadSettings();
-                                                SilentOps.ProcessSilentConfigGeneral();
-                                                SilentOps.SilentUpdateOptionsGeneral();
-                                                Options.SaveSettings();
-                                            }
-                                            else if (SilentOps.CurrentSilentConfig.WindowsVersion == 8 && Utilities.CurrentWindowsVersion == WindowsVersion.Windows8)
-                                            {
-                                                LoadSettings();
-                                                SilentOps.ProcessSilentConfigGeneral();
-                                                SilentOps.ProcessSilentConfigWindows8();
-                                                SilentOps.SilentUpdateOptionsGeneral();
-                                                SilentOps.SilentUpdateOptions8();
-                                                Options.SaveSettings();
-                                            }
-                                            else if (SilentOps.CurrentSilentConfig.WindowsVersion == 10 && Utilities.CurrentWindowsVersion == WindowsVersion.Windows10)
-                                            {
-                                                LoadSettings();
-                                                SilentOps.ProcessSilentConfigGeneral();
-                                                SilentOps.ProcessSilentConfigWindows10();
-                                                SilentOps.SilentUpdateOptionsGeneral();
-                                                SilentOps.SilentUpdateOptions10();
-                                                Options.SaveSettings();
-                                            }
-                                            else if (SilentOps.CurrentSilentConfig.WindowsVersion == 11 && Utilities.CurrentWindowsVersion == WindowsVersion.Windows11)
-                                            {
-                                                LoadSettings();
-                                                SilentOps.ProcessSilentConfigGeneral();
-                                                SilentOps.ProcessSilentConfigWindows10();
-                                                SilentOps.ProcessSilentConfigWindows11();
-                                                SilentOps.SilentUpdateOptionsGeneral();
-                                                SilentOps.SilentUpdateOptions10();
-                                                SilentOps.SilentUpdateOptions11();
-                                                Options.SaveSettings();
-                                            }
-                                            else
-                                            {
-                                                MessageBox.Show(_confInvalidVersionMsg, "Optimizer", MessageBoxButtons.OK, MessageBoxIcon.Information);
-                                                Environment.Exit(0);
-                                            }
-                                        }
-                                        else
-                                        {
-                                            MessageBox.Show(_confInvalidFormatMsg, "Optimizer", MessageBoxButtons.OK, MessageBoxIcon.Information);
-                                            Environment.Exit(0);
-                                        }
-                                    }
-                                    else
-                                    {
-                                        MessageBox.Show(_confNotFoundMsg, "Optimizer", MessageBoxButtons.OK, MessageBoxIcon.Information);
-                                        Environment.Exit(0);
-                                    }
-                                }
-                                else
-                                {
-                                    MessageBox.Show(_argInvalidMsg, "Optimizer", MessageBoxButtons.OK, MessageBoxIcon.Information);
-                                    Environment.Exit(0);
-                                }
-                            }
-                            else
-                            {
-                                LoadSettings();
-                                StartSplashForm();
-
-                                _MainForm = new MainForm(_SplashForm);
-                                _MainForm.Load += MainForm_Load;
-
-                                Application.Run(_MainForm);
-                            }
-                        }
-                        else
-                        {
-                            HelperForm f = new HelperForm(null, MessageType.Error, _unsupportedMessage);
-                            f.ShowDialog();
-
-                            Environment.Exit(0);
-                        }
+                        MessageBox.Show(_confInvalidVersionMsg, "Optimizer", MessageBoxButtons.OK, MessageBoxIcon.Information);
+                        Environment.Exit(0);
                     }
                 }
             }
+            else
+            {
+                StartMainForm();
+            }
         }
 
-        //internal static void ForceExit()
-        //{
-        //    Environment.Exit(0);
-        //}
-
         private static void LoadSettings()
         {
             // for backward compatibility (legacy)
@@ -437,6 +368,26 @@ namespace Optimizer
             File.Delete("EnableDefenderSafeMode.bat");
         }
 
+        private static void StartMainForm()
+        {
+            LoadSettings();
+            StartSplashForm();
+
+            _MainForm = new MainForm(_SplashForm);
+            _MainForm.Load += MainForm_Load;
+            Application.Run(_MainForm);
+        }
+
+        private static void StartMainForm(bool[] codes)
+        {
+            LoadSettings();
+            StartSplashForm();
+
+            _MainForm = new MainForm(_SplashForm, codes[0], codes[1], codes[2], codes[3], codes[4], codes[5], codes[6], codes[7]);
+            _MainForm.Load += MainForm_Load;
+            Application.Run(_MainForm);
+        }
+
         private static void StartSplashForm()
         {
             _SplashForm = new SplashForm();

+ 1 - 1
Optimizer/Resources/i18n/EL.json

@@ -68,7 +68,7 @@
 	"insiderSw": "Απενεργοποίηση Υπηρεσίας Insider",
 	"actionSw": "Απενεργοποίηση Κέντρου Ενημερώσεων",
 	"disableOneDriveSw": "Απενεργοποίηση OneDrive",
-	"tpmSw": "Απενεργοποίηση Ελέγχου TPM 2.0",
+	"tpmSw": "Απενεργοποίηση Ελέγχου TPM",
 	"leftTaskbarSw": "Ευθυγράμμιση Γραμμης Εργασιών Αριστερά",
 	"snapAssistSw": "Απενεργοποίηση του Snap Assist",
 	"widgetsSw": "Απενεργοποίηση των Widgets",

+ 1 - 1
Optimizer/Resources/i18n/EN.json

@@ -66,7 +66,7 @@
 	"insiderSw": "Disable Insider Service",
 	"actionSw": "Disable Notification Center",
 	"disableOneDriveSw": "Disable OneDrive",
-	"tpmSw": "Disable TPM 2.0 Check",
+	"tpmSw": "Disable TPM Check",
 	"leftTaskbarSw": "Align Taskbar to Left",
 	"snapAssistSw": "Disable Snap Assist",
 	"widgetsSw": "Disable Widgets",