/// <summary>
        /// Called when the applications starts. Makes a distinction between debug and release mode
        /// </summary>
        /// <param name="e">
        /// the event argument
        /// </param>
        protected override void OnStartup(StartupEventArgs e)
        {
            // Set the Theme of the application
            ThemeManager.ApplicationThemeName = Theme.SevenName;
            AppliedTheme.ThemeName            = Theme.SevenName;
            base.OnStartup(e);

            this.ShutdownMode = ShutdownMode.OnExplicitShutdown;

            if (UpdateInstaller.CheckInstallAndVerifyIfTheImeShallShutdown())
            {
                Current.Shutdown();
                return;
            }

            DXSplashScreen.Show <Views.SplashScreenView>();
            DXSplashScreen.SetState("Starting COMET");

#if (DEBUG)
            RunInDebugMode();
#else
            RunInReleaseMode();
#endif

            this.ShutdownMode = ShutdownMode.OnMainWindowClose;

            DXSplashScreen.SetState("Preparing Main Window");

            Current.MainWindow.Show();
            DXSplashScreen.Close();
        }
Beispiel #2
0
        public UpdateManager(HomeGenieService homeGenieService)
        {
            UpdateChecker   = new UpdateChecker();
            UpdateInstaller = new UpdateInstaller(homeGenieService);

            CurrentRelease = UpdateChecker.GetCurrentRelease();
        }
        public static void InstallUpdates(UpdateCollection DownloadedUpdates)
        {
            Console.WriteLine("Installing updates now...");
            UpdateSession   UpdateSession = new UpdateSession();
            UpdateInstaller InstallAgent  = UpdateSession.CreateUpdateInstaller() as UpdateInstaller;

            InstallAgent.Updates = DownloadedUpdates;

            //Starts a synchronous installation of the updates.
            // http://msdn.microsoft.com/en-us/library/windows/desktop/aa386491(v=VS.85).aspx#methods
            if (DownloadedUpdates.Count > 0)
            {
                IInstallationResult InstallResult = InstallAgent.Install();
                if (InstallResult.ResultCode == OperationResultCode.orcSucceeded)
                {
                    Console.WriteLine("Updates installed succesfully");
                    if (InstallResult.RebootRequired == true)
                    {
                        Console.WriteLine("Reboot is required for one of more updates.");
                    }
                }
                else
                {
                    Console.WriteLine("Updates failed to install do it manually");
                }
            }
            else
            {
                Console.WriteLine("The computer that this script was executed is up to date");
            }
        }
Beispiel #4
0
        public static int Main(string[] args)
        {
            AppDomain.CurrentDomain.UnhandledException += (s, e) => OnUnhandledException(e.ExceptionObject as Exception);

            CliArgs = CliArgs.Parse(args);

            if (args.Length == 0)
            {
                Logger.LogInfo("Started without cli args");
            }
            else
            {
                Logger.LogInfo("Started with args: " + string.Join(" ", args));
            }

            using var mutex = new Mutex(initiallyOwned: true, SingletonMutexName, out var notAlreadyRunning);

            if (CliArgs.IsUpdateRestart)
            {
                try {
                    // wait for old version to exit and release the mutex.
                    mutex.WaitOne(TimeSpan.FromSeconds(10), exitContext: false);
                    UpdateInstaller.CleanupUpdate();
                } catch (Exception e) {
                    Logger.LogException("Restart failed after update", e);
                }

                // the application has exited so we are not already running.
                notAlreadyRunning = true;
            }

            if (notAlreadyRunning)   // we are the only one around :(
            {
                var cancellationTokenSource = new CancellationTokenSource();
                Task.Run(() => RunPipeServer(cancellationTokenSource.Token), cancellationTokenSource.Token);

                var exitCode = RunApp();
                Logger.LogInfo($"App exited with code {exitCode}");

                cancellationTokenSource.Cancel();
                mutex.ReleaseMutex();
                return(exitCode);
            }
            else     // another instance is already running
            {
                using var client = new NamedPipeClientStream(".", PipeName, PipeDirection.Out, PipeOptions.Asynchronous);
                client.Connect(TimeSpan.FromSeconds(10).Milliseconds);

                if (CliArgs.IsProxyStart)
                {
                    using var writer = new StreamWriter(client);
                    writer.WriteLine(CliArgs.ProxyStartOption);
                    writer.Flush();
                }

                return(0);
            }
        }
