コード例 #1
0
        private void buttonApply_Click(object sender, EventArgs e)
        {
            SaveConfig();
            buttonApply.Enabled = false;

            if (Configuration.Enabled)
            {
                ExplorerPatcher.Configuration.ConfigurationApplying = true;
                ClassicTheme.MasterDisable(Configuration.EnableTaskbar);
                ExplorerPatcher.ApplyConfiguration(true);
                ClassicTheme.MasterEnable(Configuration.EnableTaskbar);
                ExplorerPatcher.Configuration.ConfigurationApplying = false;
            }
            else
            {
                ExplorerPatcher.ApplyConfiguration(true);
            }
        }
コード例 #2
0
        /// <summary>
        /// Performs the complete installation of SCT based on the user's options and reports back progress when needed.
        /// </summary>
        /// <param name="progressDisplay"></param>
        public static void InstallSCT(InstallationPage progressDisplay)
        {
            if (SelectedTaskbarType == TaskbarType.SimpleClassicThemeTaskbar && !ExtraFunctions.IsDotNetRuntimeInstalled())
            {
                progressDisplay.progressWorker.ReportProgress(5);
                progressDisplay.Invoke(new Action(() =>
                {
                    progressDisplay.SetProgressBarColor(2);
                    MessageBox.Show(progressDisplay.ParentForm, "Simple Classic Theme Taskbar requires the .NET Desktop Runtime. Install the .NET Desktop Runtime and run this wizard again.", "Cannot install SCT Taskbar");
                    Process.Start("https://dotnet.microsoft.com/download/dotnet/5.0/runtime");
                    ErrorWizard(progressDisplay);
                }));
                return;
            }

            // Move any existing SCT stuff to Configuration.InstallPath
            if (Configuration.InstallPath != InstallPath)
            {
                progressDisplay.progressText = "Moving SCT files to installation directory...";
                progressDisplay.progressWorker.ReportProgress(0);
                ExtraFunctions.DirectoryCopy(Configuration.InstallPath, InstallPath, true);
                Directory.Delete(Configuration.InstallPath, true);
                Configuration.InstallPath = InstallPath;
            }

            // Install SCT to Configuration.InstallPath
            // Create a task for SCT
            progressDisplay.progressText = "Installing Simple Classic Theme...";
            progressDisplay.progressWorker.ReportProgress(0);
            ExtraFunctions.UpdateStartupExecutable(true);

            // Go through all extra utilities and install them
            float temp = 10;

            foreach (InstallableUtility utility in UtilitiesToBeInstalled)
            {
                if (utility.Name != "Open-Shell" && utility.Name != "StartIsBack++")
                {
                    progressDisplay.progressText = "Installing " + utility.Name + "...";
                    progressDisplay.progressWorker.ReportProgress((int)temp);
                    temp += 10F / UtilitiesToBeInstalled.Count;
                    int returnCode = utility.Install();
                    if (returnCode != 0)
                    {
                        progressDisplay.Invoke(new Action(() =>
                        {
                            progressDisplay.SetProgressBarColor(2);
                            MessageBox.Show(progressDisplay.ParentForm, $"Could not install {utility.Name}. Installer returned code {returnCode}.", "Installation failed");
                            ErrorWizard(progressDisplay);
                        }));
                        return;
                    }
                }
            }

            // Configure StartIsBack++ if OS+SiB
            if (ConfigureSiB)
            {
                progressDisplay.progressText = "Configuring StartIsBack++ before installing...";
                progressDisplay.progressWorker.ReportProgress(20);

                ExtraFunctions.ReConfigureOS(false, false, true);
            }

            // Configure Open-Shell Start Menu if OS+SiB or for manual selection
            if (ConfigureOSSM)
            {
                progressDisplay.progressText = "Configuring Open-Shell Menu's Start Menu before installing...";
                progressDisplay.progressWorker.ReportProgress(30);

                ExtraFunctions.ReConfigureOS(true, false, false);
            }

            // Configure Open-Shell Taskbar if OS+SiB or for manual selection
            if (ConfigureOSTB)
            {
                progressDisplay.progressText = "Configuring Open-Shell Menu's Taskbar before installing...";
                progressDisplay.progressWorker.ReportProgress(40);

                ExtraFunctions.ReConfigureOS(false, true, false);
            }

            // Install StartIsBack++ if OS+SiB or for manual selection
            if (UtilitiesToBeInstalled.Where((a) => a.Name == "StartIsBack++").Count() > 0)
            {
                progressDisplay.progressText = "Installing StartIsBack++...";
                progressDisplay.progressWorker.ReportProgress(50);
                int returnCode = InstallableUtility.StartIsBackPlusPlus.Install();
                if (returnCode != 0)
                {
                    progressDisplay.Invoke(new Action(() =>
                    {
                        progressDisplay.SetProgressBarColor(2);
                        MessageBox.Show(progressDisplay.ParentForm, $"Could not install StartIsBack++. Installer returned code {returnCode}.", "Installation failed");
                        ErrorWizard(progressDisplay);
                    }));
                    return;
                }
            }

            // Install Open-Shell if OS+SiB or for manual selection
            if (UtilitiesToBeInstalled.Where((a) => a.Name == "Open-Shell").Count() > 0)
            {
                progressDisplay.progressText = "Installing Open-Shell...";
                progressDisplay.progressWorker.ReportProgress(60);
                int returnCode = InstallableUtility.OpenShell.Install();
                if (returnCode != 0)
                {
                    progressDisplay.Invoke(new Action(() =>
                    {
                        progressDisplay.SetProgressBarColor(2);
                        MessageBox.Show(progressDisplay.ParentForm, $"Could not install Open-Shell. Installer returned code {returnCode}.", "Installation failed");
                        ErrorWizard(progressDisplay);
                    }));
                    return;
                }
            }

            // Install SCT Taskbar
            if (SelectedTaskbarType == TaskbarType.SimpleClassicThemeTaskbar)
            {
                progressDisplay.progressText = "Installing Simple Classic Theme Taskbar...";
                progressDisplay.progressWorker.ReportProgress(70);
                progressDisplay.Invoke(new Action(() => new GithubDownloader(GithubDownloader.DownloadableGithubProject.SimpleClassicThemeTaskbar).ShowDialog()));
            }

            // Install RetroBar
            else if (SelectedTaskbarType == TaskbarType.RetroBar)
            {
                progressDisplay.progressText = "Installing RetroBar...";
                progressDisplay.progressWorker.ReportProgress(70);
                progressDisplay.Invoke(new Action(() => new GithubDownloader(GithubDownloader.DownloadableGithubProject.RetroBar).ShowDialog()));
            }

            // Configure SCT
            progressDisplay.progressText = "Configuring Simple Classic Theme...";
            progressDisplay.progressWorker.ReportProgress(80);
            Configuration.EnableTaskbar = SelectedTaskbarType != TaskbarType.None;
            Configuration.TaskbarType   = SelectedTaskbarType != TaskbarType.None ? SelectedTaskbarType : TaskbarType.SimpleClassicThemeTaskbar;
            Configuration.UpdateMode    = "Automatic";

            // Finalize installation and record data for uninstall
            progressDisplay.progressText = "Finalizing installation and enabling Classic Theme...";
            progressDisplay.progressWorker.ReportProgress(90);

            // Sleep for dramatic installation effect
            ClassicTheme.MasterEnable(SelectedTaskbarType != TaskbarType.None);
            System.Threading.Thread.Sleep(1200);
            progressDisplay.progressWorker.ReportProgress(100);
        }
