Пример #1
0
        private static void startSetup()
        {
            Logger.Log("Starting setup", Logger.LogLevel.info);
            var dia = new View.MissingDependenciesForm();

            Application.Run(dia);
        }
Пример #2
0
        private static bool handleCommandlineCommands()
        {
            var args = Environment.GetCommandLineArgs();

            if (args.Length < 2)
            {
                return(false);
            }

            if (args.Length > 2)
            {
                string temp = "";
                for (int i = 1; i < args.Length; i++)
                {
                    temp += args[i] + " ";
                }
                temp = temp.Substring(0, temp.Length - 1);
                args = new string[] { args[0], temp };
            }

            if (args[1] == "version")
            {
                Console.WriteLine(MainController.Version);
                return(true);
            }

            if (args[1] == "latest_version_info")
            {
                writeOutLatestReleaseInfo();
                return(true);
            }

            if (args[1] == "cef_version")
            {
                Console.WriteLine(CefVersion.ToString());
                return(true);
            }

            if (args[1] == "dependencies")
            {
                Console.WriteLine(getDependenciesString());
                return(true);
            }

            if (args[1] == "update_args")
            {
                Console.WriteLine(GetCmdUpdateArgs());
                return(true);
            }

            if (args[1] == "check")
            {
                OnlyCheck = true;

                try {
                    MainController.Instance.Start();
                } catch (FileNotFoundException) {
                    ExitWithError((int)Exitcode.CheckFailed, "At least one dependency is missing");
                } catch (Exception ex) {
                    ExitWithError((int)Exitcode.CheckFailed, "Unknown error occured: " + ex.Message);
                }

                Console.WriteLine("Ok");

                return(true);
            }

            if (args[1].StartsWith("cmd_install"))
            {
                if (!args[1].Contains("="))
                {
                    ExitWithError((int)Exitcode.CmdInstallFailed, "No installation path given.");
                }

                var    parts             = args[1].Split('=');
                string installPath       = parts[1];
                int    processId         = -1;
                bool   checkInstallation = true;
                bool   cleanup           = false;
                bool   onlyCopy          = false;
                bool   startAfter        = false;
                bool   showUpdateGui     = false;

                // get settings if any
                if (parts[0].Contains(","))
                {
                    var settings = parts[0].Split(',');
                    foreach (string setting in settings)
                    {
                        if (setting.StartsWith("processId:"))
                        {
                            string idStr = setting.Replace("processId:", "");
                            int.TryParse(idStr, out processId);
                        }
                        if (setting.StartsWith("dontCheck"))
                        {
                            checkInstallation = false;
                        }
                        if (setting.StartsWith("cleanup"))
                        {
                            cleanup = true;
                        }
                        if (setting.StartsWith("installedDependencies:"))
                        {
                            // check if the necessary dependencies are installed
                            var necessaryDependencies = Dependencies;
                            var installedDependencies = setting.Split(':');
                            for (int i = 1; i < installedDependencies.Length; i++)
                            {
                                string curDepency = installedDependencies[i];
                                necessaryDependencies.RemoveAll(v => v.URL.Replace(nugetBaseUrl, "") == curDepency);
                            }
                            onlyCopy = necessaryDependencies.Count == 0;
                            cleanup  = necessaryDependencies.Count > 0;
                        }
                        if (setting.StartsWith("showUpdateGui"))
                        {
                            showUpdateGui = true;
                        }
                        if (setting.StartsWith("startAfter"))
                        {
                            startAfter = true;
                        }
                    }
                }

                if (processId > -1)
                {
                    // wait for old process to finish
                    int  remainingMs  = 5000;
                    bool stillRunning = true;

                    while (remainingMs > 0)
                    {
                        try {
                            Process.GetProcessById(processId);
                        } catch (Exception) {
                            stillRunning = false;
                            break;
                        }
                        Thread.Sleep(500);
                        remainingMs -= 500;
                    }

                    if (stillRunning)
                    {
                        ExitWithError((int)Exitcode.CmdInstallFailed, "Reached waiting for process (" + processId + ") to stop after five seconds");
                    }
                }

                if (showUpdateGui && !onlyCopy)
                {
                    View.MissingDependenciesForm form = new View.MissingDependenciesForm();

                    form.IsUpdate         = true;
                    form.InstallDirectory = installPath;

                    cleanupInstallationDirectory(installPath);

                    form.ShowDialog();

                    return(true);
                }

                commandlineSetup(installPath, checkInstallation, cleanup, onlyCopy);

                if (startAfter)
                {
                    Process.Start(Path.Combine(installPath, "ScChrom.exe"));
                }

                return(true);
            }

            return(false);
        }