Exemplo n.º 1
0
 void OnDispatcherUnhandledException(object sender, System.Windows.Threading.DispatcherUnhandledExceptionEventArgs e)
 {
     Wu10Logger.LogError(e.Exception);
     string errorMessage = string.Format("{0}\r\n\r\nCheck the logs for more details.", e.Exception.Message);
     MessageBox.Show(errorMessage, "Error", MessageBoxButton.OK, MessageBoxImage.Error);
     e.Handled = true;
 }
 private void BlockAllHosts_Click(object sender, System.Windows.RoutedEventArgs e)
 {
     _hostsFileHelper.BlockAllHostUrls();
     Wu10Logger.LogInfo($"All hosts BLOCKED");
     GetHostSettings();
     ShowUpdateNotice();
 }
Exemplo n.º 3
0
 void WriteStartupLogs()
 {
     var appVersion = this.GetType().Assembly.GetName().Version;
     Wu10Logger.LogInfo($"Application version: v{appVersion.ToString()}");
     Wu10Logger.LogInfo(EnvironmentVersionHelper.GetWindowsVersion());
     Wu10Logger.LogInfo($".Net Framework: {EnvironmentVersionHelper.GetDotNetFrameworkBuild()}");
 }
Exemplo n.º 4
0
        private void SetGroupPolicy(object sender, System.Windows.RoutedEventArgs e)
        {
            switch (SelectedPolicyOption.Key)
            {
            case ENABLE:
                RegistryEditor.DeleteLocalMachineRegistryValue(REGISTRY_ROOT, REGISTRY_AUOPTION);
                RegistryEditor.DeleteLocalMachineRegistryValue(REGISTRY_ROOT, REGISTRY_NOUPDATE);
                break;

            case DISABLE:
                RegistryEditor.WriteLocalMachineRegistryValue(REGISTRY_ROOT, REGISTRY_NOUPDATE, NOUPDATE_ENABLE, RegistryValueKind.DWord);
                RegistryEditor.DeleteLocalMachineRegistryValue(REGISTRY_ROOT, REGISTRY_AUOPTION);
                break;

            case NOTIFY_DOWNLOAD:
                RegistryEditor.WriteLocalMachineRegistryValue(REGISTRY_ROOT, REGISTRY_AUOPTION, AUOPTION_NOTIFY_DOWNLOAD, RegistryValueKind.DWord);
                RegistryEditor.DeleteLocalMachineRegistryValue(REGISTRY_ROOT, REGISTRY_NOUPDATE);
                break;

            case NOTIFY_INSTALL:
                RegistryEditor.WriteLocalMachineRegistryValue(REGISTRY_ROOT, REGISTRY_AUOPTION, AUOPTION_NOTIFY_INSTALL, RegistryValueKind.DWord);
                RegistryEditor.DeleteLocalMachineRegistryValue(REGISTRY_ROOT, REGISTRY_NOUPDATE);
                break;

            case SCHEDULE_INSTALL:
                RegistryEditor.WriteLocalMachineRegistryValue(REGISTRY_ROOT, REGISTRY_AUOPTION, AUOPTION_SCHEDULE_INSTALL, RegistryValueKind.DWord);
                RegistryEditor.DeleteLocalMachineRegistryValue(REGISTRY_ROOT, REGISTRY_NOUPDATE);
                break;
            }

            Wu10Logger.LogInfo(string.Format("Group Policy set: {0}", SelectedPolicyOption.Value));
            System.Windows.MessageBox.Show("Registry settings updated.", "Group Policies", System.Windows.MessageBoxButton.OK, System.Windows.MessageBoxImage.Information);
        }
Exemplo n.º 5
0
 public GroupPolicyControl()
 {
     Wu10Logger.LogInfo("Group Policy Control initializing.");
     CreatePolicyOptions();
     GetCurrentStatus();
     InitializeComponent();
     Wu10Logger.LogInfo("Group Policy Control initialized.");
 }
 public PauseUpdatesControl()
 {
     Wu10Logger.LogInfo("Pause and Defer initializing.");
     DataContext = _model;
     InitializeComponent();
     ReadCurrentSettings();
     Wu10Logger.LogInfo("Pause and Defer initialized.");
 }
Exemplo n.º 7
0
        public GroupPolicyControl()
        {
            _logger = new Wu10Logger();

            CreatePolicyOptions();
            GetCurrentStatus();
            InitializeComponent();
        }
Exemplo n.º 8
0
 public HostsFileControl()
 {
     _hostsFileHelper = new HostsFileHelper();
     _model           = new HostsFileModel();
     _logger          = new Wu10Logger();
     if (!DesignerProperties.GetIsInDesignMode(this))
     {
         SetRuntimeOptions();
     }
 }
        public WindowsServicesControl()
        {
            Wu10Logger.LogInfo("Windows Services initializing.");
            DataContext = _model;

            if (!DesignerProperties.GetIsInDesignMode(this))
            {
                SetRuntimeOptions();
            }
            Wu10Logger.LogInfo("Windows Services initialized.");
        }
