public ShellView() { View = this; View.Position = new Avalonia.Point(Settings.Default.Left, Settings.Default.Top); this.Initialized += this.InitDone; InitializeComponent(); var spinner = this.FindControl <Image>("PluginUpdateSpinner"); _rotate = (RotateTransform)spinner.RenderTransform; _spinner = new Timer(25); _spinner.Elapsed += SpinnerRotatingTimer; ViewModels.UpdateViewModel.Instance.PropertyChanged += (o, e) => { if (e.PropertyName == nameof(ViewModels.UpdateViewModel.UpdatingAvailablePlugins)) { if (ViewModels.UpdateViewModel.Instance.UpdatingAvailablePlugins) { _spinner.Start(); } else { _spinner.Stop(); Avalonia.Threading.DispatcherTimer.RunOnce(() => { _rotate.Angle = 0; }, new TimeSpan(0)); } } }; View.PositionChanged += (o, e) => { var iX = (int)e.Point.X; var iY = (int)e.Point.Y; if (iX != Settings.Default.Left) { Settings.Default.Left = iX; } if (iY != Settings.Default.Top) { Settings.Default.Top = iY; } }; }
public ShellView() { InitializeComponent(); View = this; View.Topmost = true; }
/// <summary> /// </summary> public static void CheckUpdates() { try { Process[] updaters = Process.GetProcessesByName("FFXIVAPP.Updater"); foreach (Process updater in updaters) { updater.Kill(); } if (File.Exists("FFXIVAPP.Updater.exe")) { File.Delete("FFXIVAPP.Updater.Backup.exe"); } else { if (File.Exists("FFXIVAPP.Updater.Backup.exe")) { File.Move("FFXIVAPP.Updater.Backup.exe", "FFXIVAPP.Updater.exe"); } } } catch (Exception ex) { Logging.Log(Logger, new LogItem(ex, true)); } Func <bool> update = delegate { var current = Assembly.GetExecutingAssembly().GetName().Version.ToString(); AppViewModel.Instance.CurrentVersion = current; var httpWebRequest = (HttpWebRequest)WebRequest.Create("https://api.github.com/repos/Icehunter/ffxivapp/releases"); httpWebRequest.UserAgent = "Icehunter-FFXIVAPP"; httpWebRequest.Headers.Add("Accept-Language", "en;q=0.8"); httpWebRequest.ContentType = "application/json; charset=utf-8"; httpWebRequest.CachePolicy = new RequestCachePolicy(RequestCacheLevel.NoCacheNoStore); using (var httpResponse = (HttpWebResponse)httpWebRequest.GetResponse()) { using (Stream response = httpResponse.GetResponseStream()) { var responseText = string.Empty; if (response != null) { using (var streamReader = new StreamReader(response)) { responseText = streamReader.ReadToEnd(); } } var latestBuild = new BuildNumber(); var currentBuild = new BuildNumber(); if (httpResponse.StatusCode != HttpStatusCode.OK || string.IsNullOrWhiteSpace(responseText)) { AppViewModel.Instance.HasNewVersion = false; AppViewModel.Instance.LatestVersion = "Unknown"; } else { JArray releases = JArray.Parse(responseText); JToken release = releases.FirstOrDefault(r => r?["target_commitish"].ToString() == "master"); var latest = release?["name"].ToString() ?? "Unknown"; latest = latest.Split(' ')[0]; AppViewModel.Instance.LatestVersion = latest; switch (latest) { case "Unknown": AppViewModel.Instance.HasNewVersion = false; break; default: AppViewModel.Instance.DownloadUri = string.Format("https://github.com/Icehunter/ffxivapp/releases/download/{0}/{0}.zip", latest); AppViewModel.Instance.HasNewVersion = BuildUtilities.NeedsUpdate(latest, current, ref latestBuild, ref currentBuild); break; } if (AppViewModel.Instance.HasNewVersion) { var title = $"{AppViewModel.Instance.Locale["app_DownloadNoticeHeader"]} {AppViewModel.Instance.Locale["app_DownloadNoticeMessage"]}"; var message = new StringBuilder(); try { DateTime latestBuildDateTime = new DateTime(2000, 1, 1).Add(new TimeSpan(TimeSpan.TicksPerDay * latestBuild.Build + TimeSpan.TicksPerSecond * 2 * latestBuild.Revision)); DateTime currentBuildDateTime = new DateTime(2000, 1, 1).Add(new TimeSpan(TimeSpan.TicksPerDay * currentBuild.Build + TimeSpan.TicksPerSecond * 2 * currentBuild.Revision)); TimeSpan timeSpan = latestBuildDateTime - currentBuildDateTime; if (timeSpan.TotalSeconds > 0) { message.AppendLine(string.Format("Missing {0} days, {1} hours and {2} seconds of updates.{3}", timeSpan.Days, timeSpan.Hours, timeSpan.Seconds)); } } catch (Exception ex) { Logging.Log(Logger, new LogItem(ex, true)); } finally { message.AppendLine(AppViewModel.Instance.Locale["app_AlwaysReadUpdatesMessage"]); } MessageBoxHelper.ShowMessageAsync(title, message.ToString(), () => ShellView.CloseApplication(true), delegate { }); } } } } return(true); }; update.BeginInvoke(delegate { }, update); }
/// <summary> /// </summary> public static void CheckUpdates() { try { var updaters = Process.GetProcessesByName("FFXIVAPP.Updater"); foreach (var updater in updaters) { updater.Kill(); } if (File.Exists("FFXIVAPP.Updater.exe")) { File.Delete("FFXIVAPP.Updater.Backup.exe"); } else { if (File.Exists("FFXIVAPP.Updater.Backup.exe")) { File.Move("FFXIVAPP.Updater.Backup.exe", "FFXIVAPP.Updater.exe"); } } } catch (Exception ex) { } Func <bool> updateCheck = delegate { var current = Assembly.GetExecutingAssembly() .GetName() .Version.ToString(); AppViewModel.Instance.CurrentVersion = current; var httpWebRequest = (HttpWebRequest)WebRequest.Create("https://api.github.com/repos/Icehunter/ffxivapp/releases"); httpWebRequest.UserAgent = "Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10_6_3; en-US) AppleWebKit/533.4 (KHTML, like Gecko) Chrome/5.0.375.70 Safari/533.4"; httpWebRequest.Headers.Add("Accept-Language", "en;q=0.8"); httpWebRequest.ContentType = "application/json; charset=utf-8"; httpWebRequest.CachePolicy = new RequestCachePolicy(RequestCacheLevel.NoCacheNoStore); using (var httpResponse = (HttpWebResponse)httpWebRequest.GetResponse()) { using (var response = httpResponse.GetResponseStream()) { var responseText = ""; if (response != null) { using (var streamReader = new StreamReader(response)) { responseText = streamReader.ReadToEnd(); } } var latestBuild = new BuildNumber(); var currentBuild = new BuildNumber(); if (httpResponse.StatusCode != HttpStatusCode.OK || String.IsNullOrWhiteSpace(responseText)) { AppViewModel.Instance.HasNewVersion = false; AppViewModel.Instance.LatestVersion = "Unknown"; } else { var releases = JArray.Parse(responseText); var release = releases.FirstOrDefault(r => r?["target_commitish"].ToString() == "3.0-stable"); var latest = release?["name"].ToString() ?? "Unknown"; latest = latest.Split(' ')[0]; AppViewModel.Instance.LatestVersion = latest; switch (latest) { case "Unknown": AppViewModel.Instance.HasNewVersion = false; break; default: AppViewModel.Instance.DownloadUri = String.Format("https://github.com/Icehunter/ffxivapp/releases/download/{0}/{0}.zip", latest); AppViewModel.Instance.HasNewVersion = BuildUtilities.NeedsUpdate(latest, current, ref latestBuild, ref currentBuild); break; } if (AppViewModel.Instance.HasNewVersion) { var title = String.Format("{0} {1}", AppViewModel.Instance.Locale["app_DownloadNoticeHeader"], AppViewModel.Instance.Locale["app_DownloadNoticeMessage"]); var message = new StringBuilder(); try { var latestBuildDateTime = new DateTime(2000, 1, 1).Add(new TimeSpan(TimeSpan.TicksPerDay * latestBuild.Build + TimeSpan.TicksPerSecond * 2 * latestBuild.Revision)); var currentBuildDateTime = new DateTime(2000, 1, 1).Add(new TimeSpan(TimeSpan.TicksPerDay * currentBuild.Build + TimeSpan.TicksPerSecond * 2 * currentBuild.Revision)); var timeSpan = latestBuildDateTime - currentBuildDateTime; if (timeSpan.TotalSeconds > 0) { message.AppendLine(String.Format("Missing {0} days, {1} hours and {2} seconds of updates.{3}", timeSpan.Days, timeSpan.Hours, timeSpan.Seconds)); } } catch (Exception ex) { } finally { message.AppendLine(AppViewModel.Instance.Locale["app_AlwaysReadUpdatesMessage"]); } MessageBoxHelper.ShowMessageAsync(title, message.ToString(), () => ShellView.CloseApplication(true), delegate { }); } var uri = "http://ffxiv-app.com/Analytics/Google/?eCategory=Application Launch&eAction=Version Check&eLabel=FFXIVAPP"; DispatcherHelper.Invoke(() => MainView.View.GoogleAnalytics.Navigate(uri)); } } } return(true); }; updateCheck.BeginInvoke(null, null); }
/// <summary> /// </summary> /// <param name="sender"></param> /// <param name="eventArgs"></param> private static void NotifyIconOnExitClick(object sender, EventArgs eventArgs) { DispatcherHelper.Invoke(() => ShellView.CloseApplication(), DispatcherPriority.Send); }
/// <summary> /// </summary> public static void CheckUpdates() { try { var updaters = Process.GetProcessesByName("FFXIVAPP.Updater"); foreach (var updater in updaters) { updater.Kill(); } if (File.Exists("FFXIVAPP.Updater.exe")) { File.Delete("FFXIVAPP.Updater.Backup.exe"); } else { if (File.Exists("FFXIVAPP.Updater.Backup.exe")) { File.Move("FFXIVAPP.Updater.Backup.exe", "FFXIVAPP.Updater.exe"); } } } catch (Exception ex) { } Func <bool> updateCheck = delegate { var current = Assembly.GetExecutingAssembly() .GetName() .Version.ToString(); AppViewModel.Instance.CurrentVersion = current; var httpWebRequest = (HttpWebRequest)WebRequest.Create(String.Format("http://ffxiv-app.com/Json/CurrentVersion/")); httpWebRequest.UserAgent = "Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10_6_3; en-US) AppleWebKit/533.4 (KHTML, like Gecko) Chrome/5.0.375.70 Safari/533.4"; httpWebRequest.Headers.Add("Accept-Language", "en;q=0.8"); httpWebRequest.ContentType = "application/json; charset=utf-8"; httpWebRequest.CachePolicy = new RequestCachePolicy(RequestCacheLevel.NoCacheNoStore); using (var httpResponse = (HttpWebResponse)httpWebRequest.GetResponse()) { using (var response = httpResponse.GetResponseStream()) { var responseText = ""; if (response != null) { using (var streamReader = new StreamReader(response)) { responseText = streamReader.ReadToEnd(); } } var latestBuild = new BuildNumber(); var currentBuild = new BuildNumber(); if (httpResponse.StatusCode != HttpStatusCode.OK || String.IsNullOrWhiteSpace(responseText)) { AppViewModel.Instance.HasNewVersion = false; AppViewModel.Instance.LatestVersion = "Unknown"; } else { var jsonResult = JObject.Parse(responseText); var latest = jsonResult["Version"].ToString(); var updateNotes = jsonResult["Notes"].ToList(); //var enabledFeatures = jsonResult["Features"]; //try //{ // foreach (var feature in enabledFeatures) // { // var key = feature["Hash"].ToString(); // var enabled = (bool) feature["Enabled"]; // switch (key) // { // case "E9FA3917-ACEB-47AE-88CC-58AB014058F5": // XIVDBViewModel.Instance.MonsterUploadEnabled = enabled; // break; // case "6D2DB102-B1AE-4249-9E73-4ABC7B1947BC": // XIVDBViewModel.Instance.NPCUploadEnabled = enabled; // break; // case "D95ADD76-7DA7-4692-AD00-DB12F2853908": // XIVDBViewModel.Instance.KillUploadEnabled = enabled; // break; // case "6A50A13B-BA83-45D7-862F-F110049E7E78": // XIVDBViewModel.Instance.LootUploadEnabled = enabled; // break; // } // } //} //catch (Exception ex) //{ //} try { foreach (var note in updateNotes.Select(updateNote => updateNote.Value <string>())) { AppViewModel.Instance.UpdateNotes.Add(note); } } catch (Exception ex) { MessageBoxHelper.ShowMessage("Error", ex.Message); } AppViewModel.Instance.DownloadUri = jsonResult["DownloadUri"].ToString(); latest = (latest == "Unknown") ? "Unknown" : String.Format("3{0}", latest.Substring(1)); AppViewModel.Instance.LatestVersion = latest; switch (latest) { case "Unknown": AppViewModel.Instance.HasNewVersion = false; break; default: AppViewModel.Instance.HasNewVersion = BuildUtilities.NeedsUpdate(latest, current, ref latestBuild, ref currentBuild); break; } if (AppViewModel.Instance.HasNewVersion) { var title = String.Format("{0} {1}", AppViewModel.Instance.Locale["app_DownloadNoticeHeader"], AppViewModel.Instance.Locale["app_DownloadNoticeMessage"]); var message = new StringBuilder(); try { var latestBuildDateTime = new DateTime(2000, 1, 1).Add(new TimeSpan(TimeSpan.TicksPerDay * latestBuild.Build + TimeSpan.TicksPerSecond * 2 * latestBuild.Revision)); var currentBuildDateTime = new DateTime(2000, 1, 1).Add(new TimeSpan(TimeSpan.TicksPerDay * currentBuild.Build + TimeSpan.TicksPerSecond * 2 * currentBuild.Revision)); var timeSpan = latestBuildDateTime - currentBuildDateTime; if (timeSpan.TotalSeconds > 0) { message.AppendLine(String.Format("Missing {0} days, {1} hours and {2} seconds of updates.{3}", timeSpan.Days, timeSpan.Hours, timeSpan.Seconds)); } } catch (Exception ex) { } finally { message.AppendLine(AppViewModel.Instance.Locale["app_AlwaysReadUpdatesMessage"]); } MessageBoxHelper.ShowMessageAsync(title, message.ToString(), () => ShellView.CloseApplication(true), delegate { }); } var uri = "http://ffxiv-app.com/Analytics/Google/?eCategory=Application Launch&eAction=Version Check&eLabel=FFXIVAPP"; DispatcherHelper.Invoke(() => MainView.View.GoogleAnalytics.Navigate(uri)); } } } return(true); }; updateCheck.BeginInvoke(null, null); }