Skip to content

Commit

Permalink
Fixes for various crashes while managing and running games (#758)
Browse files Browse the repository at this point in the history
  • Loading branch information
halgari committed Nov 9, 2023
1 parent 7130223 commit 390ca9d
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 8 deletions.
1 change: 1 addition & 0 deletions src/NexusMods.App.UI/Controls/Spine/SpineViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ public class SpineViewModel : AViewModel<ISpineViewModel>, ISpineViewModel
this.WhenActivated(disposables =>
{
router.Messages
.OnUI()
.SubscribeWithErrorLogging(logger, HandleMessage)
.DisposeWith(disposables);
Expand Down
5 changes: 1 addition & 4 deletions src/NexusMods.App.UI/RightContent/FoundGamesViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,7 @@ public void InitializeFromFound(IEnumerable<IGame> games)
vm.Installation = install;
vm.PrimaryButton = ReactiveCommand.CreateFromTask(async () =>
{
await Task.Run(async () =>
{
await ManageGame(install);
});
await Task.Run(async () => await ManageGame(install));
});
return vm;
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
using NexusMods.DataModel.Loadouts.LoadoutSynchronizerDTOs;
using NexusMods.DataModel.Loadouts.ModFiles;
using NexusMods.DataModel.Loadouts.Mods;
using NexusMods.DataModel.LoadoutSynchronizer.Exceptions;
using NexusMods.DataModel.Sorting;
using NexusMods.DataModel.Sorting.Rules;
using NexusMods.FileExtractor.StreamFactories;
Expand Down Expand Up @@ -252,7 +253,7 @@ public virtual async Task<DiskState> GetDiskState(GameInstallation installation)
/// <param name="entry"></param>
public virtual void HandleNeedIngest(HashedEntry entry)
{
throw new Exception("File changed during apply, need to ingest");
throw new NeedsIngestException();
}

/// <inheritdoc />
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
namespace NexusMods.DataModel.LoadoutSynchronizer.Exceptions;

/// <summary>
/// Thrown when there are changes in the game folder that need to be ingested before a loadout can be applied
/// </summary>
public class NeedsIngestException : Exception
{
/// <summary>
/// Thrown when a loadout needs to be ingested before it can be applied
/// </summary>
public NeedsIngestException() : base("Loadout needs to be ingested before it can be applied")
{

}

}
23 changes: 20 additions & 3 deletions src/NexusMods.DataModel/ToolManager.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
using NexusMods.DataModel.Abstractions;
using Microsoft.Extensions.Logging;
using NexusMods.DataModel.Abstractions;
using NexusMods.DataModel.Games;
using NexusMods.DataModel.Loadouts;
using NexusMods.DataModel.Loadouts.Extensions;
using NexusMods.DataModel.Loadouts.Mods;

Check warning on line 6 in src/NexusMods.DataModel/ToolManager.cs

View workflow job for this annotation

GitHub Actions / Qodana for .NET

Redundant using directive

Using directive is not required by the code and can be safely removed
using NexusMods.DataModel.LoadoutSynchronizer.Exceptions;

namespace NexusMods.DataModel;

Expand All @@ -14,6 +16,7 @@ public class ToolManager : IToolManager
private readonly ILookup<GameDomain,ITool> _tools;
private readonly IDataStore _dataStore;

Check warning on line 17 in src/NexusMods.DataModel/ToolManager.cs

View workflow job for this annotation

GitHub Actions / Qodana for .NET

Non-accessed field (private accessibility)

Field '_dataStore' is assigned but its value is never used
private readonly LoadoutRegistry _loadoutRegistry;

Check warning on line 18 in src/NexusMods.DataModel/ToolManager.cs

View workflow job for this annotation

GitHub Actions / Qodana for .NET

Non-accessed field (private accessibility)

Field '_loadoutRegistry' is assigned but its value is never used
private readonly ILogger<ToolManager> _logger;

/// <summary>
/// DI Constructor
Expand All @@ -22,8 +25,9 @@ public class ToolManager : IToolManager
/// <param name="loadoutSynchronizer"></param>

Check warning on line 25 in src/NexusMods.DataModel/ToolManager.cs

View workflow job for this annotation

GitHub Actions / Qodana for .NET

XML comment has a 'param' tag for 'Parameter', but there is no parameter by that name

Cannot resolve parameter 'loadoutSynchronizer'
/// <param name="dataStore"></param>
/// <param name="loadoutRegistry"></param>
public ToolManager(IEnumerable<ITool> tools, IDataStore dataStore, LoadoutRegistry loadoutRegistry)
public ToolManager(ILogger<ToolManager> logger, IEnumerable<ITool> tools, IDataStore dataStore, LoadoutRegistry loadoutRegistry)

Check warning on line 28 in src/NexusMods.DataModel/ToolManager.cs

View workflow job for this annotation

GitHub Actions / Qodana for .NET

Parameter has no matching param tag in the XML comment

Parameter 'logger' has no matching param tag in the XML comment for NexusMods.DataModel.ToolManager.ToolManager (but other parameters do)
{
_logger = logger;
_dataStore = dataStore;
_tools = tools.SelectMany(tool => tool.Domains.Select(domain => (domain, tool)))
.ToLookup(t => t.domain, t => t.tool);
Expand All @@ -43,10 +47,23 @@ public async Task<Loadout> RunTool(ITool tool, Loadout loadout, ModId? generated
if (!tool.Domains.Contains(loadout.Installation.Game.Domain))
throw new Exception("Tool does not support this game");

await loadout.Apply();
_logger.LogInformation("Applying loadout {LoadoutId} to {GameName} {GameVersion}", loadout.LoadoutId, loadout.Installation.Game.Name, loadout.Installation.Version);
try
{
await loadout.Apply();
}
catch (NeedsIngestException)
{
_logger.LogInformation("Ingesting loadout {LoadoutId} from {GameName} {GameVersion}", loadout.LoadoutId, loadout.Installation.Game.Name, loadout.Installation.Version);
await loadout.Ingest();
_logger.LogInformation("Applying loadout {LoadoutId} to {GameName} {GameVersion}", loadout.LoadoutId, loadout.Installation.Game.Name, loadout.Installation.Version);
await loadout.Apply();
}

_logger.LogInformation("Running tool {ToolName} for loadout {LoadoutId} on {GameName} {GameVersion}", tool.Name, loadout.LoadoutId, loadout.Installation.Game.Name, loadout.Installation.Version);
await tool.Execute(loadout, token);

_logger.LogInformation("Ingesting loadout {LoadoutId} from {GameName} {GameVersion}", loadout.LoadoutId, loadout.Installation.Game.Name, loadout.Installation.Version);
return await loadout.Ingest();
}
}

0 comments on commit 390ca9d

Please sign in to comment.