Beispiel #1
0
        protected override void Run()
        {
            try
            {
                string[] args = this.Command.GetCommandLineArgs();

                bool runIpc      = false;
                bool showPrompts = true;

                Engine.Log(LogLevel.Standard, $"Arguments: {string.Join(", ", args)}");
                foreach (string arg in args)
                {
                    if (arg == "/ipc")
                    {
                        runIpc = true;
                    }
                    else if (arg == "/nomodals")
                    {
                        showPrompts = false;
                    }
                    else if (arg == "/waitforexit")
                    {
                        WaitForFilterExit = true;
                    }
                }

                BootstrapperDispatcher = Dispatcher.CurrentDispatcher;

                Application app = new Application();

                ISetupUI           setupUi = null;
                InstallerViewModel model   = new InstallerViewModel(this);

                // NOTE: This runIpc check can be removed if our current system proves itself.
                if (runIpc)
                {
                    if (server == null)
                    {
                        server = new UpdateIPCServer(UpdateIPCServer.PipeName);

                        server.MessageReceived += CheckExit;

                        server.RegisterObject("InstallerViewModel", model);

                        server.Start();
                    }

                    setupUi = new IpcWindow(server, model, showPrompts);
                    server.RegisterObject("SetupUI", setupUi);

                    server.MessageReceived += CheckStartCommand; // Wait for the first start command to begin installing.

                    setupUi.Closed += (sender, e) => SignalExit();

                    server.ClientConnected += () =>
                    {
                        Engine.Log(LogLevel.Standard, "Resynchronizing UI with new client.");
                        (setupUi as IpcWindow)?.ResynchronizeUI();
                    };

                    model.SetSetupUi(setupUi);

                    model.PropertyChanged += (sender, e) =>
                    {
                        server.PushMessage(new Message()
                        {
                            Command  = IPC.Command.PropertyChanged,
                            Property = e.PropertyName
                        });
                    };

                    this.Engine.Detect();
                }
                else
                {
                    setupUi         = new MainWindow(model, showPrompts);
                    setupUi.Closed += (sender, e) =>
                    {
                        Engine.Log(LogLevel.Standard, "Closing installer.");
                        BootstrapperDispatcher.BeginInvokeShutdown(DispatcherPriority.Normal);
                        Engine.Log(LogLevel.Standard, "Shutdown invoked.");
                    };

                    model.SetSetupUi(setupUi);

                    Engine.Detect();

                    if (Command.Display != Display.None && Command.Display != Display.Embedded)
                    {
                        setupUi.Show();
                    }

                    Dispatcher.Run();

                    this.Engine.Quit(0);
                }
            }
            catch (Exception ex)
            {
                Engine.Log(LogLevel.Error, "A .NET error occurred while running CloudVeilInstallerUI");
                Engine.Log(LogLevel.Error, $"Error Type: {ex.GetType().Name}");
                Engine.Log(LogLevel.Error, $"Error info: {ex}");

                this.Engine.Quit(1);
            }
        }
        protected override void Run()
        {
            try
            {
                sentry = SentrySdk.Init(CloudVeil.Windows.CompileSecrets.SentryDsn);
            } catch
            {
                sentry = null;
            }
            try
            {
                string[] args = this.Command.GetCommandLineArgs();

                bool runIpc      = false;
                bool showPrompts = true;

                Engine.Log(LogLevel.Standard, $"Arguments: {string.Join(", ", args)}");
                foreach (string arg in args)
                {
                    if (arg == "/ipc")
                    {
                        runIpc = true;
                    }
                    else if (arg == "/nomodals")
                    {
                        showPrompts = false;
                    }
                    else if (arg == "/waitforexit")
                    {
                        WaitForFilterExit = true;
                    }
                    else if (arg == "/upgrade")
                    {
                        Updating = true;
                    }
                    else if (arg.Contains("/userid="))
                    {
                        UserId = arg.Replace("/userid=", "");
                    }
                }

                if (Updating == false && WaitForFilterExit == true)
                {
                    Updating = true;
                }
                if (UserId.Length == 0)
                {
                    try
                    {
                        var email       = new RegistryAuthenticationStorage().UserEmail;
                        var fingerPrint = new WindowsFingerprint().Value;
                        UserId = email + ":" + fingerPrint;
                        Engine.Log(LogLevel.Standard, $"My autoset id: {UserId}");
                    }
                    catch
                    {
                        Engine.Log(LogLevel.Error, "Can't set User id, probably fresh install");
                    }
                }

                BootstrapperDispatcher = Dispatcher.CurrentDispatcher;

                Application app = new Application();

                ISetupUI           setupUi = null;
                InstallerViewModel model   = new InstallerViewModel(this);

                // NOTE: This runIpc check can be removed if our current system proves itself.
                if (runIpc)
                {
                    if (server == null)
                    {
                        server = new UpdateIPCServer(UpdateIPCServer.PipeName);

                        server.MessageReceived += CheckExit;

                        server.RegisterObject("InstallerViewModel", model);

                        server.Start();
                    }

                    setupUi = new IpcWindow(server, model, showPrompts);
                    server.RegisterObject("SetupUI", setupUi);

                    server.MessageReceived += CheckStartCommand; // Wait for the first start command to begin installing.

                    setupUi.Closed += (sender, e) => SignalExit();

                    server.ClientConnected += () =>
                    {
                        Engine.Log(LogLevel.Standard, "Resynchronizing UI with new client.");
                        (setupUi as IpcWindow)?.ResynchronizeUI();
                    };

                    model.SetSetupUi(setupUi);

                    model.PropertyChanged += (sender, e) =>
                    {
                        server.PushMessage(new Message()
                        {
                            Command  = IPC.Command.PropertyChanged,
                            Property = e.PropertyName
                        });
                    };

                    this.Engine.Detect();
                }
                else
                {
                    setupUi         = new MainWindow(model, showPrompts);
                    setupUi.Closed += (sender, e) =>
                    {
                        Engine.Log(LogLevel.Standard, "Closing installer.");
                        BootstrapperDispatcher.BeginInvokeShutdown(DispatcherPriority.Normal);
                        Engine.Log(LogLevel.Standard, "Shutdown invoked.");
                    };

                    model.SetSetupUi(setupUi);

                    Engine.Detect();

                    if (Command.Display != Display.None && Command.Display != Display.Embedded)
                    {
                        setupUi.Show();
                    }

                    Dispatcher.Run();

                    if (sentry != null)
                    {
                        sentry.Dispose();
                    }
                    this.Engine.Quit(0);
                }
            }
            catch (Exception ex)
            {
                Engine.Log(LogLevel.Error, "A .NET error occurred while running CloudVeilInstallerUI");
                Engine.Log(LogLevel.Error, $"Error Type: {ex.GetType().Name}");
                Engine.Log(LogLevel.Error, $"Error info: {ex}");

                this.Engine.Quit(1);
            }
        }