コード例 #1
0
        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));
        }
コード例 #2
0
        private void _CorrectKbIdsIfNeeded()
        {
            var kbIds = mConfig.AppSettings.Settings[KB_IDS_TO_INSTALL].Value;

            if (kbIds == WINDOWS_8_DEFENDER_KB_ID && UacHelper.IsRunningOnWindows7())
            {
                _SetSetting(KB_IDS_TO_INSTALL, WINDOWS_7_DEFENDER_KB_ID);
            }
        }
コード例 #3
0
        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;
        }
コード例 #4
0
        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);
            }
        }
コード例 #5
0
        private static Color _GetWindowsThemeBackgroundColor()
        {
            if (UacHelper.IsRunningOnWindows7())
            {
                return(Color.FromArgb(255, 35, 38, 39));
            }

            var colorSet    = GetImmersiveUserColorSetPreference(false, false);
            var elementName = Marshal.StringToHGlobalUni("ImmersiveStartBackground");

            Marshal.FreeCoTaskMem(elementName);

            var type       = GetImmersiveColorTypeFromName(elementName);
            var colorDword = GetImmersiveColorFromColorSetEx((uint)colorSet, type, false, 0);

            var colorBytes = new byte[4];

            colorBytes[0] = (byte)((0xFF000000 & colorDword) >> 24); // A
            colorBytes[1] = (byte)((0x00FF0000 & colorDword) >> 16); // B
            colorBytes[2] = (byte)((0x0000FF00 & colorDword) >> 8);  // G
            colorBytes[3] = (byte)((0x000000FF & colorDword) >> 0);  // R

            return(Color.FromArgb(colorBytes[0], colorBytes[3], colorBytes[2], colorBytes[1]));
        }
コード例 #6
0
 private string _GetWindowsDefenderKbId()
 {
     return(UacHelper.IsRunningOnWindows7()
         ? WINDOWS_7_DEFENDER_KB_ID
         : WINDOWS_8_DEFENDER_KB_ID); // use windows 8 kb-id as a default value even if it is not a windows 8 os.
 }