From 651836182492b420f2e1a6d90c01180c95147eef Mon Sep 17 00:00:00 2001 From: Jeddunk Date: Thu, 12 May 2022 21:40:28 +0200 Subject: [PATCH] update dependencies --- GoldbergGUI.Core/GoldbergGUI.Core.csproj | 10 +- GoldbergGUI.Core/Services/GoldbergService.cs | 124 +++++++++--------- GoldbergGUI.Core/Services/SteamService.cs | 52 ++++---- GoldbergGUI.Core/ViewModels/MainViewModel.cs | 42 +++--- .../ViewModels/SearchResultViewModel.cs | 10 +- GoldbergGUI.WPF/GoldbergGUI.WPF.csproj | 9 +- GoldbergGUI.WPF/Setup.cs | 13 +- 7 files changed, 132 insertions(+), 128 deletions(-) diff --git a/GoldbergGUI.Core/GoldbergGUI.Core.csproj b/GoldbergGUI.Core/GoldbergGUI.Core.csproj index 865a61b..6d27c2c 100644 --- a/GoldbergGUI.Core/GoldbergGUI.Core.csproj +++ b/GoldbergGUI.Core/GoldbergGUI.Core.csproj @@ -8,12 +8,12 @@ - - + + - - - + + + diff --git a/GoldbergGUI.Core/Services/GoldbergService.cs b/GoldbergGUI.Core/Services/GoldbergService.cs index 6b7bcfa..40bca24 100644 --- a/GoldbergGUI.Core/Services/GoldbergService.cs +++ b/GoldbergGUI.Core/Services/GoldbergService.cs @@ -1,6 +1,6 @@ using GoldbergGUI.Core.Models; using GoldbergGUI.Core.Utils; -using MvvmCross.Logging; +using Microsoft.Extensions.Logging; using System; using System.Collections.Generic; using System.IO; @@ -18,7 +18,7 @@ namespace GoldbergGUI.Core.Services // does file copy stuff public interface IGoldbergService { - public Task Initialize(IMvxLog log); + public Task Initialize(ILogger log); public Task Read(string path); public Task Save(string path, GoldbergConfiguration configuration); public Task GetGlobalSettings(); @@ -32,7 +32,7 @@ namespace GoldbergGUI.Core.Services // ReSharper disable once ClassNeverInstantiated.Global public class GoldbergService : IGoldbergService { - private IMvxLog _log; + private ILogger _log; private const string DefaultAccountName = "Mr_Goldberg"; private const long DefaultSteamId = 76561197960287930; private const string DefaultLanguage = "english"; @@ -82,7 +82,7 @@ namespace GoldbergGUI.Core.Services // Call Download // Get global settings - public async Task Initialize(IMvxLog log) + public async Task Initialize(ILogger log) { _log = log; @@ -97,7 +97,7 @@ namespace GoldbergGUI.Core.Services public async Task GetGlobalSettings() { - _log.Info("Getting global settings..."); + _log.LogInformation("Getting global settings..."); var accountName = DefaultAccountName; var steamId = DefaultSteamId; var language = DefaultLanguage; @@ -110,7 +110,7 @@ namespace GoldbergGUI.Core.Services !long.TryParse(File.ReadLines(_userSteamIdPath).First().Trim(), out steamId) && steamId < 76561197960265729 && steamId > 76561202255233023) { - _log.Error("Invalid User Steam ID! Using default Steam ID..."); + _log.LogError("Invalid User Steam ID! Using default Steam ID..."); steamId = DefaultSteamId; } @@ -119,7 +119,7 @@ namespace GoldbergGUI.Core.Services customBroadcastIps.AddRange( File.ReadLines(_customBroadcastIpsPath).Select(line => line.Trim())); }).ConfigureAwait(false); - _log.Info("Got global settings."); + _log.LogInformation("Got global settings."); return new GoldbergGlobalConfiguration { AccountName = accountName, @@ -135,18 +135,18 @@ namespace GoldbergGUI.Core.Services var userSteamId = c.UserSteamId; var language = c.Language; var customBroadcastIps = c.CustomBroadcastIps; - _log.Info("Setting global settings..."); + _log.LogInformation("Setting global settings..."); // Account Name if (!string.IsNullOrEmpty(accountName)) { - _log.Info("Setting account name..."); + _log.LogInformation("Setting account name..."); if (!File.Exists(_accountNamePath)) await File.Create(_accountNamePath).DisposeAsync().ConfigureAwait(false); await File.WriteAllTextAsync(_accountNamePath, accountName).ConfigureAwait(false); } else { - _log.Info("Invalid account name! Skipping..."); + _log.LogInformation("Invalid account name! Skipping..."); if (!File.Exists(_accountNamePath)) await File.Create(_accountNamePath).DisposeAsync().ConfigureAwait(false); await File.WriteAllTextAsync(_accountNamePath, DefaultAccountName).ConfigureAwait(false); @@ -155,14 +155,14 @@ namespace GoldbergGUI.Core.Services // User SteamID if (userSteamId >= 76561197960265729 && userSteamId <= 76561202255233023) { - _log.Info("Setting user Steam ID..."); + _log.LogInformation("Setting user Steam ID..."); if (!File.Exists(_userSteamIdPath)) await File.Create(_userSteamIdPath).DisposeAsync().ConfigureAwait(false); await File.WriteAllTextAsync(_userSteamIdPath, userSteamId.ToString()).ConfigureAwait(false); } else { - _log.Info("Invalid user Steam ID! Skipping..."); + _log.LogInformation("Invalid user Steam ID! Skipping..."); if (!File.Exists(_userSteamIdPath)) await File.Create(_userSteamIdPath).DisposeAsync().ConfigureAwait(false); await File.WriteAllTextAsync(_userSteamIdPath, DefaultSteamId.ToString()).ConfigureAwait(false); @@ -171,14 +171,14 @@ namespace GoldbergGUI.Core.Services // Language if (!string.IsNullOrEmpty(language)) { - _log.Info("Setting language..."); + _log.LogInformation("Setting language..."); if (!File.Exists(_languagePath)) await File.Create(_languagePath).DisposeAsync().ConfigureAwait(false); await File.WriteAllTextAsync(_languagePath, language).ConfigureAwait(false); } else { - _log.Info("Invalid language! Skipping..."); + _log.LogInformation("Invalid language! Skipping..."); if (!File.Exists(_languagePath)) await File.Create(_languagePath).DisposeAsync().ConfigureAwait(false); await File.WriteAllTextAsync(_languagePath, DefaultLanguage).ConfigureAwait(false); @@ -187,7 +187,7 @@ namespace GoldbergGUI.Core.Services // Custom Broadcast IPs if (customBroadcastIps != null && customBroadcastIps.Count > 0) { - _log.Info("Setting custom broadcast IPs..."); + _log.LogInformation("Setting custom broadcast IPs..."); var result = customBroadcastIps.Aggregate("", (current, address) => $"{current}{address}\n"); if (!File.Exists(_customBroadcastIpsPath)) @@ -196,50 +196,50 @@ namespace GoldbergGUI.Core.Services } else { - _log.Info("Empty list of custom broadcast IPs! Skipping..."); + _log.LogInformation("Empty list of custom broadcast IPs! Skipping..."); await Task.Run(() => File.Delete(_customBroadcastIpsPath)).ConfigureAwait(false); } - _log.Info("Setting global configuration finished."); + _log.LogInformation("Setting global configuration finished."); } // If first time, call GenerateInterfaces // else try to read config public async Task Read(string path) { - _log.Info("Reading configuration..."); + _log.LogInformation("Reading configuration..."); var appId = -1; var achievementList = new List(); var dlcList = new List(); var steamAppidTxt = Path.Combine(path, "steam_appid.txt"); if (File.Exists(steamAppidTxt)) { - _log.Info("Getting AppID..."); + _log.LogInformation("Getting AppID..."); await Task.Run(() => int.TryParse(File.ReadLines(steamAppidTxt).First().Trim(), out appId)) .ConfigureAwait(false); } else { - _log.Info(@"""steam_appid.txt"" missing! Skipping..."); + _log.LogInformation(@"""steam_appid.txt"" missing! Skipping..."); } var achievementJson = Path.Combine(path, "steam_settings", "achievements.json"); if (File.Exists(achievementJson)) { - _log.Info("Getting achievements..."); + _log.LogInformation("Getting achievements..."); var json = await File.ReadAllTextAsync(achievementJson) .ConfigureAwait(false); achievementList = System.Text.Json.JsonSerializer.Deserialize>(json); } else { - _log.Info(@"""steam_settings/achievements.json"" missing! Skipping..."); + _log.LogInformation(@"""steam_settings/achievements.json"" missing! Skipping..."); } var dlcTxt = Path.Combine(path, "steam_settings", "DLC.txt"); var appPathTxt = Path.Combine(path, "steam_settings", "app_paths.txt"); if (File.Exists(dlcTxt)) { - _log.Info("Getting DLCs..."); + _log.LogInformation("Getting DLCs..."); var readAllLinesAsync = await File.ReadAllLinesAsync(dlcTxt).ConfigureAwait(false); var expression = new Regex(@"(?.*) *= *(?.*)"); // ReSharper disable once LoopCanBeConvertedToQuery @@ -271,7 +271,7 @@ namespace GoldbergGUI.Core.Services } else { - _log.Info(@"""steam_settings/DLC.txt"" missing! Skipping..."); + _log.LogInformation(@"""steam_settings/DLC.txt"" missing! Skipping..."); } return new GoldbergConfiguration @@ -291,9 +291,9 @@ namespace GoldbergGUI.Core.Services // Save configuration files public async Task Save(string path, GoldbergConfiguration c) { - _log.Info("Saving configuration..."); + _log.LogInformation("Saving configuration..."); // DLL setup - _log.Info("Running DLL setup..."); + _log.LogInformation("Running DLL setup..."); const string x86Name = "steam_api"; const string x64Name = "steam_api64"; if (File.Exists(Path.Combine(path, $"{x86Name}.dll"))) @@ -305,10 +305,10 @@ namespace GoldbergGUI.Core.Services { CopyDllFiles(path, x64Name); } - _log.Info("DLL setup finished!"); + _log.LogInformation("DLL setup finished!"); // Create steam_settings folder if missing - _log.Info("Saving settings..."); + _log.LogInformation("Saving settings..."); if (!Directory.Exists(Path.Combine(path, "steam_settings"))) { Directory.CreateDirectory(Path.Combine(path, "steam_settings")); @@ -321,7 +321,7 @@ namespace GoldbergGUI.Core.Services // Achievements + Images if (c.Achievements.Count > 0) { - _log.Info("Downloading images..."); + _log.LogInformation("Downloading images..."); var imagePath = Path.Combine(path, "steam_settings", "images"); Directory.CreateDirectory(imagePath); @@ -335,7 +335,7 @@ namespace GoldbergGUI.Core.Services achievement.IconGray = $"images/{Path.GetFileName(achievement.IconGray)}"; } - _log.Info("Saving achievements..."); + _log.LogInformation("Saving achievements..."); var achievementJson = System.Text.Json.JsonSerializer.Serialize( c.Achievements, @@ -347,11 +347,11 @@ namespace GoldbergGUI.Core.Services await File.WriteAllTextAsync(Path.Combine(path, "steam_settings", "achievements.json"), achievementJson) .ConfigureAwait(false); - _log.Info("Finished saving achievements."); + _log.LogInformation("Finished saving achievements."); } else { - _log.Info("No achievements set! Removing achievement files..."); + _log.LogInformation("No achievements set! Removing achievement files..."); var imagePath = Path.Combine(path, "steam_settings", "images"); if (Directory.Exists(imagePath)) { @@ -362,13 +362,13 @@ namespace GoldbergGUI.Core.Services { File.Delete(achievementPath); } - _log.Info("Removed achievement files."); + _log.LogInformation("Removed achievement files."); } // DLC + App path if (c.DlcList.Count > 0) { - _log.Info("Saving DLC settings..."); + _log.LogInformation("Saving DLC settings..."); var dlcContent = ""; //var depotContent = ""; var appPathContent = ""; @@ -399,54 +399,54 @@ namespace GoldbergGUI.Core.Services if (File.Exists(Path.Combine(path, "steam_settings", "app_paths.txt"))) File.Delete(Path.Combine(path, "steam_settings", "app_paths.txt")); } - _log.Info("Saved DLC settings."); + _log.LogInformation("Saved DLC settings."); } else { - _log.Info("No DLC set! Removing DLC configuration files..."); + _log.LogInformation("No DLC set! Removing DLC configuration files..."); if (File.Exists(Path.Combine(path, "steam_settings", "DLC.txt"))) File.Delete(Path.Combine(path, "steam_settings", "DLC.txt")); if (File.Exists(Path.Combine(path, "steam_settings", "app_paths.txt"))) File.Delete(Path.Combine(path, "steam_settings", "app_paths.txt")); - _log.Info("Removed DLC configuration files."); + _log.LogInformation("Removed DLC configuration files."); } // Offline if (c.Offline) { - _log.Info("Create offline.txt"); + _log.LogInformation("Create offline.txt"); await File.Create(Path.Combine(path, "steam_settings", "offline.txt")).DisposeAsync() .ConfigureAwait(false); } else { - _log.Info("Delete offline.txt if it exists"); + _log.LogInformation("Delete offline.txt if it exists"); File.Delete(Path.Combine(path, "steam_settings", "offline.txt")); } // Disable Networking if (c.DisableNetworking) { - _log.Info("Create disable_networking.txt"); + _log.LogInformation("Create disable_networking.txt"); await File.Create(Path.Combine(path, "steam_settings", "disable_networking.txt")).DisposeAsync() .ConfigureAwait(false); } else { - _log.Info("Delete disable_networking.txt if it exists"); + _log.LogInformation("Delete disable_networking.txt if it exists"); File.Delete(Path.Combine(path, "steam_settings", "disable_networking.txt")); } // Disable Overlay if (c.DisableOverlay) { - _log.Info("Create disable_overlay.txt"); + _log.LogInformation("Create disable_overlay.txt"); await File.Create(Path.Combine(path, "steam_settings", "disable_overlay.txt")).DisposeAsync() .ConfigureAwait(false); } else { - _log.Info("Delete disable_overlay.txt if it exists"); + _log.LogInformation("Delete disable_overlay.txt if it exists"); File.Delete(Path.Combine(path, "steam_settings", "disable_overlay.txt")); } } @@ -460,7 +460,7 @@ namespace GoldbergGUI.Core.Services if (!File.Exists(originalDll)) { - _log.Info("Back up original Steam API DLL..."); + _log.LogInformation("Back up original Steam API DLL..."); File.Move(steamApiDll, originalDll); } else @@ -469,7 +469,7 @@ namespace GoldbergGUI.Core.Services File.SetAttributes(guiBackup, FileAttributes.Hidden); } - _log.Info("Copy Goldberg DLL to target path..."); + _log.LogInformation("Copy Goldberg DLL to target path..."); File.Copy(goldbergDll, steamApiDll); } @@ -477,7 +477,7 @@ namespace GoldbergGUI.Core.Services { var steamSettingsDirExists = Directory.Exists(Path.Combine(path, "steam_settings")); var steamAppIdTxtExists = File.Exists(Path.Combine(path, "steam_appid.txt")); - _log.Debug($"Goldberg applied? {(steamSettingsDirExists && steamAppIdTxtExists).ToString()}"); + _log.LogDebug($"Goldberg applied? {steamSettingsDirExists && steamAppIdTxtExists}"); return steamSettingsDirExists && steamAppIdTxtExists; } @@ -486,7 +486,7 @@ namespace GoldbergGUI.Core.Services // Get webpage // Get job id, compare with local if exists, save it if false or missing // Get latest archive if mismatch, call Extract - _log.Info("Initializing download..."); + _log.LogInformation("Initializing download..."); if (!Directory.Exists(_goldbergPath)) Directory.CreateDirectory(_goldbergPath); var client = new HttpClient(); var response = await client.GetAsync(GoldbergUrl).ConfigureAwait(false); @@ -499,23 +499,23 @@ namespace GoldbergGUI.Core.Services { try { - _log.Info("Check if update is needed..."); + _log.LogInformation("Check if update is needed..."); var jobIdLocal = Convert.ToInt32(File.ReadLines(jobIdPath).First().Trim()); var jobIdRemote = Convert.ToInt32(match.Groups["jobid"].Value); - _log.Debug($"job_id: local {jobIdLocal}; remote {jobIdRemote}"); + _log.LogDebug($"job_id: local {jobIdLocal}; remote {jobIdRemote}"); if (jobIdLocal.Equals(jobIdRemote)) { - _log.Info("Latest Goldberg emulator is already available! Skipping..."); + _log.LogInformation("Latest Goldberg emulator is already available! Skipping..."); return false; } } catch (Exception) { - _log.Error("An error occured, local Goldberg setup might be broken!"); + _log.LogError("An error occured, local Goldberg setup might be broken!"); } } - _log.Info("Starting download..."); + _log.LogInformation("Starting download..."); await StartDownload(match.Value).ConfigureAwait(false); return true; } @@ -525,7 +525,7 @@ namespace GoldbergGUI.Core.Services try { var client = new HttpClient(); - _log.Debug(downloadUrl); + _log.LogDebug(downloadUrl); await using var fileStream = File.OpenWrite(_goldbergZipPath); //client.GetAsync(downloadUrl, HttpCompletionOption.ResponseHeadersRead) var httpRequestMessage = new HttpRequestMessage(HttpMethod.Head, downloadUrl); @@ -539,7 +539,7 @@ namespace GoldbergGUI.Core.Services // Environment.Exit(128); if (contentLength == fileLength) { - _log.Info("Download finished!"); + _log.LogInformation("Download finished!"); } else { @@ -550,7 +550,7 @@ namespace GoldbergGUI.Core.Services catch (Exception e) { ShowErrorMessage(); - _log.Error(e.ToString); + _log.LogError(e.ToString()); Environment.Exit(1); } } @@ -560,7 +560,7 @@ namespace GoldbergGUI.Core.Services private async Task Extract(string archivePath) { var errorOccured = false; - _log.Debug("Start extraction..."); + _log.LogDebug("Start extraction..."); Directory.Delete(_goldbergPath, true); Directory.CreateDirectory(_goldbergPath); using (var archive = await Task.Run(() => ZipFile.OpenRead(archivePath)).ConfigureAwait(false)) @@ -584,8 +584,8 @@ namespace GoldbergGUI.Core.Services catch (Exception e) { errorOccured = true; - _log.Error($"Error while trying to extract {entry.FullName}"); - _log.Error(e.ToString); + _log.LogError($"Error while trying to extract {entry.FullName}"); + _log.LogError(e.ToString()); } }).ConfigureAwait(false); } @@ -594,9 +594,9 @@ namespace GoldbergGUI.Core.Services if (errorOccured) { ShowErrorMessage(); - _log.Warn("Error occured while extraction! Please setup Goldberg manually"); + _log.LogWarning("Error occured while extraction! Please setup Goldberg manually"); } - _log.Info("Extraction was successful!"); + _log.LogInformation("Extraction was successful!"); } private void ShowErrorMessage() @@ -615,7 +615,7 @@ namespace GoldbergGUI.Core.Services // (maybe) check DLL date first public async Task GenerateInterfacesFile(string filePath) { - _log.Debug($"GenerateInterfacesFile {filePath}"); + _log.LogDebug($"GenerateInterfacesFile {filePath}"); //throw new NotImplementedException(); // Get DLL content var result = new HashSet(); @@ -694,7 +694,7 @@ namespace GoldbergGUI.Core.Services } else if (imageUrl.StartsWith("images/")) { - _log.Warn($"Previously downloaded image '{imageUrl}' is now missing!"); + _log.LogWarning($"Previously downloaded image '{imageUrl}' is now missing!"); } var wc = new System.Net.WebClient(); diff --git a/GoldbergGUI.Core/Services/SteamService.cs b/GoldbergGUI.Core/Services/SteamService.cs index 74c369b..c457000 100644 --- a/GoldbergGUI.Core/Services/SteamService.cs +++ b/GoldbergGUI.Core/Services/SteamService.cs @@ -2,7 +2,7 @@ using AngleSharp.Dom; using AngleSharp.Html.Parser; using GoldbergGUI.Core.Models; using GoldbergGUI.Core.Utils; -using MvvmCross.Logging; +using Microsoft.Extensions.Logging; using NinjaNye.SearchExtensions; using SQLite; using SteamStorefrontAPI; @@ -19,7 +19,7 @@ namespace GoldbergGUI.Core.Services // gets info from steam api public interface ISteamService { - public Task Initialize(IMvxLog log); + public Task Initialize(ILogger log); public Task> GetListOfAppsByName(string name); public Task GetAppByName(string name); public Task GetAppById(int appid); @@ -84,11 +84,11 @@ namespace GoldbergGUI.Core.Services private const string Database = "steamapps.cache"; private const string GameSchemaUrl = "https://api.steampowered.com/ISteamUserStats/GetSchemaForGame/v2/"; - private IMvxLog _log; + private ILogger _log; private SQLiteAsyncConnection _db; - public async Task Initialize(IMvxLog log) + public async Task Initialize(ILogger log) { static SteamApps DeserializeSteamApps(Type type, string cacheString) { @@ -101,7 +101,7 @@ namespace GoldbergGUI.Core.Services _db = new SQLiteAsyncConnection(Database); //_db.CreateTable(); await _db.CreateTableAsync() - //.ContinueWith(x => _log.Debug("Table success!")) + //.ContinueWith(x => _log.LogDebug("Table success!")) .ConfigureAwait(false); var countAsync = await _db.Table().CountAsync().ConfigureAwait(false); @@ -109,7 +109,7 @@ namespace GoldbergGUI.Core.Services { foreach (var (appType, steamCache) in _caches) { - _log.Info($"Updating cache ({appType})..."); + _log.LogInformation($"Updating cache ({appType})..."); bool haveMoreResults; long lastAppId = 0; var client = new HttpClient(); @@ -152,21 +152,21 @@ namespace GoldbergGUI.Core.Services public async Task GetAppByName(string name) { - _log.Info($"Trying to get app {name}"); + _log.LogInformation($"Trying to get app {name}"); var comparableName = PrepareStringToCompare(name); var app = await _db.Table() .FirstOrDefaultAsync(x => x.AppType == AppTypeGame && x.ComparableName.Equals(comparableName)) .ConfigureAwait(false); - if (app != null) _log.Info($"Successfully got app {app}"); + if (app != null) _log.LogInformation($"Successfully got app {app}"); return app; } public async Task GetAppById(int appid) { - _log.Info($"Trying to get app with ID {appid}"); + _log.LogInformation($"Trying to get app with ID {appid}"); var app = await _db.Table().Where(x => x.AppType == AppTypeGame) .FirstOrDefaultAsync(x => x.AppId.Equals(appid)).ConfigureAwait(false); - if (app != null) _log.Info($"Successfully got app {app}"); + if (app != null) _log.LogInformation($"Successfully got app {app}"); return app; } @@ -178,7 +178,7 @@ namespace GoldbergGUI.Core.Services return achievementList; } - _log.Info($"Getting achievements for App {steamApp}"); + _log.LogInformation($"Getting achievements for App {steamApp}"); var client = new HttpClient(); client.DefaultRequestHeaders.UserAgent.ParseAdd(UserAgent); @@ -201,7 +201,7 @@ namespace GoldbergGUI.Core.Services var dlcList = new List(); if (steamApp != null) { - _log.Info($"Get DLC for App {steamApp}"); + _log.LogInformation($"Get DLC for App {steamApp}"); var task = AppDetails.GetAsync(steamApp.AppId); var steamAppDetails = await task.ConfigureAwait(true); if (steamAppDetails.Type == AppTypeGame) @@ -212,10 +212,10 @@ namespace GoldbergGUI.Core.Services .FirstOrDefaultAsync(y => y.AppId.Equals(x)).ConfigureAwait(true) ?? new SteamApp() { AppId = x, Name = $"Unknown DLC {x}", ComparableName = $"unknownDlc{x}", AppType = AppTypeDlc }; dlcList.Add(new DlcApp(result)); - _log.Debug($"{result.AppId}={result.Name}"); + _log.LogDebug($"{result.AppId}={result.Name}"); }); - _log.Info("Got DLC successfully..."); + _log.LogInformation("Got DLC successfully..."); // Get DLC from SteamDB // Get Cloudflare cookie (not implemented) @@ -232,15 +232,15 @@ namespace GoldbergGUI.Core.Services var client = new HttpClient(); client.DefaultRequestHeaders.UserAgent.ParseAdd(UserAgent); - _log.Info($"Get SteamDB App {steamApp}"); + _log.LogInformation($"Get SteamDB App {steamApp}"); var httpCall = client.GetAsync(steamDbUri); var response = await httpCall.ConfigureAwait(false); - _log.Debug(httpCall.Status.ToString()); - _log.Debug(response.EnsureSuccessStatusCode().ToString()); + _log.LogDebug(httpCall.Status.ToString()); + _log.LogDebug(response.EnsureSuccessStatusCode().ToString()); var readAsStringAsync = response.Content.ReadAsStringAsync(); var responseBody = await readAsStringAsync.ConfigureAwait(false); - _log.Debug(readAsStringAsync.Status.ToString()); + _log.LogDebug(readAsStringAsync.Status.ToString()); var parser = new HtmlParser(); var doc = parser.ParseDocument(responseBody); @@ -248,7 +248,7 @@ namespace GoldbergGUI.Core.Services var query1 = doc.QuerySelector("#dlc"); if (query1 != null) { - _log.Info("Got list of DLC from SteamDB."); + _log.LogInformation("Got list of DLC from SteamDB."); var query2 = query1.QuerySelectorAll(".app"); foreach (var element in query2) { @@ -269,28 +269,28 @@ namespace GoldbergGUI.Core.Services } } - dlcList.ForEach(x => _log.Debug($"{x.AppId}={x.Name}")); - _log.Info("Got DLC from SteamDB successfully..."); + dlcList.ForEach(x => _log.LogDebug($"{x.AppId}={x.Name}")); + _log.LogInformation("Got DLC from SteamDB successfully..."); } else { - _log.Error("Could not get DLC from SteamDB!"); + _log.LogError("Could not get DLC from SteamDB!"); } } catch (Exception e) { - _log.Error("Could not get DLC from SteamDB! Skipping..."); - _log.Error(e.ToString); + _log.LogError("Could not get DLC from SteamDB! Skipping..."); + _log.LogError(e.ToString()); } } else { - _log.Error("Could not get DLC: Steam App is not of type \"game\""); + _log.LogError("Could not get DLC: Steam App is not of type \"game\""); } } else { - _log.Error("Could not get DLC: Invalid Steam App"); + _log.LogError("Could not get DLC: Invalid Steam App"); } return dlcList; diff --git a/GoldbergGUI.Core/ViewModels/MainViewModel.cs b/GoldbergGUI.Core/ViewModels/MainViewModel.cs index 54580c7..666401a 100644 --- a/GoldbergGUI.Core/ViewModels/MainViewModel.cs +++ b/GoldbergGUI.Core/ViewModels/MainViewModel.cs @@ -1,9 +1,9 @@ using GoldbergGUI.Core.Models; using GoldbergGUI.Core.Services; using GoldbergGUI.Core.Utils; +using Microsoft.Extensions.Logging; using Microsoft.Win32; using MvvmCross.Commands; -using MvvmCross.Logging; using MvvmCross.Navigation; using MvvmCross.ViewModels; using System; @@ -42,20 +42,20 @@ namespace GoldbergGUI.Core.ViewModels private readonly ISteamService _steam; private readonly IGoldbergService _goldberg; - private readonly IMvxLog _log; + private readonly ILogger _log; private bool _mainWindowEnabled; private bool _goldbergApplied; private ObservableCollection _steamLanguages; private string _selectedLanguage; - private readonly IMvxLogProvider _logProvider; + private readonly ILoggerFactory _logProvider; - public MainViewModel(ISteamService steam, IGoldbergService goldberg, IMvxLogProvider logProvider, + public MainViewModel(ISteamService steam, IGoldbergService goldberg, ILoggerFactory logProvider, IMvxNavigationService navigationService) : base(logProvider, navigationService) { _steam = steam; _goldberg = goldberg; _logProvider = logProvider; - _log = logProvider.GetLogFor(); + _log = logProvider.CreateLogger(); _navigationService = navigationService; } @@ -71,9 +71,9 @@ namespace GoldbergGUI.Core.ViewModels { SteamLanguages = new ObservableCollection(_goldberg.Languages()); ResetForm(); - await _steam.Initialize(_logProvider.GetLogFor()).ConfigureAwait(false); + await _steam.Initialize(_logProvider.CreateLogger()).ConfigureAwait(false); var globalConfiguration = - await _goldberg.Initialize(_logProvider.GetLogFor()).ConfigureAwait(false); + await _goldberg.Initialize(_logProvider.CreateLogger()).ConfigureAwait(false); AccountName = globalConfiguration.AccountName; SteamId = globalConfiguration.UserSteamId; SelectedLanguage = globalConfiguration.Language; @@ -81,7 +81,7 @@ namespace GoldbergGUI.Core.ViewModels catch (Exception e) { Console.WriteLine(e); - _log.Error(e.Message); + _log.LogError(e.Message); throw; } @@ -237,7 +237,7 @@ namespace GoldbergGUI.Core.ViewModels get { var value = !DllPath.Contains("Path to game's steam_api(64).dll"); - if (!value) _log.Warn("No DLL selected! Skipping..."); + if (!value) _log.LogWarning("No DLL selected! Skipping..."); return value; } } @@ -296,7 +296,7 @@ namespace GoldbergGUI.Core.ViewModels if (dialog.ShowDialog() != true) { MainWindowEnabled = true; - _log.Warn("File selection canceled."); + _log.LogWarning("File selection canceled."); StatusText = "No file selected! Ready."; return; } @@ -326,7 +326,7 @@ namespace GoldbergGUI.Core.ViewModels if (GameName.Contains("Game name...")) { - _log.Error("No game name entered!"); + _log.LogError("No game name entered!"); return; } @@ -371,7 +371,7 @@ namespace GoldbergGUI.Core.ViewModels { if (AppId <= 0) { - _log.Error("Invalid Steam App!"); + _log.LogError("Invalid Steam App!"); return; } @@ -385,7 +385,7 @@ namespace GoldbergGUI.Core.ViewModels { if (AppId <= 0) { - _log.Error("Invalid Steam App!"); + _log.LogError("Invalid Steam App!"); return; } @@ -412,7 +412,7 @@ namespace GoldbergGUI.Core.ViewModels { if (AppId <= 0) { - _log.Error("Invalid Steam App!"); + _log.LogError("Invalid Steam App!"); return; } @@ -437,7 +437,7 @@ namespace GoldbergGUI.Core.ViewModels private async Task SaveConfig() { - _log.Info("Saving global settings..."); + _log.LogInformation("Saving global settings..."); var globalConfiguration = new GoldbergGlobalConfiguration { AccountName = AccountName, @@ -447,7 +447,7 @@ namespace GoldbergGUI.Core.ViewModels await _goldberg.SetGlobalSettings(globalConfiguration).ConfigureAwait(false); if (!DllSelected) return; - _log.Info("Saving Goldberg settings..."); + _log.LogInformation("Saving Goldberg settings..."); if (!GetDllPathDir(out var dirPath)) return; MainWindowEnabled = false; StatusText = "Saving..."; @@ -476,7 +476,7 @@ namespace GoldbergGUI.Core.ViewModels SelectedLanguage = globalConfiguration.Language; if (!DllSelected) return; - _log.Info("Reset form..."); + _log.LogInformation("Reset form..."); MainWindowEnabled = false; StatusText = "Resetting..."; await ReadConfig().ConfigureAwait(false); @@ -490,7 +490,7 @@ namespace GoldbergGUI.Core.ViewModels { if (!DllSelected) return; - _log.Info("Generate steam_interfaces.txt..."); + _log.LogInformation("Generate steam_interfaces.txt..."); MainWindowEnabled = false; StatusText = @"Generating ""steam_interfaces.txt""."; GetDllPathDir(out var dirPath); @@ -508,10 +508,10 @@ namespace GoldbergGUI.Core.ViewModels public IMvxCommand PasteDlcCommand => new MvxCommand(() => { if (!RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) return; - _log.Info("Trying to paste DLC list..."); + _log.LogInformation("Trying to paste DLC list..."); if (!(Clipboard.ContainsText(TextDataFormat.UnicodeText) || Clipboard.ContainsText(TextDataFormat.Text))) { - _log.Warn("Invalid DLC list!"); + _log.LogWarning("Invalid DLC list!"); } else { @@ -604,7 +604,7 @@ namespace GoldbergGUI.Core.ViewModels dirPath = Path.GetDirectoryName(DllPath); if (dirPath != null) return true; - _log.Error($"Invalid directory for {DllPath}."); + _log.LogError($"Invalid directory for {DllPath}."); return false; } } diff --git a/GoldbergGUI.Core/ViewModels/SearchResultViewModel.cs b/GoldbergGUI.Core/ViewModels/SearchResultViewModel.cs index 35f4dc2..d04a3d8 100644 --- a/GoldbergGUI.Core/ViewModels/SearchResultViewModel.cs +++ b/GoldbergGUI.Core/ViewModels/SearchResultViewModel.cs @@ -1,6 +1,6 @@ using GoldbergGUI.Core.Models; +using Microsoft.Extensions.Logging; using MvvmCross.Commands; -using MvvmCross.Logging; using MvvmCross.Navigation; using MvvmCross.ViewModels; using System.Collections.Generic; @@ -11,13 +11,13 @@ namespace GoldbergGUI.Core.ViewModels public class SearchResultViewModel : MvxNavigationViewModel>, IMvxViewModel, SteamApp> { private readonly IMvxNavigationService _navigationService; - private readonly IMvxLog _log; + private readonly ILogger _log; private IEnumerable _apps; - public SearchResultViewModel(IMvxLogProvider logProvider, IMvxNavigationService navigationService) : + public SearchResultViewModel(ILoggerFactory logProvider, IMvxNavigationService navigationService) : base(logProvider, navigationService) { - _log = logProvider.GetLogFor(typeof(SearchResultViewModel)); + _log = logProvider.CreateLogger();//.GetLogFor(typeof(SearchResultViewModel)); _navigationService = navigationService; } @@ -61,7 +61,7 @@ namespace GoldbergGUI.Core.ViewModels { if (Selected != null) { - _log.Info($"Successfully got app {Selected}"); + _log.LogInformation($"Successfully got app {Selected}"); await _navigationService.Close(this, Selected).ConfigureAwait(false); } } diff --git a/GoldbergGUI.WPF/GoldbergGUI.WPF.csproj b/GoldbergGUI.WPF/GoldbergGUI.WPF.csproj index d0e7dcb..0c67434 100644 --- a/GoldbergGUI.WPF/GoldbergGUI.WPF.csproj +++ b/GoldbergGUI.WPF/GoldbergGUI.WPF.csproj @@ -10,10 +10,11 @@ - - - - + + + + + diff --git a/GoldbergGUI.WPF/Setup.cs b/GoldbergGUI.WPF/Setup.cs index c9f6d78..33a3d7d 100644 --- a/GoldbergGUI.WPF/Setup.cs +++ b/GoldbergGUI.WPF/Setup.cs @@ -1,15 +1,18 @@ -using MvvmCross.Logging; +using Microsoft.Extensions.Logging; using MvvmCross.Platforms.Wpf.Core; using Serilog; +using Serilog.Extensions.Logging; using System.IO; namespace GoldbergGUI.WPF { public class Setup : MvxWpfSetup { - public override MvxLogProviderType GetDefaultLogProviderType() => MvxLogProviderType.Serilog; - - protected override IMvxLogProvider CreateLogProvider() + protected override ILoggerProvider CreateLogProvider() + { + return new SerilogLoggerProvider(); + } + protected override ILoggerFactory CreateLogFactory() { var logPath = Path.Combine(Directory.GetCurrentDirectory(), "goldberg_.log"); Log.Logger = new LoggerConfiguration() @@ -17,7 +20,7 @@ namespace GoldbergGUI.WPF .WriteTo.Console() .WriteTo.File(logPath, rollingInterval: RollingInterval.Day) .CreateLogger(); - return base.CreateLogProvider(); + return new SerilogLoggerFactory(); } }