Пример #1
0
        public Installer(string filename)
        {
            try {
                MsiFilename = filename;
                Quiet       = ((AppDomain.CurrentDomain.GetData("QUIET") as string) ?? "false").IsTrue();
                Passive     = ((AppDomain.CurrentDomain.GetData("PASSIVE") as string) ?? "false").IsTrue();
                Remove      = ((AppDomain.CurrentDomain.GetData("REMOVE") as string) ?? "false").IsTrue();

                Logger.Message("Quiet {0}/Passive {1}/Remove {2}", Quiet, Passive, Remove);

                // was coapp just installed by the bootstrapper?
                var tsk = Task.Factory.StartNew(() => {
                    if (((AppDomain.CurrentDomain.GetData("COAPP_INSTALLED") as string) ?? "false").IsTrue())
                    {
                        // we'd better make sure that the most recent version of the service is running.
                        EngineServiceManager.InstallAndStartService();
                        EnvironmentUtility.BroadcastChange();
                    }
                    bool wasCreated;
                    var ewhSec = new EventWaitHandleSecurity();
                    ewhSec.AddAccessRule(new EventWaitHandleAccessRule(new SecurityIdentifier(WellKnownSidType.WorldSid, null), EventWaitHandleRights.FullControl, AccessControlType.Allow));
                    _ping = new EventWaitHandle(false, EventResetMode.ManualReset, "BootstrapperPing", out wasCreated, ewhSec);
                });

                // force the explorer process to pick up changes to the environment.
                EnvironmentUtility.BroadcastChange();

                var ts2 = tsk.Continue(() => {
                    // gets the package data for the likely suspects.
                    _packageManager.AddSessionFeed(Path.GetDirectoryName(Path.GetFullPath(MsiFilename))).Continue(() => {
                        _packageManager.GetPackageFromFile(Path.GetFullPath(MsiFilename)).Continue(pkg =>
                                                                                                   Task.WaitAll(new[] { pkg.InstalledNewest, pkg.AvailableNewestUpdate, pkg.AvailableNewestUpgrade }
                                                                                                                .Select(each => each != null ? _packageManager.GetPackage(each.CanonicalName, true)
                                                                                                                        .Continue(() => { _packageManager.GetPackageDetails(each.CanonicalName); })
                                : "".AsResultTask())
                                                                                                                .UnionSingleItem(_packageManager.GetPackageDetails(pkg).Continue(() => { PrimaryPackage = pkg; }))
                                                                                                                .ToArray()));
                    });
                });

                tsk.ContinueOnFail(error => {
                    DoError(InstallerFailureState.FailedToGetPackageFromFile, error);
                    ExitQuick();
                });

                try {
                    Application.ResourceAssembly = Assembly.GetExecutingAssembly();
                } catch {
                }

                ts2.Wait();

                if (!Quiet)
                {
                    _window = new InstallerMainWindow(this);
                    if (Remove)
                    {
                        _window.Loaded += (sender, args) => _window.RemoveButtonClick(sender, args);
                    }
                    else if (Passive)
                    {
                        _window.Loaded += (sender, args) => _window.InstallButtonClick(sender, args);
                    }

                    _window.ShowDialog();

                    if (Application.Current != null)
                    {
                        Application.Current.Shutdown(0);
                    }
                }
                else
                {
                    // when quiet
                    var discard  = RemoveChoices.ToArray();
                    var discard2 = InstallChoices.ToArray();

                    if (Remove)
                    {
                        if (CanRemove)
                        {
                            RemoveAll().Wait();
                        }
                    }
                    else
                    {
                        Logger.Message("Thinkin' about installin' {0}", CanInstall);
                        Debugger.Break();
                        if (CanInstall)
                        {
                            Install().Wait();
                        }
                    }
                }
                ExitQuick();
            }
            catch (Exception e) {
                DoError(InstallerFailureState.FailedToGetPackageDetails, e);
            }
        }