/// <summary>When Seven Update is closing, save the Window Width and Height in the settings.</summary> /// <param name="sender">The object that called the event.</param> /// <param name="e">The <c>System.ComponentModel.CancelEventArgs</c> instance containing the event data.</param> void SaveWindowSize(object sender, CancelEventArgs e) { Settings.Default.WindowHeight = this.Height; Settings.Default.WindowWidth = this.Width; Settings.Default.Save(); WcfService.Disconnect(); Application.Current.Shutdown(0); }
/// <summary>Loads settings and UI for the page.</summary> /// <param name="sender">The object that called the event.</param> /// <param name="e">The <c>System.Windows.RoutedEventArgs</c> instance containing the event data.</param> void Init(object sender, RoutedEventArgs e) { if (Utilities.RebootNeeded) { Core.Instance.UpdateAction = UpdateAction.RebootNeeded; } if (init) { return; } init = true; this.DataContext = Core.Instance; // Subscribe to events RestoreUpdates.RestoredHiddenUpdate += SettingsChanged; WcfService.SettingsChanged += SettingsChanged; Search.ErrorOccurred += this.ErrorOccurred; Search.SearchCompleted += this.SearchCompleted; UpdateInfo.UpdateSelectionChanged += this.UpdateSelectionChanged; Core.UpdateActionChanged += this.SetUI; WcfService.DownloadProgressChanged += this.DownloadProgressChanged; WcfService.DownloadDone += this.DownloadCompleted; WcfService.InstallProgressChanged += this.InstallProgressChanged; WcfService.InstallDone += this.InstallCompleted; WcfService.ErrorOccurred += this.ErrorOccurred; WcfService.ServiceError += this.ErrorOccurred; if (App.IsDev) { this.tbDevNote.Visibility = Visibility.Visible; this.Title += " - " + Properties.Resources.DevChannel; } if (App.IsBeta) { this.Title += " - " + Properties.Resources.BetaChannel; } Core.Instance.UpdateAction = UpdateAction.NoUpdates; if (Core.IsReconnect) { Core.Instance.UpdateAction = UpdateAction.ConnectingToService; this.timer = new Timer { Enabled = true, Interval = 30000 }; this.timer.Elapsed -= this.CheckIfConnecting; this.timer.Elapsed += this.CheckIfConnecting; WcfService.Connect(); } else if (File.Exists(Path.Combine(App.AllUserStore, "updates.sui"))) { DateTime lastCheck = File.GetLastWriteTime(Path.Combine(App.AllUserStore, "updates.sui")); DateTime today = DateTime.Now; if (lastCheck.Month == today.Month && lastCheck.Year == today.Year) { if (lastCheck.Day == today.Day || lastCheck.Day + 1 == today.Day || lastCheck.Day + 2 == today.Day || lastCheck.Day + 3 == today.Day || lastCheck.Day + 4 == today.Day || lastCheck.Day + 5 == today.Day) { WcfService.Disconnect(); if (File.Exists(Path.Combine(App.AllUserStore, "updates.sui"))) { Task.Factory.StartNew( () => Search.SetUpdatesFound( Utilities.Deserialize <Collection <Sui> >( Path.Combine(App.AllUserStore, "updates.sui")))); } } } else { try { File.Delete(Path.Combine(App.AllUserStore, "updates.sui")); } catch (Exception f) { if (!(f is UnauthorizedAccessException || f is IOException)) { Utilities.ReportError(f, ErrorType.GeneralError); throw; } } Core.Instance.UpdateAction = UpdateAction.CheckForUpdates; } } else { if (Utilities.RebootNeeded) { Core.Instance.UpdateAction = UpdateAction.RebootNeeded; return; } if (Settings.Default.LastUpdateCheck == DateTime.MinValue) { Core.Instance.UpdateAction = UpdateAction.CheckForUpdates; } if (!Settings.Default.LastUpdateCheck.Date.Equals(DateTime.Now.Date)) { Core.Instance.UpdateAction = UpdateAction.CheckForUpdates; } } }