public RPCPreview(PresenceMessage msg) { InitializeComponent(); CurrentViewType = ViewType.RichPresence; UpdateBackground("Purple"); UpdateForeground(Brushes.White); tblTitle.Text = msg.Name; tblText1.Text = msg.Presence.Details; tblText2.Text = msg.Presence.State; UpdateTextVisibility(); tblTime.Visibility = Visibility.Visible; if (msg.Presence.HasAssets()) { recLargeImage.Visibility = Visibility.Collapsed; if (!string.IsNullOrEmpty(msg.Presence.Assets.LargeImageKey)) { recLargeImage.Visibility = Visibility.Visible; var largeImage = BitmapDownloader .DownloadImage(new System.Uri(Uri.Combine("https://cdn.discordapp.com/app-assets", msg.ApplicationID, msg.Presence.Assets.LargeImageID + ".png"))).ConfigureAwait(false) .GetAwaiter().GetResult(); recLargeImage.Fill = new ImageBrush(largeImage); if (!string.IsNullOrEmpty(msg.Presence.Assets.LargeImageText)) { recLargeImage.ToolTip = new ToolTip(msg.Presence.Assets.LargeImageText); } } else { recLargeImage.Fill = null; } if (!string.IsNullOrEmpty(msg.Presence.Assets.SmallImageKey) && recLargeImage.Visibility == Visibility.Visible) { var smallImage = BitmapDownloader .DownloadImage(new System.Uri(Uri.Combine("https://cdn.discordapp.com/app-assets", msg.ApplicationID, msg.Presence.Assets.SmallImageID + ".png"))).ConfigureAwait(false) .GetAwaiter().GetResult(); ellSmallImage.Fill = new ImageBrush(smallImage); if (!string.IsNullOrEmpty(msg.Presence.Assets.SmallImageText)) { ellSmallImage.ToolTip = new ToolTip(msg.Presence.Assets.SmallImageText); } } else { gridSmallImage.Visibility = Visibility.Collapsed; } } else { recLargeImage.Visibility = Visibility.Collapsed; gridSmallImage.Visibility = Visibility.Collapsed; } }
private async void WebClient_DownloadFileCompleted(object sender, AsyncCompletedEventArgs e) { bool doLogic; try { var uri = (System.Uri)((TaskCompletionSource <object>)e.UserState).Task.AsyncState; doLogic = uri.AbsoluteUri == Uri.Combine(App.MultiRPCWebsiteRoot, CreditsFileName); } catch (Exception ex) { App.Logging.Application(ex.Message); return; } if (!doLogic) { return; } if (File.Exists(CreditsFileLocalLocation)) { File.Delete(CreditsFileLocalLocation); } File.Move(CreditsFileLocalLocation + ".new", CreditsFileLocalLocation); _webClient.DownloadFileCompleted -= WebClient_DownloadFileCompleted; await UpdateCredits(); }
private async Task SetupLogic() { if (File.Exists(CreditsFileLocalLocation)) { UpdateCredits(); } _webClient.DownloadFileCompleted += WebClient_DownloadFileCompleted; var webFile = Uri.Combine(App.MultiRPCWebsiteRoot, CreditsFileName); DownloadFile: try { if (!Utils.NetworkIsAvailable()) { var second = 5; while (second != 0) { tblLastUpdated.Text = $"{App.Text.WaitingForInternetUpdate.Replace("{second}", second.ToString())}..."; await Task.Delay(1000); second--; } goto DownloadFile; } await _webClient.DownloadFileTaskAsync(webFile, CreditsFileLocalLocation + ".new"); } catch (Exception e) { App.Logging.Application(e.Message); if (File.Exists(CreditsFileLocalLocation + ".new")) { File.Delete(CreditsFileLocalLocation + ".new"); } if (_retryCount == App.RetryCount) { _webClient.DownloadFileCompleted -= WebClient_DownloadFileCompleted; await UpdateCredits(); } else { _retryCount++; goto DownloadFile; } } }
public static async Task Check(bool showNoUpdateMessage = false) { if (BeenUpdated) { return; } IsChecking = true; if (ApplicationDeployment.IsNetworkDeployed) { try { MainPage._MainPage.Dispatcher.Invoke(() => { MainPage._MainPage.pbUpdateProgress.Visibility = Visibility.Visible; MainPage._MainPage.pbUpdateProgress.IsIndeterminate = true; MainPage._MainPage.pbUpdateProgress.ToolTip = new ToolTip($"{App.Text.CheckingForUpdates}..."); }); if (Environment.OSVersion.Version.Major >= 6 && Environment.OSVersion.Version.Minor >= 1) { Application.Current.MainWindow.TaskbarItemInfo.ProgressState = TaskbarItemProgressState.Indeterminate; } var info = ApplicationDeployment.CurrentDeployment.CheckForDetailedUpdate(false); MainPage._MainPage.Dispatcher.Invoke(() => { MainPage._MainPage.pbUpdateProgress.IsIndeterminate = false; MainPage._MainPage.pbUpdateProgress.ToolTip = null; }); if (Environment.OSVersion.Version.Major >= 6 && Environment.OSVersion.Version.Minor >= 1) { Application.Current.MainWindow.TaskbarItemInfo.ProgressState = TaskbarItemProgressState.None; } if (info.UpdateAvailable) { try { using (var client = new WebClient()) { await client.DownloadFileTaskAsync( Uri.Combine(App.MultiRPCWebsiteRoot, "Changelog.txt"), FileLocations.ChangelogFileLocalLocation); } } catch { App.Logging.Application($"{App.Text.CouldntDownload} {App.Text.Changelog}"); } if (App.Config.AutoUpdate) { Start(); } else { var tick = DateTime.Now.Ticks; await Application.Current.Dispatcher.InvokeAsync(async() => { if (await MainWindow.OpenWindow(new UpdatePage(null, tick), true, tick, false) != null) { IsChecking = false; } }); IsChecking = false; } } else if (showNoUpdateMessage) { await CustomMessageBox.Show(App.Text.NoUpdate); } } catch { App.Logging.Error("App", App.Text.UpdateCheckFailed); MainPage._MainPage.Dispatcher.Invoke(() => { MainPage._MainPage.pbUpdateProgress.Visibility = Visibility.Collapsed; MainPage._MainPage.pbUpdateProgress.IsIndeterminate = false; MainPage._MainPage.pbUpdateProgress.ToolTip = null; }); if (Environment.OSVersion.Version.Major >= 6 && Environment.OSVersion.Version.Minor >= 1) { Application.Current.MainWindow.TaskbarItemInfo.ProgressState = TaskbarItemProgressState.None; } } } IsChecking = false; }