Exemplo n.º 10
0
 public HostsFileControl()
 {
     Wu10Logger.LogInfo("Hosts File initializing.");
     _hostsFileHelper = new HostsFileHelper();
     _model           = new HostsFileModel();
     if (!DesignerProperties.GetIsInDesignMode(this))
     {
         SetRuntimeOptions();
     }
     Wu10Logger.LogInfo("Hosts File initialized.");
 }
Exemplo n.º 11
0
 public bool ServiceExists()
 {
     try
     {
         return(_serviceController.DisplayName != null);
     }
     catch (Exception ex)
     {
         Wu10Logger.LogError(ex);
         return(false);
     }
 }
Exemplo n.º 12
0
        private bool IsHostsFileLocked()
        {
            var lockingProcesses = _hostsFileHelper.GetLockingProcessNames();

            if (lockingProcesses?.Any() == true)
            {
                var processNames = string.Join("\r\n", lockingProcesses);
                var message      = "The Hosts file is being locked by the following processes and cannot be updated:\r\n" + processNames;
                Wu10Logger.LogInfo(message);
                System.Windows.MessageBox.Show(message, "Hosts File Locked", System.Windows.MessageBoxButton.OK, System.Windows.MessageBoxImage.Error);
                return(true);
            }

            return(false);
        }
        private void ToggleService(object sender, System.Windows.RoutedEventArgs e)
        {
            var toggle = ((ToggleSwitch)sender);
            var data   = (WindowsServiceStatusModel)toggle.DataContext;

            if (toggle.IsChecked.Value)
            {
                EnableService(data.ServiceName, data.DisplayName);
                Wu10Logger.LogInfo($"Service ENABLED: {data.ServiceName} - {data.DisplayName}");
            }
            else
            {
                DisableService(data.ServiceName, data.DisplayName);
                Wu10Logger.LogInfo($"Service DISABLED: {data.ServiceName} - {data.DisplayName}");
            }
        }
Exemplo n.º 14
0
        private void SetServiceStatus(string serviceName)
        {
            var serviceModel = _model.Services.Single(x => x.ServiceName == serviceName);

            try
            {
                serviceModel.ServiceExists = _windowsServiceHelper.ServiceExists(serviceName);
                if (serviceModel.ServiceExists)
                {
                    serviceModel.DisplayName      = _windowsServiceHelper.GetServiceDisplayName(serviceName);
                    serviceModel.IsServiceEnabled = _windowsServiceHelper.IsServiceEnabled(serviceName);
                }
            }
            catch (Exception ex)
            {
                Wu10Logger.LogError(ex);
            }
        }
Exemplo n.º 15
0
        private void ToggleHostItem(object sender, System.Windows.RoutedEventArgs e)
        {
            var toggle = (ToggleSwitch)sender;
            var kvp    = (HostStatus)toggle.DataContext;

            if (toggle.IsChecked.Value)
            {
                _hostsFileHelper.UnblockHostUrl(kvp.Host);
                Wu10Logger.LogInfo($"Host UNBLOCKED: {kvp.Host}");
            }
            else
            {
                _hostsFileHelper.BlockHostUrl(kvp.Host);
                Wu10Logger.LogInfo($"Host BLOCKED: {kvp.Host}");
            }

            ShowUpdateNotice();
        }
