public MainWindow() { try { InitializeComponent(); if (User.Default.MinimiseToSystemTray) { //add tray icon _tray = new TrayMainWindows(this); //add global key _hotkey = new HotKeyMainWindows(this, ModifierKeys.Windows | ModifierKeys.Alt, System.Windows.Forms.Keys.T); } //add view on change file _changefile = new ObserverChangeFile(); _changefile.OnFileTaskListChange += () => Dispatcher.Invoke(DispatcherPriority.Normal, new Action(delegate() { this.Refresh(); })); //CheckUpdate new version _checkupdate = new CheckUpdate(); _checkupdate.OnCheckedUpdateVersion += (string version) => Dispatcher.BeginInvoke(new CheckUpdate.CheckUpdateVersion(this.ShowUpdateMenu), version); _checkupdate.Check(); webBrowser1.Navigate("about:blank"); // migrate the user settings from the previous version, if necessary if (User.Default.FirstRun) { User.Default.Upgrade(); User.Default.FirstRun = false; User.Default.Save(); } Log.LogLevel = User.Default.DebugLoggingOn ? LogLevel.Debug : LogLevel.Error; this.Height = User.Default.WindowHeight; this.Width = User.Default.WindowWidth; this.Left = User.Default.WindowLeft; this.Top = User.Default.WindowTop; if (!string.IsNullOrEmpty(User.Default.FilePath)) LoadTasks(User.Default.FilePath); FilterAndSort((SortType)User.Default.CurrentSort); lbTasks.Focus(); string startupFile = ((App)App.Current).StartupFile; if (!string.IsNullOrEmpty(startupFile)) LoadTasks(startupFile); } catch (Exception ex) { var msg = "An error occurred while intialising the application"; Log.Error(msg, ex); MessageBox.Show(ex.Message, msg, MessageBoxButton.OK); } }
public MainWindow() { try { InitializeComponent(); if (User.Default.MinimiseToSystemTray) { //add tray icon _tray = new TrayMainWindows(this); //add global key _hotkey = new HotKeyMainWindows(this, ModifierKeys.Windows | ModifierKeys.Alt, System.Windows.Forms.Keys.T); } //add view on change file _changefile = new ObserverChangeFile(); _changefile.OnFileTaskListChange += () => Dispatcher.Invoke(DispatcherPriority.Normal, new Action(delegate() { this.Refresh(); })); //CheckUpdate new version _checkupdate = new CheckUpdate(); _checkupdate.OnCheckedUpdateVersion += (string version) => Dispatcher.BeginInvoke(new CheckUpdate.CheckUpdateVersion(this.ShowUpdateMenu), version); _checkupdate.Check(); webBrowser1.Navigate("about:blank"); // migrate the user settings from the previous version, if necessary if (User.Default.FirstRun) { User.Default.Upgrade(); User.Default.FirstRun = false; User.Default.Save(); } Log.LogLevel = User.Default.DebugLoggingOn ? LogLevel.Debug : LogLevel.Error; this.Height = User.Default.WindowHeight; this.Width = User.Default.WindowWidth; this.Left = User.Default.WindowLeft; this.Top = User.Default.WindowTop; if (!string.IsNullOrEmpty(User.Default.FilePath)) { LoadTasks(User.Default.FilePath); } FilterAndSort((SortType)User.Default.CurrentSort); lbTasks.Focus(); } catch (Exception ex) { var msg = "An error occurred while intialising the application"; Log.Error(msg, ex); MessageBox.Show(ex.Message, msg, MessageBoxButton.OK, MessageBoxImage.Error); } }
/// <summary> /// 获得最后的版本信息 /// </summary> void GetLastVersionInfo() { var path = Path.Combine(CacheManager.Instance.Version.URL, CacheManager.Instance.Version.Path); WebClientPro client = new WebClientPro(10 * 1000); try { var bytes = client.DownloadData(path); string serviceInfo = Encoding.UTF8.GetString(client.DownloadData(path)); var serviceUpdate = serviceInfo.XmlDeserailize<ServiceUpdate>(); // 获取原始路径 if (File.Exists("target.info")) { var targetPath = (string)"target.info".FileDeSerialize(); if (Directory.Exists(targetPath)) Directory.Delete(targetPath, true); } var localVersion = new Version(CacheManager.Instance.Version.Version); var serviceVersion = new Version(serviceUpdate.Version); if (localVersion < serviceVersion) { CheckUpdate checkUpdate = new CheckUpdate(); checkUpdate.Closed += (s, arg) => { if (!checkUpdate.DialogResult.Value) { System.Environment.Exit(-1); } }; checkUpdate.ShowDialog(); } else { LogManager.Logger.Info($"localVersion:{localVersion} serviceVersion:{serviceVersion}"); } } catch (Exception ex) { LogManager.Logger.Warn($"GetLastVersionInfo {ex.Message}"); return; } }