From 508d23da5f6af43038fa95443b2acb48c3a98fc8 Mon Sep 17 00:00:00 2001 From: Jeddunk Date: Fri, 15 Jan 2021 17:46:13 +0100 Subject: [PATCH 01/36] Added Extensions.cs. Added GoldbergGlobalConfiguration. Code cleanup. --- .gitignore | 1 + GoldbergGUI.Core/Models/GoldbergModel.cs | 6 +++ GoldbergGUI.Core/Services/GoldbergService.cs | 42 ++++++++--------- GoldbergGUI.Core/Utils/Extensions.cs | 20 ++++++++ GoldbergGUI.Core/ViewModels/MainViewModel.cs | 49 +++++++++++--------- 5 files changed, 74 insertions(+), 44 deletions(-) create mode 100644 GoldbergGUI.Core/Utils/Extensions.cs diff --git a/.gitignore b/.gitignore index 1a57dee..7cf360d 100644 --- a/.gitignore +++ b/.gitignore @@ -542,3 +542,4 @@ MigrationBackup/ # End of https://www.toptal.com/developers/gitignore/api/intellij,rider,visualstudio,dotnetcore,windows /GoldbergGUI.Core/Utils/Secrets.cs +/README.bbcode diff --git a/GoldbergGUI.Core/Models/GoldbergModel.cs b/GoldbergGUI.Core/Models/GoldbergModel.cs index 724ce27..1906781 100644 --- a/GoldbergGUI.Core/Models/GoldbergModel.cs +++ b/GoldbergGUI.Core/Models/GoldbergModel.cs @@ -2,6 +2,12 @@ using System.Collections.Generic; namespace GoldbergGUI.Core.Models { + public class GoldbergGlobalConfiguration + { + public string AccountName { get; set; } + public long UserSteamId { get; set; } + public string Language { get; set; } + } public class GoldbergConfiguration { public int AppId { get; set; } diff --git a/GoldbergGUI.Core/Services/GoldbergService.cs b/GoldbergGUI.Core/Services/GoldbergService.cs index 83f32b5..e99e86a 100644 --- a/GoldbergGUI.Core/Services/GoldbergService.cs +++ b/GoldbergGUI.Core/Services/GoldbergService.cs @@ -8,6 +8,7 @@ using System.Text.RegularExpressions; using System.Threading; using System.Threading.Tasks; using GoldbergGUI.Core.Models; +using GoldbergGUI.Core.Utils; using MvvmCross.Logging; namespace GoldbergGUI.Core.Services @@ -17,11 +18,11 @@ namespace GoldbergGUI.Core.Services // does file copy stuff public interface IGoldbergService { - public Task<(string accountName, long userSteamId, string language)> Initialize(IMvxLog log); + public Task Initialize(IMvxLog log); public Task Read(string path); public Task Save(string path, GoldbergConfiguration configuration); - public Task<(string accountName, long steamId, string language)> GetGlobalSettings(); - public Task SetGlobalSettings(string accountName, long userSteamId, string language); + public Task GetGlobalSettings(); + public Task SetGlobalSettings(GoldbergGlobalConfiguration configuration); public bool GoldbergApplied(string path); public Task Download(); public Task Extract(string archivePath); @@ -76,7 +77,7 @@ namespace GoldbergGUI.Core.Services // Call Download // Get global settings - public async Task<(string accountName, long userSteamId, string language)> Initialize(IMvxLog log) + public async Task Initialize(IMvxLog log) { _log = log; @@ -85,7 +86,7 @@ namespace GoldbergGUI.Core.Services return await GetGlobalSettings().ConfigureAwait(false); } - public async Task<(string accountName, long steamId, string language)> GetGlobalSettings() + public async Task GetGlobalSettings() { _log.Info("Getting global settings..."); var accountName = "Account name..."; @@ -100,11 +101,19 @@ namespace GoldbergGUI.Core.Services _log.Error("Invalid User Steam ID!"); if (File.Exists(_languagePath)) language = File.ReadLines(_languagePath).First().Trim(); }).ConfigureAwait(false); - return (accountName, steamId, language); + return new GoldbergGlobalConfiguration + { + AccountName = accountName, + UserSteamId = steamId, + Language = language + }; } - public async Task SetGlobalSettings(string accountName, long userSteamId, string language) + public async Task SetGlobalSettings(GoldbergGlobalConfiguration c) { + var accountName = c.AccountName; + var userSteamId = c.UserSteamId; + var language = c.Language; _log.Info("Setting global settings..."); if (accountName != null && accountName != "Account name...") { @@ -324,16 +333,17 @@ namespace GoldbergGUI.Core.Services } } _log.Info("Starting download..."); - await StartDownload(client, match.Value).ConfigureAwait(false); + await StartDownload(match.Value).ConfigureAwait(false); return true; } - private async Task StartDownload(HttpClient client, string downloadUrl) + private async Task StartDownload(string downloadUrl) { + var client = new HttpClient(); _log.Debug(downloadUrl); await using var fileStream = File.OpenWrite(_goldbergZipPath); //client.GetAsync(downloadUrl, HttpCompletionOption.ResponseHeadersRead) - var task = GetFileAsync(client, downloadUrl, fileStream).ConfigureAwait(false); + var task = client.GetFileAsync(downloadUrl, fileStream).ConfigureAwait(false); await task; if (task.GetAwaiter().IsCompleted) { @@ -341,16 +351,6 @@ namespace GoldbergGUI.Core.Services } } - private static async Task GetFileAsync(HttpClient client, string requestUri, Stream destination, - CancellationToken cancelToken = default) - { - var response = await client.GetAsync(requestUri, HttpCompletionOption.ResponseHeadersRead, cancelToken) - .ConfigureAwait(false); - await using var download = await response.Content.ReadAsStreamAsync().ConfigureAwait(false); - await download.CopyToAsync(destination, cancelToken).ConfigureAwait(false); - if (destination.CanSeek) destination.Position = 0; - } - // Empty subfolder ./goldberg/ // Extract all from archive to subfolder ./goldberg/ public async Task Extract(string archivePath) @@ -361,7 +361,7 @@ namespace GoldbergGUI.Core.Services Directory.Delete(_goldbergPath, true); ZipFile.ExtractToDirectory(archivePath, _goldbergPath); }).ConfigureAwait(false); - _log.Debug("Extract done!"); + _log.Debug("Extraction done!"); } // https://gitlab.com/Mr_Goldberg/goldberg_emulator/-/blob/master/generate_interfaces_file.cpp diff --git a/GoldbergGUI.Core/Utils/Extensions.cs b/GoldbergGUI.Core/Utils/Extensions.cs new file mode 100644 index 0000000..2c03d9a --- /dev/null +++ b/GoldbergGUI.Core/Utils/Extensions.cs @@ -0,0 +1,20 @@ +using System.IO; +using System.Net.Http; +using System.Threading; +using System.Threading.Tasks; + +namespace GoldbergGUI.Core.Utils +{ + public static class Extensions + { + public static async Task GetFileAsync(this HttpClient client, string requestUri, Stream destination, + CancellationToken cancelToken = default) + { + var response = await client.GetAsync(requestUri, HttpCompletionOption.ResponseHeadersRead, cancelToken) + .ConfigureAwait(false); + await using var download = await response.Content.ReadAsStreamAsync().ConfigureAwait(false); + await download.CopyToAsync(destination, cancelToken).ConfigureAwait(false); + if (destination.CanSeek) destination.Position = 0; + } + } +} \ No newline at end of file diff --git a/GoldbergGUI.Core/ViewModels/MainViewModel.cs b/GoldbergGUI.Core/ViewModels/MainViewModel.cs index 667c1b4..8248d5e 100644 --- a/GoldbergGUI.Core/ViewModels/MainViewModel.cs +++ b/GoldbergGUI.Core/ViewModels/MainViewModel.cs @@ -12,7 +12,6 @@ using System.Windows; using GoldbergGUI.Core.Models; using GoldbergGUI.Core.Services; using Microsoft.Win32; -using MvvmCross; using MvvmCross.Commands; using MvvmCross.Logging; using MvvmCross.Navigation; @@ -71,11 +70,11 @@ namespace GoldbergGUI.Core.ViewModels SteamLanguages = new ObservableCollection(_goldberg.Languages()); ResetForm(); await _steam.Initialize(_logProvider.GetLogFor()).ConfigureAwait(false); - var (accountName, userSteamId, language) = + var globalConfiguration = await _goldberg.Initialize(_logProvider.GetLogFor()).ConfigureAwait(false); - AccountName = accountName; - SteamId = userSteamId; - SelectedLanguage = language; + AccountName = globalConfiguration.AccountName; + SteamId = globalConfiguration.UserSteamId; + SelectedLanguage = globalConfiguration.Language; } catch (Exception e) { @@ -221,7 +220,15 @@ namespace GoldbergGUI.Core.ViewModels } } - public bool DllSelected => !DllPath.Contains("Path to game's steam_api(64).dll"); + public bool DllSelected + { + get + { + var value = !DllPath.Contains("Path to game's steam_api(64).dll"); + if (!value) _log.Warn("No DLL selected! Skipping..."); + return value; + } + } public ObservableCollection SteamLanguages { @@ -389,12 +396,14 @@ namespace GoldbergGUI.Core.ViewModels private async Task SaveConfig() { _log.Info("Saving global settings..."); - await _goldberg.SetGlobalSettings(AccountName, SteamId, SelectedLanguage).ConfigureAwait(false); - if (!DllSelected) + var globalConfiguration = new GoldbergGlobalConfiguration { - _log.Error("No DLL selected!"); - return; - } + AccountName = AccountName, + UserSteamId = SteamId, + Language = SelectedLanguage + }; + await _goldberg.SetGlobalSettings(globalConfiguration).ConfigureAwait(false); + if (!DllSelected) return; _log.Info("Saving Goldberg settings..."); if (!GetDllPathDir(out var dirPath)) return; @@ -418,12 +427,11 @@ namespace GoldbergGUI.Core.ViewModels private async Task ResetConfig() { - (AccountName, SteamId, SelectedLanguage) = await _goldberg.GetGlobalSettings().ConfigureAwait(false); - if (!DllSelected) - { - _log.Error("No DLL selected!"); - return; - } + var globalConfiguration = await _goldberg.GetGlobalSettings().ConfigureAwait(false); + AccountName = globalConfiguration.AccountName; + SteamId = globalConfiguration.UserSteamId; + SelectedLanguage = globalConfiguration.Language; + if (!DllSelected) return; _log.Info("Reset form..."); MainWindowEnabled = false; @@ -437,11 +445,7 @@ namespace GoldbergGUI.Core.ViewModels private async Task GenerateSteamInterfaces() { - if (!DllSelected) - { - _log.Error("No DLL selected!"); - return; - } + if (!DllSelected) return; _log.Info("Generate steam_interfaces.txt..."); MainWindowEnabled = false; @@ -536,7 +540,6 @@ namespace GoldbergGUI.Core.ViewModels { if (!DllSelected) { - _log.Error("No DLL selected!"); dirPath = null; return false; } From 76f2d45f4531529fb63e0e1eafddd5586e9fc561 Mon Sep 17 00:00:00 2001 From: Jeddunk Date: Tue, 19 Jan 2021 13:23:31 +0100 Subject: [PATCH 02/36] Added UI elements for global options. Bigger minimal size for main window. --- GoldbergGUI.Core/ViewModels/MainViewModel.cs | 36 ++++++++++++++++++++ GoldbergGUI.WPF/GoldbergGUI.WPF.csproj | 16 +++++++++ GoldbergGUI.WPF/MainWindow.xaml | 2 +- GoldbergGUI.WPF/Views/MainView.xaml | 30 +++++++++++++++- 4 files changed, 82 insertions(+), 2 deletions(-) diff --git a/GoldbergGUI.Core/ViewModels/MainViewModel.cs b/GoldbergGUI.Core/ViewModels/MainViewModel.cs index 8248d5e..d5058c0 100644 --- a/GoldbergGUI.Core/ViewModels/MainViewModel.cs +++ b/GoldbergGUI.Core/ViewModels/MainViewModel.cs @@ -264,6 +264,26 @@ namespace GoldbergGUI.Core.ViewModels } } + public class GlobalHelp + { + public static string Header => + "Information\n"; + + public static string TextPreLink => + "Usually these settings are saved under"; + + public static string Link => "%APPDATA%\\Goldberg SteamEmu Saves\\settings"; + + public static string TextPostLink => + ", which makes these " + + "available for every game that uses the Goldberg Emulator. However, if you want to set specific settings " + + "for certain games (e.g. different language), you can remove the \"Global\" checkmark next to the option " + + "and then change it. If you want to remove that setting, just empty the field while \"Global\" is " + + "unchecked. (Not implemented yet!)"; + } + + public static GlobalHelp G => new GlobalHelp(); + // COMMANDS // public IMvxCommand OpenFileCommand => new MvxAsyncCommand(OpenFile); @@ -503,6 +523,22 @@ namespace GoldbergGUI.Core.ViewModels } }); + public IMvxCommand OpenGlobalSettingsFolderCommand => new MvxCommand(OpenGlobalSettingsFolder); + + private void OpenGlobalSettingsFolder() + { + if (!RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) + { + StatusText = "Can't open folder (Windows only)! Ready."; + return; + } + + var path = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), + "Goldberg SteamEmu Saves", "settings"); + var start = Process.Start("explorer.exe", path); + start?.Dispose(); + } + // OTHER METHODS // private void ResetForm() diff --git a/GoldbergGUI.WPF/GoldbergGUI.WPF.csproj b/GoldbergGUI.WPF/GoldbergGUI.WPF.csproj index 81eaa19..eb4287b 100644 --- a/GoldbergGUI.WPF/GoldbergGUI.WPF.csproj +++ b/GoldbergGUI.WPF/GoldbergGUI.WPF.csproj @@ -20,4 +20,20 @@ + + + + + + + + + + + + + + + + diff --git a/GoldbergGUI.WPF/MainWindow.xaml b/GoldbergGUI.WPF/MainWindow.xaml index 313c271..4d57311 100644 --- a/GoldbergGUI.WPF/MainWindow.xaml +++ b/GoldbergGUI.WPF/MainWindow.xaml @@ -5,6 +5,6 @@ xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" mc:Ignorable="d" - Title="GoldbergGUI" MinHeight="500" MinWidth="600" Background="#FFF0F0F0"> + Title="GoldbergGUI" MinHeight="600" MinWidth="800" Background="#FFF0F0F0"> \ No newline at end of file diff --git a/GoldbergGUI.WPF/Views/MainView.xaml b/GoldbergGUI.WPF/Views/MainView.xaml index 6f2ce2d..eff2105 100644 --- a/GoldbergGUI.WPF/Views/MainView.xaml +++ b/GoldbergGUI.WPF/Views/MainView.xaml @@ -96,20 +96,48 @@ + + + From 1602937be3888e6eb8b89cf9a9cd80ebdc174f83 Mon Sep 17 00:00:00 2001 From: Jeddunk Date: Tue, 19 Jan 2021 13:35:13 +0100 Subject: [PATCH 03/36] Automatically look up DLC when looking for AppID and when opening file with no config. --- GoldbergGUI.Core/ViewModels/MainViewModel.cs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/GoldbergGUI.Core/ViewModels/MainViewModel.cs b/GoldbergGUI.Core/ViewModels/MainViewModel.cs index d5058c0..587711b 100644 --- a/GoldbergGUI.Core/ViewModels/MainViewModel.cs +++ b/GoldbergGUI.Core/ViewModels/MainViewModel.cs @@ -309,6 +309,7 @@ namespace GoldbergGUI.Core.ViewModels DllPath = dialog.FileName; await ReadConfig().ConfigureAwait(false); + if (!GoldbergApplied) await GetListOfDlc().ConfigureAwait(false); MainWindowEnabled = true; StatusText = "Ready."; } @@ -365,7 +366,7 @@ namespace GoldbergGUI.Core.ViewModels await FindIdInList(steamApps).ConfigureAwait(false); } } - + await GetListOfDlc().ConfigureAwait(false); MainWindowEnabled = true; StatusText = "Ready."; } From 950844a14ba7fa693e22165100f288314fa934ec Mon Sep 17 00:00:00 2001 From: Jeddunk Date: Tue, 19 Jan 2021 20:37:13 +0100 Subject: [PATCH 04/36] Removed unused code. Minor code changes. --- GoldbergGUI.Core/Models/SteamAppModel.cs | 2 +- GoldbergGUI.Core/Services/SteamService.cs | 2 +- GoldbergGUI.Core/Utils/Misc.cs | 57 +++++++------------ GoldbergGUI.Core/ViewModels/MainViewModel.cs | 23 +------- GoldbergGUI.WPF/Views/MainView.xaml | 2 +- .../Views/SearchResultView.xaml.cs | 2 +- 6 files changed, 27 insertions(+), 61 deletions(-) diff --git a/GoldbergGUI.Core/Models/SteamAppModel.cs b/GoldbergGUI.Core/Models/SteamAppModel.cs index 0b5f79e..66bd139 100644 --- a/GoldbergGUI.Core/Models/SteamAppModel.cs +++ b/GoldbergGUI.Core/Models/SteamAppModel.cs @@ -24,7 +24,7 @@ namespace GoldbergGUI.Core.Models set { _name = value; - _comparableName = Regex.Replace(value, Misc.SpecialCharsRegex, "").ToLower(); + _comparableName = Regex.Replace(value, Misc.AlphaNumOnlyRegex, "").ToLower(); } } diff --git a/GoldbergGUI.Core/Services/SteamService.cs b/GoldbergGUI.Core/Services/SteamService.cs index 53d00fe..300961e 100644 --- a/GoldbergGUI.Core/Services/SteamService.cs +++ b/GoldbergGUI.Core/Services/SteamService.cs @@ -177,7 +177,7 @@ namespace GoldbergGUI.Core.Services public SteamApp GetAppByName(string name) { _log.Info($"Trying to get app {name}"); - var comparableName = Regex.Replace(name, Misc.SpecialCharsRegex, "").ToLower(); + var comparableName = Regex.Replace(name, Misc.AlphaNumOnlyRegex, "").ToLower(); var app = _caches[AppType.Game].Cache.FirstOrDefault(x => x.CompareName(comparableName)); if (app != null) _log.Info($"Successfully got app {app}"); return app; diff --git a/GoldbergGUI.Core/Utils/Misc.cs b/GoldbergGUI.Core/Utils/Misc.cs index 2a76437..6bf7df2 100644 --- a/GoldbergGUI.Core/Utils/Misc.cs +++ b/GoldbergGUI.Core/Utils/Misc.cs @@ -1,42 +1,25 @@ -using System.Collections.ObjectModel; - namespace GoldbergGUI.Core.Utils { - public class Misc + public static class Misc { - public const string SpecialCharsRegex = "[^0-9a-zA-Z]+"; - public const string DefaultLanguageSelection = "english"; - public static readonly ObservableCollection DefaultLanguages = new ObservableCollection(new[] - { - "arabic", - "bulgarian", - "schinese", - "tchinese", - "czech", - "danish", - "dutch", - "english", - "finnish", - "french", - "german", - "greek", - "hungarian", - "italian", - "japanese", - "koreana", - "norwegian", - "polish", - "portuguese", - "brazilian", - "romanian", - "russian", - "spanish", - "latam", - "swedish", - "thai", - "turkish", - "ukrainian", - "vietnamese" - }); + public const string AlphaNumOnlyRegex = "[^0-9a-zA-Z]+"; + } + + public class GlobalHelp + { + public static string Header => + "Information\n"; + + public static string TextPreLink => + "Usually these settings are saved under"; + + public static string Link => "%APPDATA%\\Goldberg SteamEmu Saves\\settings"; + + public static string TextPostLink => + ", which makes these " + + "available for every game that uses the Goldberg Emulator. However, if you want to set specific settings " + + "for certain games (e.g. different language), you can remove the \"Global\" checkmark next to the option " + + "and then change it. If you want to remove that setting, just empty the field while \"Global\" is " + + "unchecked. (Not implemented yet!)"; } } \ No newline at end of file diff --git a/GoldbergGUI.Core/ViewModels/MainViewModel.cs b/GoldbergGUI.Core/ViewModels/MainViewModel.cs index 587711b..a864d3c 100644 --- a/GoldbergGUI.Core/ViewModels/MainViewModel.cs +++ b/GoldbergGUI.Core/ViewModels/MainViewModel.cs @@ -11,6 +11,7 @@ using System.Threading.Tasks; using System.Windows; using GoldbergGUI.Core.Models; using GoldbergGUI.Core.Services; +using GoldbergGUI.Core.Utils; using Microsoft.Win32; using MvvmCross.Commands; using MvvmCross.Logging; @@ -251,9 +252,6 @@ namespace GoldbergGUI.Core.ViewModels } } - public string AboutVersionText => - FileVersionInfo.GetVersionInfo(Assembly.GetExecutingAssembly().Location).FileVersion; - public string StatusText { get => _statusText; @@ -264,23 +262,8 @@ namespace GoldbergGUI.Core.ViewModels } } - public class GlobalHelp - { - public static string Header => - "Information\n"; - - public static string TextPreLink => - "Usually these settings are saved under"; - - public static string Link => "%APPDATA%\\Goldberg SteamEmu Saves\\settings"; - - public static string TextPostLink => - ", which makes these " + - "available for every game that uses the Goldberg Emulator. However, if you want to set specific settings " + - "for certain games (e.g. different language), you can remove the \"Global\" checkmark next to the option " + - "and then change it. If you want to remove that setting, just empty the field while \"Global\" is " + - "unchecked. (Not implemented yet!)"; - } + public static string AboutVersionText => + FileVersionInfo.GetVersionInfo(Assembly.GetExecutingAssembly().Location).FileVersion; public static GlobalHelp G => new GlobalHelp(); diff --git a/GoldbergGUI.WPF/Views/MainView.xaml b/GoldbergGUI.WPF/Views/MainView.xaml index eff2105..62094dc 100644 --- a/GoldbergGUI.WPF/Views/MainView.xaml +++ b/GoldbergGUI.WPF/Views/MainView.xaml @@ -143,7 +143,7 @@ -