コード例 #3
0
        public bool LoadSCT(string[] args)
        {
            Configuration.MigrateOldSCTRegistry();
            Application.VisualStyleState = Configuration.Enabled ? VisualStyleState.NoneEnabled : VisualStyleState.ClientAndNonClientAreasEnabled;

            //If it's the first time running SCT, start the wizard.
            if (args.Length == 0 && Configuration.ShowWizard && MessageBox.Show("It seems to be the first time you are running SCT.\nWould you like to run the automated setup tool?", "First run", MessageBoxButtons.YesNo) == DialogResult.Yes)
            {
                SetupWizard.SetupHandler.ShowWizard(SetupWizard.SetupHandler.CreateWizard());
            }
            else
            {
                Configuration.ShowWizard = false;
            }

            Directory.CreateDirectory(Configuration.InstallPath);

            // Small delay for pressing Details button
            label2.Text = "Status: ";
            DateTime time = DateTime.Now;

            while (DateTime.Now.Subtract(time).TotalSeconds < 0.8)
            {
                Application.DoEvents();
            }
            button1.Hide();

            label2.Text = "Status: Writing load scripts";
            Application.DoEvents();

            //Write loading scripts
            if (!File.Exists($"{Configuration.InstallPath}EnableThemeScript.bat"))
            {
                File.WriteAllText($"{Configuration.InstallPath}EnableThemeScript.bat", Properties.Resources.EnableThemeScript.Replace("{ver}", Assembly.GetExecutingAssembly().GetName().Version.ToString()));
            }
            if (!File.Exists($"{Configuration.InstallPath}DisableThemeScript.bat"))
            {
                File.WriteAllText($"{Configuration.InstallPath}DisableThemeScript.bat", Properties.Resources.DisableThemeScript.Replace("{ver}", Assembly.GetExecutingAssembly().GetName().Version.ToString()));
            }

            label2.Text = "Status: Checking for updates";
            Application.DoEvents();

            //Start update checking
            string updateMode = Configuration.UpdateMode;

            if (updateMode == "Automatic" || updateMode == "Ask on startup")
            {
                if (ExtraFunctions.Update(this))
                {
                    return(false);
                }
            }

            label2.Text = "Status: Cleaning up files";
            Application.DoEvents();

            //Clean up any files that might have been left over on the root of the C: drive
            File.Delete("C:\\upm.reg");
            File.Delete("C:\\restoreMetrics.reg");
            File.Delete("C:\\fox.exe");
            File.Delete("C:\\7tt.exe");
            File.Delete("C:\\ctm.exe");
            File.Delete("C:\\ossettings.reg");
            File.Delete("C:\\sib.reg");
            File.Delete("C:\\sib.exe");
            File.Delete("C:\\windowmetrics.reg");
            File.Delete("C:\\RibbonDisabler.exe");

            Application.DoEvents();
            if (args.Length > 0)
            {
                /*// Free the console if by any chance we are still attached to one.
                 * Kernel32.FreeConsole();
                 *
                 * // Allocate a console so we can output information.
                 * // TODO: Create a custom screen that will replace the console and display the status in a 'Classic' GUI way
                 * Kernel32.AllocConsole();
                 *
                 * // Show copyright header
                 * WriteLine("Simple Classic Theme {0}\r\n(C) 2021 LeetFTW\r\n", Assembly.GetExecutingAssembly().GetName().Version);
                 */

                // Parse arguments
                List <(string, object[])> arguments = new List <(string, object[])>();
                for (int i = 0; i < args.Length; i++)
                {
                    label2.Text = $"Status: Parsing arguments ({i}/{args.Length})";
                    Application.DoEvents();

                    string parseableArgument;
                    if (args[i].StartsWith("/"))
                    {
                        parseableArgument = "--" + args[i].Substring(1);
                    }
                    else
                    {
                        parseableArgument = args[i];
                    }
                    switch (parseableArgument)
                    {
                    case "--verbose":
                    case "-v":
                        button1_Click(null, null);
                        break;

                    case "--boot":
                        if (args.Length > 1)
                        {
                            WriteLine("Warning: Any arguments beside --boot will be ignored");
                        }
                        arguments.Clear();
                        arguments.Add(("--boot", null));
                        goto execute_arguments;

                    case "--configure":
                    case "-c":
                        arguments.Add(("--configure", null));
                        break;

                    case "--enable":
                    case "-e":
                        arguments.Add(("--enable", null));
                        break;

                    case "--disable":
                    case "-d":
                        arguments.Add(("--disable", null));
                        break;

                    case "--install-dependencies":
                    case "-r":
                        arguments.Add(("--install-dependencies", null));
                        break;

                    case "--install":
                    case "-i":
                        arguments.Add(("--install", null));
                        break;

                    case "--set":
                    case "-s":
                        if (args.Length - 3 >= i)
                        {
                            List <string> possibleSettingNames = new[] { "EnableTaskbar", "TaskbarDelay", "UpdateMode", "TaskbarType" }.ToList();
                            string[]      possibleSettingTypes = { "Boolean", "Int32", "String", "String" };
                            if (possibleSettingNames.Contains(args[i + 1]))
                            {
                                switch (possibleSettingTypes[possibleSettingNames.IndexOf(args[i + 1])])
                                {
                                case "Boolean":
                                    if (Boolean.TryParse(args[i + 2], out bool boolean))
                                    {
                                        arguments.Add(("--set", new object[] { args[i + 1], boolean.ToString(), RegistryValueKind.String }));
                                    }
                                    else
                                    {
                                        WriteLine($"Error: Could not parse '{args[i + 2]}' to type System.Boolean");
                                        goto exit;
                                    }
                                    break;

                                case "Int32":
                                    if (Int32.TryParse(args[i + 2], out int int32))
                                    {
                                        arguments.Add(("--set", new object[] { args[i + 1], int32, RegistryValueKind.DWord }));
                                    }
                                    else
                                    {
                                        WriteLine($"Error: Could not parse '{args[i + 2]}' to type System.Int32");
                                        goto exit;
                                    }
                                    break;

                                case "String":
                                    arguments.Add(("--set", new object[] { args[i + 1], args[i + 2], RegistryValueKind.String }));
                                    break;
                                }
                            }
                            else
                            {
                                WriteLine($"Error: Invalid setting name '{args[i + 1]}'\r\nPossible values: {1}");
                                goto exit;
                            }
                        }
                        else
                        {
                            WriteLine($"Error: Insufficient information supplied for argument {args[i]}");
                            goto exit;
                        }
                        i += 2;
                        break;

                    case "--gui":
                    case "-g":
                        arguments.Add(("--gui", null));
                        if (i < args.Length - 1)
                        {
                            WriteLine($"Warning: Arguments after {args[i]} will be ingnored\r\nIgnored arguments: {string.Join(", ", args.Skip(i + 1))}");
                        }
                        goto execute_arguments;

                    default:
                        WriteLine("Error: Invalid argument '{args[i]}'");
                        goto case "/?";

                    case "--help":
                    case "-h":
                    case "/help":
                    case "/h":
                    case "/?":
                        arguments.Clear();
                        arguments.Add(("--help", null));
                        goto execute_arguments;

                    case "--wizard":
                    case "-w":
                        arguments.Add(("--wizard", null));
                        break;
                    }
                }
execute_arguments:
                WriteLine($"Succesfully parsed {arguments.Count} argument{(arguments.Count > 1 ? "s" : "")}");
                bool enableTaskbar = Configuration.EnableTaskbar;
                for (int i = 0; i < arguments.Count; i++)
                {
                    label2.Text = $"Status: Parsing arguments ({i}/{args.Length})";
                    Application.DoEvents();

                    (string, object[])argument = arguments[i];
                    string selector = argument.Item1;
run_argument:
                    WriteLine("");
                    switch (selector)
                    {
                    case "--boot":
                        WriteLine("Simple Classic Theme is restoring Classic Theme settings");
                        bool Enabled = Configuration.Enabled;
                        if (Directory.Exists($"{Configuration.InstallPath}AHK"))
                        {
                            foreach (string f in Directory.EnumerateFiles($"{Configuration.InstallPath}AHK"))
                            {
                                Process.Start(f);
                            }
                        }
                        if (Enabled)
                        {
                            selector = "--enable";
                            goto run_argument;
                        }
                        break;

                    case "--configure":
                        File.WriteAllBytes($"{Configuration.InstallPath}deskn.cpl", Properties.Resources.desktopControlPanelCPL);
                        Process.Start($"{Configuration.InstallPath}deskn.cpl");
                        WriteLine("Launched Clasic Theme configuration dialog");
                        break;

                    case "--disable":
                        if (!MainForm.CheckDependencies(enableTaskbar))
                        {
                            WriteLine("Error: Not all dependencies are installed\r\nPlease use the GUI or --install-dependencies to install the dependencies");
                            goto exit;
                        }
                        Write($"Disabling classic theme{(enableTaskbar ? " and taskbar" : "")}...");
                        ClassicTheme.MasterDisable(enableTaskbar); WriteLine("");
                        WriteLine("Disabled SCT succesfully");
                        break;

                    case "--enable":
                        if (!MainForm.CheckDependencies(enableTaskbar))
                        {
                            WriteLine("Error: Not all dependencies are installed\r\nPlease use the GUI or --install-dependencies to install the dependencies");
                            goto exit;
                        }
                        Write($"Enabling classic theme{(enableTaskbar ? " and taskbar" : "")}...");
                        ClassicTheme.MasterEnable(enableTaskbar, true); WriteLine("");
                        WriteLine("Enabled SCT succesfully");
                        break;

                    case "--gui":
                        WriteLine("Starting GUI interface");
                        goto run_gui;

                    case "--help":
                        new CommandLineHelpForm().ShowDialog(this);
                        goto exit;

                    case "--install":
                        ExtraFunctions.UpdateStartupExecutable(true);
                        WriteLine("Installed SCT succesfully");
                        break;

                    case "--install-dependencies":
                        if (!ExtraFunctions.InstallDependencies())
                        {
                            goto exit;
                        }
                        break;

                    case "--set":
                        if ((string)argument.Item2[0] == "EnableTaskbar")
                        {
                            enableTaskbar = Boolean.Parse((string)argument.Item2[1]);
                        }
                        Configuration.SetItemManually((string)argument.Item2[0], argument.Item2[1], (RegistryValueKind)argument.Item2[2]);
                        WriteLine($"Set configuration item '{argument.Item2[0]}' to '{argument.Item2[1]}'");
                        break;

                    case "--wizard":
                        WriteLine("Running SCT wizard... (Note that this console will stay open)");
                        SetupWizard.SetupHandler.ShowWizard(SetupWizard.SetupHandler.CreateWizard());
                        WriteLine("SCT Wizard finished");
                        break;
                    }
                }
                Kernel32.FreeConsole();
                if (ControlBox)
                {
                    goto exit;
                }
                return(false);

exit:
                Kernel32.FreeConsole();
                button1_Click(null, null);
                Application.Run(this);
                return(false);
            }

run_gui:
            return(true);
        }