Beispiel #5
0
        private void updateInteractionManager_UpdateAccepted(object sender, UpdateInfo update)
        {
            this.InvokeAsyncSafe(() => {
                FormManager.CloseAllDialogs();

                if (!string.IsNullOrEmpty(Config.DismissedUpdate))
                {
                    Config.DismissedUpdate = null;
                    Config.Save();
                }

                void OnFinished()
                {
                    UpdateDownloadStatus status = update.DownloadStatus;

                    if (status == UpdateDownloadStatus.Done)
                    {
                        UpdateInstaller = new UpdateInstaller(update.InstallerPath);
                        ForceClose();
                    }
                    else if (status != UpdateDownloadStatus.Canceled && FormMessage.Error("Update Has Failed", "Could not automatically download the update: " + (update.DownloadError?.Message ?? "unknown error") + "\n\nWould you like to open the website and try downloading the update manually?", FormMessage.Yes, FormMessage.No))
                    {
                        App.SystemHandler.OpenBrowser(Program.Website);
                        ForceClose();
                    }
                    else
                    {
                        Show();
                    }
                }

                if (update.DownloadStatus.IsFinished(true))
                {
                    OnFinished();
                }
                else
                {
                    FormUpdateDownload downloadForm = new FormUpdateDownload(update);

                    downloadForm.VisibleChanged += (sender2, args2) => {
                        downloadForm.MoveToCenter(this);
                        Hide();
                    };

                    downloadForm.FormClosed += (sender2, args2) => {
                        if (downloadForm.DialogResult != DialogResult.OK)
                        {
                            update.CancelDownload();
                        }

                        downloadForm.Dispose();
                        OnFinished();
                    };

                    downloadForm.Show();
                }
            });
        }
         public static void InstallUpdates(UpdateCollection DownloadedUpdates)
         {
             UpdateSession UpdateSession = new UpdateSession();
             UpdateInstaller InstallAgent = UpdateSession.CreateUpdateInstaller() as UpdateInstaller;
             InstallAgent.Updates = DownloadedUpdates;
             
             //Starts a synchronous installation of the updates.
             // http://msdn.microsoft.com/en-us/library/windows/desktop/aa386491(v=VS.85).aspx#methods
             IInstallationResult InstallResult = InstallAgent.Install();
 
         }
        public void VerifyIncompatibleIMEUpdate()
        {
            this.SetupInstallerFile(false);

            new UpdateFileSystemService().ImeDownloadPath = new DirectoryInfo(this.imeDownloadTestPath);
            Assert.IsFalse(UpdateInstaller.CheckInstallAndVerifyIfTheImeShallShutdown(this.viewInvoker.Object));

            this.viewInvoker.Verify(x => x.ShowMessageBox(
                                        It.IsAny <string>(), It.IsAny <string>(), MessageBoxButton.YesNo, MessageBoxImage.Information), Times.Never);

            this.commandRunner.Verify(x => x.RunAsAdmin(It.IsAny <string>()), Times.Never);
        }
        public void VerifyIMEUpdate()
        {
            this.viewInvoker.Setup(x => x.ShowMessageBox(
                                       It.IsAny <string>(), It.IsAny <string>(), MessageBoxButton.YesNo, MessageBoxImage.Information)).Returns(MessageBoxResult.Yes);

            this.SetupInstallerFile(true);

            Assert.IsTrue(UpdateInstaller.CheckInstallAndVerifyIfTheImeShallShutdown(this.viewInvoker.Object, this.commandRunner.Object));

            this.viewInvoker.Verify(x => x.ShowMessageBox(
                                        It.IsAny <string>(), It.IsAny <string>(), MessageBoxButton.YesNo, MessageBoxImage.Information), Times.Once);

            this.commandRunner.Verify(x => x.RunAsAdmin(It.IsAny <string>()), Times.Once);
        }
