diff --git a/CHANGELOG.md b/CHANGELOG.md index 117cca1b..c2bdcef8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,8 @@ ### Changelog +#### Version - 3.0.2.3 - 10/19/2022 +* HOTFIX: revert GameFinder library to 1.8 until it's a bit more forgiving of corrupt files + #### Version - 3.0.2.2 - 10/19/2022 * HOTFIX: make game detection *even more* safe against crashes diff --git a/Wabbajack.App.Wpf/View Models/MainWindowVM.cs b/Wabbajack.App.Wpf/View Models/MainWindowVM.cs index 872ef742..cef0719a 100644 --- a/Wabbajack.App.Wpf/View Models/MainWindowVM.cs +++ b/Wabbajack.App.Wpf/View Models/MainWindowVM.cs @@ -147,11 +147,19 @@ namespace Wabbajack Task.Run(() => _wjClient.SendMetric("started_sha", ThisAssembly.Git.Sha)); // setup file association - var applicationRegistrationService = _serviceProvider.GetRequiredService(); + try + { + var applicationRegistrationService = + _serviceProvider.GetRequiredService(); - var applicationInfo = new ApplicationInfo(assembly); - applicationInfo.SupportedExtensions.Add("wabbajack"); - applicationRegistrationService.RegisterApplication(applicationInfo); + var applicationInfo = new ApplicationInfo(assembly); + applicationInfo.SupportedExtensions.Add("wabbajack"); + applicationRegistrationService.RegisterApplication(applicationInfo); + } + catch (Exception ex) + { + _logger.LogError(ex, "While setting up file associations"); + } } catch (Exception ex) { diff --git a/Wabbajack.Downloaders.GameFile/GameLocator.cs b/Wabbajack.Downloaders.GameFile/GameLocator.cs index 535b6c6b..aaeb0e97 100644 --- a/Wabbajack.Downloaders.GameFile/GameLocator.cs +++ b/Wabbajack.Downloaders.GameFile/GameLocator.cs @@ -1,5 +1,3 @@ -using System.Runtime.InteropServices; -using GameFinder.RegistryUtils; using GameFinder.StoreHandlers.EGS; using GameFinder.StoreHandlers.GOG; using GameFinder.StoreHandlers.Origin; @@ -7,109 +5,67 @@ using GameFinder.StoreHandlers.Steam; using Microsoft.Extensions.Logging; using Wabbajack.DTOs; using Wabbajack.Paths; -using Wabbajack.Paths.IO; namespace Wabbajack.Downloaders.GameFile; public class GameLocator : IGameLocator { - private readonly SteamHandler _steam; - private readonly GOGHandler? _gog; private readonly EGSHandler? _egs; - private readonly OriginHandler? _origin; - - private readonly Dictionary _steamGames = new(); - private readonly Dictionary _gogGames = new(); - private readonly Dictionary _egsGames = new(); - private readonly Dictionary _originGames = new(); - + private readonly GOGHandler? _gog; private readonly Dictionary _locationCache; private readonly ILogger _logger; + private readonly OriginHandler? _origin; + private readonly SteamHandler _steam; public GameLocator(ILogger logger) { _logger = logger; + _steam = new SteamHandler(logger); - if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) + if (OperatingSystem.IsWindows()) { - var windowsRegistry = new WindowsRegistry(); - - _steam = new SteamHandler(windowsRegistry); - _gog = new GOGHandler(windowsRegistry); - _egs = new EGSHandler(windowsRegistry); - _origin = new OriginHandler(); + _origin = new OriginHandler(true, false, logger); + _gog = new GOGHandler(logger); + + _egs = new EGSHandler(logger); } - else - { - _steam = new SteamHandler(null); - } - + _locationCache = new Dictionary(); - - FindAllGames(); - } - private void FindAllGames() - { - FindStoreGames(_steam.FindAllGames(), _steamGames, - steamGame => steamGame.Path, - steamGame => steamGame.AppId); - - if (_gog is not null) + try { - FindStoreGames(_gog.FindAllGames(), _gogGames, - gogGame => gogGame.Path, - gogGame => gogGame.Id); + _steam.FindAllGames(); + } + catch (Exception ex) + { + _logger.LogError(ex, "While finding Steam games"); } - if (_egs is not null) + try { - FindStoreGames(_egs.FindAllGames(), _egsGames, - egsGame => egsGame.InstallLocation, - egsGame => egsGame.CatalogItemId); + _origin?.FindAllGames(); + } + catch (Exception ex) + { + _logger.LogInformation(ex, "While finding Origin games"); } - if (_origin is not null) + try { - FindStoreGames(_origin.FindAllGames(), _originGames, - originGame => originGame.InstallPath, - originGame => originGame.Id); + _gog?.FindAllGames(); } - } - - private void FindStoreGames( - IEnumerable<(TGame? game, string? error)> games, - IDictionary paths, - Func getPath, - Func getId) - where TGame : class - { - foreach (var (game, error) in games) + catch (Exception ex) { - try - { - if (game is not null) - { - var path = getPath(game).ToAbsolutePath(); - if (path.DirectoryExists()) - { - paths[getId(game)] = path; - _logger.LogDebug("Found Game {} at {}", game, path); - } - else - { - _logger.LogError("Game {} does not exist at {}", game, path); - } - } - else - { - _logger.LogError("{}", error); - } - } - catch (Exception ex) - { - _logger.LogError(ex, "While locating game {Game}", game); - } + _logger.LogInformation(ex, "While finding GoG games"); + } + + try + { + _egs?.FindAllGames(); + } + catch (Exception ex) + { + _logger.LogInformation(ex, "While finding Epic Games"); } } @@ -148,61 +104,66 @@ public class GameLocator : IGameLocator try { - foreach (var id in metaData.SteamIDs) + foreach (var steamGame in _steam.Games.Where(steamGame => metaData.SteamIDs.Contains(steamGame.ID))) { - if (!_steamGames.TryGetValue(id, out var found)) continue; - path = found; + path = steamGame!.Path.ToAbsolutePath(); return true; } } catch (Exception ex) { - _logger.LogInformation(ex, "During Steam detection"); + _logger.LogInformation(ex, "While finding {Game} from Steam", game); + } + + try + { + if (_gog != null) + { + foreach (var gogGame in _gog.Games.Where(gogGame => metaData.GOGIDs.Contains(gogGame.GameID))) + { + path = gogGame!.Path.ToAbsolutePath(); + return true; + } + } + } + catch (Exception ex) + { + _logger.LogInformation(ex, "While finding {Game} from GoG", game); + } + + try + { + if (_egs != null) + { + foreach (var egsGame in _egs.Games.Where(egsGame => + metaData.EpicGameStoreIDs.Contains(egsGame.CatalogItemId))) + { + path = egsGame!.Path.ToAbsolutePath(); + return true; + } + } + } + catch (Exception ex) + { + _logger.LogInformation(ex, "While finding {Game} from Epic", game); } try { - foreach (var id in metaData.GOGIDs) + if (_origin != null) { - if (!_gogGames.TryGetValue(id, out var found)) continue; - path = found; - return true; + foreach (var originGame in _origin.Games.Where(originGame => + metaData.EpicGameStoreIDs.Contains(originGame.Id))) + { + path = originGame.Path.ToAbsolutePath(); + return true; + } } } catch (Exception ex) { - _logger.LogInformation(ex, "During GOG detection"); - } - - - try - { - foreach (var id in metaData.EpicGameStoreIDs) - { - if (!_egsGames.TryGetValue(id, out var found)) continue; - path = found; - return true; - } - } - catch (Exception ex) - { - _logger.LogInformation(ex, "During Epic detection"); - } - - - try - { - foreach (var id in metaData.OriginIDs) - { - if (!_originGames.TryGetValue(id, out var found)) continue; - path = found; - return true; - } - } - catch (Exception ex) - { - _logger.LogInformation(ex, "During Origin Store detection"); + _logger.LogInformation(ex, "While finding {Game} from Origin", game); } path = default; diff --git a/Wabbajack.Downloaders.GameFile/Wabbajack.Downloaders.GameFile.csproj b/Wabbajack.Downloaders.GameFile/Wabbajack.Downloaders.GameFile.csproj index 4ee68a0c..0095b51a 100644 --- a/Wabbajack.Downloaders.GameFile/Wabbajack.Downloaders.GameFile.csproj +++ b/Wabbajack.Downloaders.GameFile/Wabbajack.Downloaders.GameFile.csproj @@ -18,10 +18,10 @@ - - - - + + + +