public SettingsViewModel(Action closeWindowCallback, VersionHelper versionHelper) { CanInstallUpdates = UacHelper.IsRunningAsAdmin(); CanNotInstallUpdates = !CanInstallUpdates; var settings = AppSettings.Instance; RefreshInterval = settings.RefreshInterval; HideIcon = settings.HideIcon; DisableNotifications = settings.DisableNotifications; UseMetroStyle = settings.UseMetroStyle; InstallUpdates = settings.InstallUpdates && CanInstallUpdates; AdditionalKbIds = settings.AdditionalKbIds; IsSetAsAutoStartup = StartupHelper.IsSetAsAutoStartup(); HelpLink = "http://wun.codeplex.com/"; HowToStartAsAdminLink = "http://wun.codeplex.com/wikipage?title=HowToStartAsAdmin"; Version = string.Format("Version {0} © Christoph Pangerl", versionHelper.CurrentVersion); AutoInstallComment = string.Format(TextResources.Label_AutoInstallComment, string.Join(", KB", settings.WindowsDefenderKbIds)); SaveAndCloseCommand = new SimpleCommand(() => _SaveAndClose(closeWindowCallback)); ShowHelpCommand = new SimpleCommand(() => _OpenLink(HelpLink)); ShowHowToStartAsAdminCommand = new SimpleCommand(() => _OpenLink(HowToStartAsAdminLink)); }
public void SearchForUpdates() { mTimer.Stop(); mWmiWatcher.Stop(); var ids = AppSettings.Instance.InstallUpdates && UacHelper.IsRunningAsAdmin() ? AppSettings.Instance.KbIdsToInstall : new string[0]; mUpdateManager.StartSearchForUpdates(ids, AppSettings.Instance.KbIdsToIgnore); mTrayIcon.SetupToolTip(TextResources.ToolTip_Searching); mTrayIcon.SetIcon(UpdateState.Searching); mMenuViewModel.IsSearchForUpdatesEnabled = false; mMenuViewModel.UpdateStateText = TextResources.ToolTip_Searching; }
private int _InstallUpdates(UpdateSession session, UpdateCollection updates) { if (updates.Count < 1 || UacHelper.IsRunningAsAdmin() == false) { return(0); } try { var downloader = session.CreateUpdateDownloader(); downloader.Updates = updates; downloader.Download(); var updatesToInstall = new UpdateCollection(); foreach (IUpdate update in updates) { if (update.IsDownloaded) { updatesToInstall.Add(update); } } var installer = session.CreateUpdateInstaller(); installer.Updates = updatesToInstall; var result = installer.Install(); var numberOfInstalledUpdates = 0; for (var i = 0; i < updatesToInstall.Count; i++) { if (result.GetUpdateResult(i).HResult == 0) { numberOfInstalledUpdates++; } } return(numberOfInstalledUpdates); } catch (Exception) { return(0); } }