Beispiel #9
0
        private void InstallUpdate(string downloadUrl, string[] toBackup)
        {
            UpdateInstaller installer = new UpdateInstaller(downloadUrl, toBackup);

            installer.Progress += installer_Progress;


            this.Notify("Update Started", "The update process has started.");
            try
            {
                installer.Update();
            }
            catch (Exception ex)
            {
                Log.Error("Exception occurred. {Exception}.", ex);
                this.Notify(Titles.UnknownError, ex.Message);
            }
        }
Beispiel #10
0
        internal static void WsusInstaller(UpdateCollection updatesToInstall)
        {
            IUpdateInstaller installer = new UpdateInstaller();

            installer.Updates = updatesToInstall;
            IInstallationResult installationRes = installer.Install();

            for (int i = 0; i < updatesToInstall.Count; i++)
            {
                if (installationRes.GetUpdateResult(i).HResult == 0)
                {
                    Program.LogInfo($"Installed :  {updatesToInstall[i].Title}");
                }
                else
                {
                    Program.LogInfo($"Failed :  {updatesToInstall[i].Title}");
                }
            }
        }
Beispiel #11
0
        public static UpdateCollection InsallWsusUpdates()
        {
            //var sSecurePassword = ConvertTo-SecureString –String sPassword –AsPlainText -Force
            //  var oCredential = CreateObject("System.Management.Automation.PSCredential") ' - ArgumentList sUser, sSecurePassword
            var sDateAndTime  = DateTime.Now;
            var sCriteria     = "IsInstalled=0 and Type='Software'";
            var oSearcher     = new UpdateSearcher();
            var oSearchResult = oSearcher.Search(sCriteria).Updates;
            var count         = oSearchResult.Count;
            var oSession      = new UpdateSession();
            var oDownloader   = oSession.CreateUpdateDownloader();

            oDownloader.Updates = oSearchResult;
            oDownloader.Download();
            var oInstaller = new UpdateInstaller();

            oInstaller.Updates = oSearchResult;
            //Result -> 2 = Succeeded, 3 = Succeeded with Errors, 4 = Failed, 5 = Aborted
            return((UpdateCollection)oInstaller.Install());
        }
        public void VerifyCheckInstallAndVerifyIfTheImeShallShutdown()
        {
            Assert.IsFalse(UpdateInstaller.CheckInstallAndVerifyIfTheImeShallShutdown(this.viewInvoker.Object));
            this.viewInvoker.Verify(x => x.ShowDialog(It.IsAny <UpdateDownloaderInstaller>()), Times.Never);

            var dataPath = new DirectoryInfo(Path.Combine(TestContext.CurrentContext.TestDirectory, "ViewModels", "PluginMockData"));

            foreach (var file in dataPath.EnumerateFiles())
            {
                var destination = Path.Combine(this.downloadPath, Path.GetFileNameWithoutExtension(file.Name));

                if (!Directory.Exists(destination))
                {
                    Directory.CreateDirectory(destination);
                }

                File.Copy(file.FullName, Path.Combine(destination, file.Name), true);
            }

            UpdateInstaller.CheckInstallAndVerifyIfTheImeShallShutdown(this.viewInvoker.Object);
            this.viewInvoker.Verify(x => x.ShowDialog(It.IsAny <UpdateDownloaderInstaller>()), Times.Once);
        }
Beispiel #13
0
        // source; http://www.tech-archive.net/Archive/DotNet/microsoft.public.dotnet.framework.interop/2007-01/msg00001.html
        private static int PendingUpdates()
        {
            Type            stype     = Type.GetTypeFromProgID("Microsoft.Update.Session");
            UpdateSession   session   = (UpdateSession)Activator.CreateInstance(stype);
            Type            itype     = Type.GetTypeFromProgID("Microsoft.Update.Installer");
            UpdateInstaller installer = (UpdateInstaller)Activator.CreateInstance(itype);
            IUpdate         u;

            IUpdateSearcher  us      = session.CreateUpdateSearcher();
            ISearchResult    sr      = us.Search("IsInstalled=0 and Type='Software'");
            UpdateCollection updates = sr.Updates;

            for (int i = 0; i < updates.Count; i++)
            {
                u = updates[i]; //do something with update;show.
                //System.Console.WriteLine(u.Title);
                // System.Console.WriteLine(u.Description);
                //System.Console.WriteLine(" ");
            }
            Console.WriteLine("Updates:{0}", updates.Count);

            return(updates.Count);
        }