Exemplo n.º 16
0
        public App() : base()
        {
            Wu10Logger.LogInfo("Application starting");
            try
            {
                WriteStartupLogs();
                this.Dispatcher.UnhandledException += OnDispatcherUnhandledException;
                this.MainWindow = new MainWindow();
                this.MainWindow.Show();

                Wu10Logger.LogInfo("Application started");
            }
            catch (Exception ex)
            {
                Wu10Logger.LogError(ex);
                MessageBox.Show("An error occured attempting to initialize the application.  Check the log file for more details.", "Error!", System.Windows.MessageBoxButton.OK, System.Windows.MessageBoxImage.Error);
                this.Shutdown();
            }
        }
        private void WriteChanges()
        {
            var nowString = GetDateString(DateTime.Now);

            if (_model.FeatureUpdatePauseDate.HasValue)
            {
                var pauseDateString = GetDateString(_model.FeatureUpdatePauseDate.Value);
                RegistryEditor.WriteLocalMachineRegistryValue(UXRegistryKey, PauseFeatureUpdatesStartTime, nowString, RegistryValueKind.String);
                RegistryEditor.WriteLocalMachineRegistryValue(UXRegistryKey, PauseFeatureUpdatesEndTime, pauseDateString, RegistryValueKind.String);
                Wu10Logger.LogInfo($"Saving Feature Pause Date: {pauseDateString}");
            }
            else
            {
                RegistryEditor.DeleteLocalMachineRegistryValue(UXRegistryKey, PauseFeatureUpdatesStartTime);
                RegistryEditor.DeleteLocalMachineRegistryValue(UXRegistryKey, PauseFeatureUpdatesEndTime);
                Wu10Logger.LogInfo("Removing Feature Pause Date");
            }

            if (_model.FeatureUpdateDelayDays > 0)
            {
                RegistryEditor.WriteLocalMachineRegistryValue(UXRegistryKey, DeferFeatureUpdatesPeriodInDays, _model.FeatureUpdateDelayDays.ToString(), RegistryValueKind.DWord);
                Wu10Logger.LogInfo($"Saving Feature Deferal Days: {_model.FeatureUpdateDelayDays}");
            }
            else
            {
                RegistryEditor.WriteLocalMachineRegistryValue(UXRegistryKey, DeferFeatureUpdatesPeriodInDays, "0", RegistryValueKind.DWord);
                Wu10Logger.LogInfo($"Saving Feature Deferal Days: 0");
            }

            if (_model.QualityUpdatePauseDate.HasValue)
            {
                var pauseDateString = GetDateString(_model.QualityUpdatePauseDate.Value);
                RegistryEditor.WriteLocalMachineRegistryValue(UXRegistryKey, PauseQualityUpdatesStartTime, nowString, RegistryValueKind.String);
                RegistryEditor.WriteLocalMachineRegistryValue(UXRegistryKey, PauseQualityUpdatesEndTime, pauseDateString, RegistryValueKind.String);
                Wu10Logger.LogInfo($"Saving Quality Pause Date: {pauseDateString}");
            }
            else
            {
                RegistryEditor.DeleteLocalMachineRegistryValue(UXRegistryKey, PauseQualityUpdatesStartTime);
                RegistryEditor.DeleteLocalMachineRegistryValue(UXRegistryKey, PauseQualityUpdatesEndTime);
                Wu10Logger.LogInfo("Removing Quality Pause Date");
            }

            if (_model.QualityUpdateDelayDays > 0)
            {
                RegistryEditor.WriteLocalMachineRegistryValue(UXRegistryKey, DeferQualityUpdatesPeriodInDays, _model.QualityUpdateDelayDays.ToString(), RegistryValueKind.DWord);
                Wu10Logger.LogInfo($"Saving Quality Deferal Days: {_model.QualityUpdateDelayDays}");
            }
            else
            {
                RegistryEditor.WriteLocalMachineRegistryValue(UXRegistryKey, DeferQualityUpdatesPeriodInDays, "0", RegistryValueKind.DWord);
                Wu10Logger.LogInfo($"Saving Quality Deferal Days: {_model.FeatureUpdateDelayDays}");
            }

            var latestDate = Math.Max(_model.FeatureUpdatePauseDate?.Ticks ?? 0, _model.QualityUpdatePauseDate?.Ticks ?? 0);

            if (latestDate > 0)
            {
                var pauseDateString = GetDateString(new DateTime(latestDate));
                RegistryEditor.WriteLocalMachineRegistryValue(UXRegistryKey, PauseUpdatesExpiryTime, GetDateString(new DateTime(latestDate)), RegistryValueKind.String);
                //RegistryEditor.WriteLocalMachineRegistryValue(UXRegistryKey, PendingRebootStartTime, now.ToString(dateFormat), RegistryValueKind.String);
                Wu10Logger.LogInfo($"Saving Pause Date Expiry: {pauseDateString}");
            }
            else
            {
                RegistryEditor.DeleteLocalMachineRegistryValue(UXRegistryKey, PauseUpdatesExpiryTime);
                Wu10Logger.LogInfo($"Removing Pause Date Expiry");
            }

            MessageBox.Show($"Windows Update pause dates and deferal period have been saved.", "Pause and Defer", System.Windows.MessageBoxButton.OK, System.Windows.MessageBoxImage.Information);
        }
Exemplo n.º 18
0
 protected override void OnExit(ExitEventArgs e)
 {
     Wu10Logger.LogInfo("Application ended");
     base.OnExit(e);
 }
Exemplo n.º 19
0
 public MainWindow()
 {
     Wu10Logger.LogInfo("Main window initializing.");
     InitializeComponent();
     Wu10Logger.LogInfo("Main window initialized.");
 }
Exemplo n.º 20
0
 public App() : base()
 {
     _logger = new Wu10Logger();
     _logger.LogInfo("Application started");
     this.Dispatcher.UnhandledException += OnDispatcherUnhandledException;
 }