From 1d53a2f34ac42d7b72f3d5ca3239dd270091b05b Mon Sep 17 00:00:00 2001 From: Philip Date: Thu, 17 Aug 2023 09:49:37 +0200 Subject: [PATCH 1/6] - In case of an unhandled exception, you can now navigate directly to the error logs - Downloader now pulls the filename from the request header instead of the game object - In the admin console, you can now jump directly to the profiles - Bug fix: a long error message in the download tab, no longer rescales the individual elements --- gamevault/App.xaml.cs | 10 ++++++-- .../Helper/HttpClientDownloadWithProgress.cs | 23 ++++++++++++------- .../UserControls/AdminConsoleUserControl.xaml | 2 +- .../AdminConsoleUserControl.xaml.cs | 7 ++++++ .../UserControls/CommunityUserControl.xaml.cs | 14 ++++++++++- .../UserControls/GameDownloadUserControl.xaml | 2 +- .../GameDownloadUserControl.xaml.cs | 2 +- gamevault/ViewModels/SettingsViewModel.cs | 2 +- 8 files changed, 47 insertions(+), 15 deletions(-) diff --git a/gamevault/App.xaml.cs b/gamevault/App.xaml.cs index 3870a3d..31ef66d 100644 --- a/gamevault/App.xaml.cs +++ b/gamevault/App.xaml.cs @@ -35,6 +35,7 @@ private async void Application_Startup(object sender, StartupEventArgs e) { Application.Current.DispatcherUnhandledException += new DispatcherUnhandledExceptionEventHandler(AppDispatcherUnhandledException); + try { NewNameMigrationHelper.MigrateIfNeeded(); @@ -101,7 +102,7 @@ private void AppDispatcherUnhandledException(object sender, DispatcherUnhandledE { ProcessShepherd.KillAllChildProcesses(); #if DEBUG - e.Handled = false; + e.Handled = false; #else LogUnhandledException(e); #endif @@ -121,7 +122,12 @@ void LogUnhandledException(DispatcherUnhandledExceptionEventArgs e) { e.Handled = true; LogUnhandledException(e.Exception); - System.Windows.MessageBox.Show("Something went wrong. View error log for more details", "Unhandled Exception", MessageBoxButton.OK, MessageBoxImage.Warning); + MessageBoxResult result = System.Windows.MessageBox.Show("Something went wrong. View error log for more details.\nDo you want to open the error logs?", "Unhandled Exception", MessageBoxButton.YesNo, MessageBoxImage.Warning); + if (result == MessageBoxResult.Yes) + { + if (Directory.Exists(AppFilePath.ErrorLog)) + Process.Start("explorer.exe", AppFilePath.ErrorLog.Replace(@"\\",@"\").Replace("/",@"\")); + } ShutdownApp(); } private void StartServer() diff --git a/gamevault/Helper/HttpClientDownloadWithProgress.cs b/gamevault/Helper/HttpClientDownloadWithProgress.cs index 1f8ad0a..70bd150 100644 --- a/gamevault/Helper/HttpClientDownloadWithProgress.cs +++ b/gamevault/Helper/HttpClientDownloadWithProgress.cs @@ -15,7 +15,8 @@ namespace gamevault.Helper public class HttpClientDownloadWithProgress : IDisposable { private readonly string _downloadUrl; - private readonly string _destinationFilePath; + private readonly string _destinationFolderPath; + private string _fileName; private bool _Cancelled = false; private DateTime lastTime; private HttpClient _httpClient; @@ -24,10 +25,10 @@ public class HttpClientDownloadWithProgress : IDisposable public event ProgressChangedHandler ProgressChanged; - public HttpClientDownloadWithProgress(string downloadUrl, string destinationFilePath) + public HttpClientDownloadWithProgress(string downloadUrl, string destinationFolderPath) { _downloadUrl = downloadUrl; - _destinationFilePath = destinationFilePath; + _destinationFolderPath = destinationFolderPath; } public async Task StartDownload() @@ -45,6 +46,11 @@ private async Task DownloadFileFromHttpResponseMessage(HttpResponseMessage respo { response.EnsureSuccessStatusCode(); + _fileName = response.Content.Headers.ContentDisposition.FileName.Replace("\"", ""); + if(string.IsNullOrEmpty(_fileName)) + { + throw new Exception("Incomplete request header"); + } var totalBytes = response.Content.Headers.ContentLength; using (var contentStream = await response.Content.ReadAsStreamAsync()) @@ -53,11 +59,12 @@ private async Task DownloadFileFromHttpResponseMessage(HttpResponseMessage respo private async Task ProcessContentStream(long? totalDownloadSize, Stream contentStream) { - var totalBytesRead = 0L; + var totalBytesRead = 0L; var buffer = new byte[8192]; var isMoreToRead = true; lastTime = DateTime.Now; - using (var fileStream = new FileStream(_destinationFilePath, FileMode.Create, FileAccess.Write, FileShare.None, 8192, true)) + string fullFilePath = $"{_destinationFolderPath}\\{_fileName}"; + using (var fileStream = new FileStream(fullFilePath, FileMode.Create, FileAccess.Write, FileShare.None, 8192, true)) { do { @@ -66,7 +73,7 @@ private async Task ProcessContentStream(long? totalDownloadSize, Stream contentS fileStream.Close(); try { - File.Delete(_destinationFilePath); + File.Delete(fullFilePath); } catch { } return; @@ -84,10 +91,10 @@ private async Task ProcessContentStream(long? totalDownloadSize, Stream contentS totalBytesRead += bytesRead; //readCount += 1; - if((DateTime.Now - lastTime).TotalSeconds > 2) + if ((DateTime.Now - lastTime).TotalSeconds > 2) { TriggerProgressChanged(totalDownloadSize, totalBytesRead); - lastTime = DateTime.Now; + lastTime = DateTime.Now; } //if (readCount % 100 == 0) // TriggerProgressChanged(totalDownloadSize, totalBytesRead); diff --git a/gamevault/UserControls/AdminConsoleUserControl.xaml b/gamevault/UserControls/AdminConsoleUserControl.xaml index 764a389..c007afc 100644 --- a/gamevault/UserControls/AdminConsoleUserControl.xaml +++ b/gamevault/UserControls/AdminConsoleUserControl.xaml @@ -47,7 +47,7 @@ - + diff --git a/gamevault/UserControls/AdminConsoleUserControl.xaml.cs b/gamevault/UserControls/AdminConsoleUserControl.xaml.cs index 29bae65..e4004cb 100644 --- a/gamevault/UserControls/AdminConsoleUserControl.xaml.cs +++ b/gamevault/UserControls/AdminConsoleUserControl.xaml.cs @@ -172,5 +172,12 @@ private async Task HandleChangesOnCurrentUser(User selectedUser) await InitUserList(); await MainWindowViewModel.Instance.Community.InitUserList(); } + + private void ShowUser_Click(object sender, MouseButtonEventArgs e) + { + User selectedUser = ((FrameworkElement)sender).DataContext as User; + MainWindowViewModel.Instance.SetActiveControl(MainControl.Community); + MainWindowViewModel.Instance.Community.ShowUser(selectedUser); + } } } diff --git a/gamevault/UserControls/CommunityUserControl.xaml.cs b/gamevault/UserControls/CommunityUserControl.xaml.cs index 0dfbe28..12e2a8e 100644 --- a/gamevault/UserControls/CommunityUserControl.xaml.cs +++ b/gamevault/UserControls/CommunityUserControl.xaml.cs @@ -35,7 +35,19 @@ public async Task InitUserList() return users; }); } - + internal void ShowUser(User userToShow) + { + for (int count = 0; count < ViewModel.Users.Length; count++) + { + if (ViewModel.Users[count].ID == userToShow.ID) + { + if (uiSelectUser.SelectedIndex != count) + { + uiSelectUser.SelectedIndex = count; + } + } + } + } private async void Users_SelectionChanged(object sender, SelectionChangedEventArgs e) { try diff --git a/gamevault/UserControls/GameDownloadUserControl.xaml b/gamevault/UserControls/GameDownloadUserControl.xaml index fb7e62e..a445b26 100644 --- a/gamevault/UserControls/GameDownloadUserControl.xaml +++ b/gamevault/UserControls/GameDownloadUserControl.xaml @@ -21,7 +21,7 @@ - + diff --git a/gamevault/UserControls/GameDownloadUserControl.xaml.cs b/gamevault/UserControls/GameDownloadUserControl.xaml.cs index 4ba293b..3e52b65 100644 --- a/gamevault/UserControls/GameDownloadUserControl.xaml.cs +++ b/gamevault/UserControls/GameDownloadUserControl.xaml.cs @@ -103,7 +103,7 @@ private void DownloadGame() ViewModel.DownloadFailedVisibility = System.Windows.Visibility.Hidden; if (!Directory.Exists(m_DownloadPath)) { Directory.CreateDirectory(m_DownloadPath); } - client = new HttpClientDownloadWithProgress($"{SettingsViewModel.Instance.ServerUrl}/api/v1/games/{ViewModel.Game.ID}/download", $"{m_DownloadPath}\\{Path.GetFileName(ViewModel.Game.FilePath)}"); + client = new HttpClientDownloadWithProgress($"{SettingsViewModel.Instance.ServerUrl}/api/v1/games/{ViewModel.Game.ID}/download", m_DownloadPath); client.ProgressChanged += DownloadProgress; startTime = DateTime.Now; diff --git a/gamevault/ViewModels/SettingsViewModel.cs b/gamevault/ViewModels/SettingsViewModel.cs index a736eaf..9d95c05 100644 --- a/gamevault/ViewModels/SettingsViewModel.cs +++ b/gamevault/ViewModels/SettingsViewModel.cs @@ -130,7 +130,7 @@ public string Version { get { - return "1.3.0"; + return "1.3.1"; } } From 781bdce08b31d2d73b916a72493a69f9f7e9c32d Mon Sep 17 00:00:00 2001 From: Philip Date: Thu, 17 Aug 2023 23:29:33 +0200 Subject: [PATCH 2/6] Support singe file binary --- gamevault/UserControls/GameDownloadUserControl.xaml | 2 +- .../UserControls/GameDownloadUserControl.xaml.cs | 11 ++++++++++- gamevault/ViewModels/GameDownloadViewModel.cs | 9 ++++++++- 3 files changed, 19 insertions(+), 3 deletions(-) diff --git a/gamevault/UserControls/GameDownloadUserControl.xaml b/gamevault/UserControls/GameDownloadUserControl.xaml index a445b26..9dcdabc 100644 --- a/gamevault/UserControls/GameDownloadUserControl.xaml +++ b/gamevault/UserControls/GameDownloadUserControl.xaml @@ -18,7 +18,7 @@ - + diff --git a/gamevault/UserControls/GameDownloadUserControl.xaml.cs b/gamevault/UserControls/GameDownloadUserControl.xaml.cs index 3e52b65..0e92ec4 100644 --- a/gamevault/UserControls/GameDownloadUserControl.xaml.cs +++ b/gamevault/UserControls/GameDownloadUserControl.xaml.cs @@ -1,11 +1,13 @@ ๏ปฟusing gamevault.Helper; using gamevault.Models; using gamevault.ViewModels; +using ImageMagick.Formats; using MahApps.Metro.Controls; using MahApps.Metro.Controls.Dialogs; using System; using System.Diagnostics; using System.IO; +using System.Linq; using System.Threading.Tasks; using System.Windows; using System.Windows.Controls; @@ -235,6 +237,13 @@ private void ExtractionProgress(object sender, SevenZipProgressEventArgs e) private async void Extract_Click(object sender, System.Windows.Input.MouseButtonEventArgs e) { + DirectoryInfo dirInf = new DirectoryInfo(m_DownloadPath); + FileInfo[] files = dirInf.GetFiles().Where(f => ViewModel.SupportedArchives.Contains(f.Extension.ToLower())).ToArray(); + if (files.Length <= 0) + { + ViewModel.State = "No archive found"; + return; + } uiBtnInstall.IsEnabled = false; ViewModel.ExtractionUIVisibility = System.Windows.Visibility.Hidden; ViewModel.State = "Extracting..."; @@ -242,7 +251,7 @@ private async void Extract_Click(object sender, System.Windows.Input.MouseButton sevenZipHelper.Process += ExtractionProgress; startTime = DateTime.Now; - int result = await sevenZipHelper.ExtractArchive($"{m_DownloadPath}\\{Path.GetFileName(ViewModel.Game.FilePath)}", $"{m_DownloadPath}\\Extract"); + int result = await sevenZipHelper.ExtractArchive($"{m_DownloadPath}\\{files[0].Name}", $"{m_DownloadPath}\\Extract"); if (result == 0) { if (!File.Exists($"{m_DownloadPath}\\Extract\\gamevault-metadata")) diff --git a/gamevault/ViewModels/GameDownloadViewModel.cs b/gamevault/ViewModels/GameDownloadViewModel.cs index bb504e3..531f609 100644 --- a/gamevault/ViewModels/GameDownloadViewModel.cs +++ b/gamevault/ViewModels/GameDownloadViewModel.cs @@ -16,7 +16,7 @@ internal class GameDownloadViewModel : ViewModelBase private Game m_Game { get; set; } private string m_State { get; set; } private int m_GameDownloadProgress { get; set; } - private int m_GameExtractionProgress { get; set; } + private int m_GameExtractionProgress { get; set; } private string m_DownloadInfo { get; set; } private string m_ExtractionInfo { get; set; } private string m_InstallPath { get; set; } @@ -77,5 +77,12 @@ public string InstallPath get { return m_InstallPath; } set { m_InstallPath = value; OnPropertyChanged(); } } + public string[] SupportedArchives + { + get + { + return new string[] { ".7z", ".xz", ".bz2", ".gz", ".tar", ".zip", ".wim", ".ar", ".arj", ".cab", ".chm", ".cpio", ".cramfs", ".dmg", ".ext", ".fat", ".gpt", ".hfs", ".ihex", ".iso", ".lzh", ".lzma", ".mbr", ".msi", ".nsis", ".ntfs", ".qcow2", ".rar", ".rpm", ".squashfs", ".udf", ".uefi", ".vdi", ".vhd", ".vmdk", ".wim", ".xar", ".z" }; + } + } } } From fad027a85a9eff2955bd3fda8d7966d8ed45ec02 Mon Sep 17 00:00:00 2001 From: Philip Date: Fri, 18 Aug 2023 00:31:26 +0200 Subject: [PATCH 3/6] Handle Undetected game type in installation --- gamevault/UserControls/DownloadsUserControl.xaml | 2 +- .../UserControls/GameDownloadUserControl.xaml | 16 ++++++++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/gamevault/UserControls/DownloadsUserControl.xaml b/gamevault/UserControls/DownloadsUserControl.xaml index 0330baf..f5f4490 100644 --- a/gamevault/UserControls/DownloadsUserControl.xaml +++ b/gamevault/UserControls/DownloadsUserControl.xaml @@ -35,7 +35,7 @@ - + diff --git a/gamevault/UserControls/GameDownloadUserControl.xaml b/gamevault/UserControls/GameDownloadUserControl.xaml index 9dcdabc..5744f3c 100644 --- a/gamevault/UserControls/GameDownloadUserControl.xaml +++ b/gamevault/UserControls/GameDownloadUserControl.xaml @@ -147,6 +147,22 @@ + + + + + + + + + From c222d0a57e9c1acfff2eb8c3b08ed9648de825bc Mon Sep 17 00:00:00 2001 From: Philip Date: Fri, 18 Aug 2023 16:50:23 +0200 Subject: [PATCH 4/6] - The selectable executables are now trimmed, in the installation tab - Removed unneeded scroll arrows on library edit screen --- CHANGELOG.md | 10 ++++++++ .../GameDownloadUserControl.xaml.cs | 7 +++--- .../UserControls/GameInstallUserControl.xaml | 2 +- .../GameInstallUserControl.xaml.cs | 24 +++++++++++-------- .../UserControls/GameViewUserControl.xaml | 2 +- gamevault/ViewModels/GameInstallViewModel.cs | 6 ++--- gamevault/ViewModels/SettingsViewModel.cs | 2 +- 7 files changed, 33 insertions(+), 20 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index d8fcb89..31b209a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,15 @@ # GameVault App Changelog +## 1.4.0 +### Changes +- In case of an unhandled exception, you can now navigate directly to the error logs +- In the admin console, you can now jump directly to the profiles +- Support single file binary +- The selectable executables are now trimmed in the installation tab +- Bug fix: Dealing with undiscovered games in the installation process +- Bug fix: A long error message in the download tab, no longer rescales the individual elements +- Bug fix: Download speed not shown, when it's KB/s and below + ## 1.3.0 ### Changes - Installation pipeline implemented. The UI for the download tab has been completely overhauled. GameVault is now able to extract downloaded game archives and perform the installation process depending on the game type. diff --git a/gamevault/UserControls/GameDownloadUserControl.xaml.cs b/gamevault/UserControls/GameDownloadUserControl.xaml.cs index 0e92ec4..4368a34 100644 --- a/gamevault/UserControls/GameDownloadUserControl.xaml.cs +++ b/gamevault/UserControls/GameDownloadUserControl.xaml.cs @@ -172,18 +172,17 @@ private void CancelExtraction_Click(object sender, System.Windows.Input.MouseBut } private string CalculateSpeed(double size, double tspan) { - string message = string.Empty; if (size / tspan > 1024 * 1024) // MB { - return $"{message} {Math.Round(size / (1024 * 1204) / tspan, 2)} MB/s"; //string.Format(message, size / (1024 * 1204) / tspan, "MB/s"); + return $"{Math.Round(size / (1024 * 1204) / tspan, 2)} MB/s"; } else if (size / tspan > 1024) // KB { - return string.Format(message, size / (1024) / tspan, "KB/s"); + return $"{Math.Round(size / (1024) / tspan, 2)} KB/s"; } else { - return string.Format(message, size / tspan, "B/s"); + return $"{Math.Round(size / tspan, 2)} B/s"; } } diff --git a/gamevault/UserControls/GameInstallUserControl.xaml b/gamevault/UserControls/GameInstallUserControl.xaml index 6d10bf7..8d1b489 100644 --- a/gamevault/UserControls/GameInstallUserControl.xaml +++ b/gamevault/UserControls/GameInstallUserControl.xaml @@ -18,7 +18,7 @@ - +