From c60ee90b0b54701d38d01c8935d5a5332821ff92 Mon Sep 17 00:00:00 2001 From: Joshua Askharoun Date: Thu, 6 May 2021 04:02:36 -0500 Subject: [PATCH] Added App Center analytics; Added downloaded progress to update dialog; Bumped version --- ZuneModdingHelper/App.xaml.cs | 14 +++++- ZuneModdingHelper/MainWindow.xaml.cs | 53 +++++++++++++++++++--- ZuneModdingHelper/ZuneModdingHelper.csproj | 2 + 3 files changed, 61 insertions(+), 8 deletions(-) diff --git a/ZuneModdingHelper/App.xaml.cs b/ZuneModdingHelper/App.xaml.cs index ab0fae4..3a653f6 100644 --- a/ZuneModdingHelper/App.xaml.cs +++ b/ZuneModdingHelper/App.xaml.cs @@ -1,5 +1,8 @@ using System; using System.Windows; +using Microsoft.AppCenter; +using Microsoft.AppCenter.Analytics; +using Microsoft.AppCenter.Crashes; namespace ZuneModdingHelper { @@ -10,7 +13,7 @@ namespace ZuneModdingHelper { public static string Title => "Zune Modding Helper"; - public static Version VersionNum => new(2021, 4, 26, 1); + public static Version VersionNum => new(2021, 5, 6, 0); public static string VersionStatus => "alpha"; public static string Version => VersionNum.ToString() + (VersionStatus != string.Empty ? "-" + VersionStatus : string.Empty); @@ -25,5 +28,14 @@ namespace ZuneModdingHelper bool isNewer = otherNum > VersionNum; return isNotAlpha || isNewer; } + + protected override void OnStartup(StartupEventArgs e) + { + base.OnStartup(e); + + // Set up App Center analytics + AppCenter.SetCountryCode(System.Globalization.RegionInfo.CurrentRegion.TwoLetterISORegionName); + AppCenter.Start("24903c19-b3d9-4ab5-b445-b981ca647125", typeof(Analytics), typeof(Crashes)); + } } } diff --git a/ZuneModdingHelper/MainWindow.xaml.cs b/ZuneModdingHelper/MainWindow.xaml.cs index 2b63866..70c582c 100644 --- a/ZuneModdingHelper/MainWindow.xaml.cs +++ b/ZuneModdingHelper/MainWindow.xaml.cs @@ -2,6 +2,7 @@ using Flurl.Http; using MahApps.Metro.Controls; using MahApps.Metro.Controls.Dialogs; +using Microsoft.AppCenter.Analytics; using Newtonsoft.Json.Linq; using OwlCore.AbstractUI.ViewModels; using System; @@ -72,10 +73,20 @@ namespace ZuneModdingHelper if (applyResult != null) { progDialog.SetMessage($"Failed to apply '{mod.Title}':\r\n{applyResult}"); + + Analytics.TrackEvent("Failed to apply mod", new Dictionary { + { "ModID", mod.Id }, + { "ErrorMessage", applyResult } + }); + await Task.Delay(15000); continue; } progDialog.SetProgress(++numCompleted); + + Analytics.TrackEvent("Applied mod", new Dictionary { + { "ModID", mod.Id }, + }); } await progDialog.CloseAsync(); @@ -106,15 +117,25 @@ namespace ZuneModdingHelper //} progDialog.SetMessage($"Resetting '{mod.Title}'"); - string applyResult = await mod.Reset(); - if (applyResult != null) + string resetResult = await mod.Reset(); + if (resetResult != null) { + Analytics.TrackEvent("Failed to reset mod", new Dictionary { + { "ModID", mod.Id }, + { "ErrorMessage", resetResult } + }); + await progDialog.CloseAsync(); - await this.ShowMessageAsync("Completed", $"Failed to reset '{mod.Title}':\r\n{applyResult}", settings: defaultMetroDialogSettings); + await this.ShowMessageAsync("Completed", $"Failed to reset '{mod.Title}':\r\n{resetResult}", settings: defaultMetroDialogSettings); return; } progDialog.SetProgress(++numCompleted); + + Analytics.TrackEvent("Reset mod", new Dictionary { + { "ModID", mod.Id }, + }); + await progDialog.CloseAsync(); await this.ShowMessageAsync("Completed", $"Successfully reset '{mod.Title}'", settings: defaultMetroDialogSettings); } @@ -147,6 +168,11 @@ namespace ZuneModdingHelper if (!App.CheckIfNewerVersion(latest["tag_name"].Value())) { // Already up-to-date + + Analytics.TrackEvent("Checked for updates", new Dictionary { + { "UpdatesFound", bool.FalseString }, + }); + await checkDialog.CloseAsync(); await this.ShowMessageAsync("No updates available", "You're already using the latest version.", settings: defaultMetroDialogSettings); return; @@ -164,10 +190,12 @@ namespace ZuneModdingHelper await checkDialog.CloseAsync(); var promptResult = await this.ShowMessageAsync("Update available", $"Relase {latest["name"]} is available. Would you like to download it now?", MessageDialogStyle.AffirmativeAndNegative, promptSettings); + bool acceptedUpdate = promptResult == MessageDialogResult.Affirmative; - if (promptResult == MessageDialogResult.Affirmative) + if (acceptedUpdate) { var progDialog = await this.ShowProgressAsync("Downloading update...", "This may take a few minutes.", settings: defaultMetroDialogSettings); + progDialog.Maximum = 100; progDialog.SetIndeterminate(); // Download new version to AppData @@ -177,6 +205,12 @@ namespace ZuneModdingHelper if (File.Exists(downloadedFile)) File.Delete(downloadedFile); using (var client = new System.Net.WebClient()) { + client.DownloadProgressChanged += (object sender, System.Net.DownloadProgressChangedEventArgs e) => { + // Update UI with download progress + progDialog.SetProgress(e.ProgressPercentage); + }; + + progDialog.SetProgress(0); await client.DownloadFileTaskAsync(new Uri(asset["browser_download_url"].Value()), downloadedFile); } @@ -185,14 +219,19 @@ namespace ZuneModdingHelper { FileName = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.UserProfile), "Downloads", assetName) }; - if (saveFileDialog.ShowDialog() == true) + bool dialogResult = saveFileDialog.ShowDialog() ?? false; + await progDialog.CloseAsync(); + if (dialogResult) { File.Copy(downloadedFile, saveFileDialog.FileName, true); - - await progDialog.CloseAsync(); await this.ShowMessageAsync("Update complete", "You may now exit this program and open the new version.", settings: defaultMetroDialogSettings); } } + + Analytics.TrackEvent("Checked for updates", new Dictionary { + { "UpdatesFound", bool.TrueString }, + { "Accepted", acceptedUpdate.ToString() }, + }); } } } diff --git a/ZuneModdingHelper/ZuneModdingHelper.csproj b/ZuneModdingHelper/ZuneModdingHelper.csproj index 985985d..64d92e4 100644 --- a/ZuneModdingHelper/ZuneModdingHelper.csproj +++ b/ZuneModdingHelper/ZuneModdingHelper.csproj @@ -14,6 +14,8 @@ + +