Skip to content

Commit 390ca9d

Browse files
authored
Fixes for various crashes while managing and running games (#758)
1 parent 7130223 commit 390ca9d

File tree

5 files changed

+40
-8
lines changed

5 files changed

+40
-8
lines changed

src/NexusMods.App.UI/Controls/Spine/SpineViewModel.cs

+1
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ public SpineViewModel(ILogger<SpineViewModel> logger,
7575
this.WhenActivated(disposables =>
7676
{
7777
router.Messages
78+
.OnUI()
7879
.SubscribeWithErrorLogging(logger, HandleMessage)
7980
.DisposeWith(disposables);
8081

src/NexusMods.App.UI/RightContent/FoundGamesViewModel.cs

+1-4
Original file line numberDiff line numberDiff line change
@@ -52,10 +52,7 @@ public void InitializeFromFound(IEnumerable<IGame> games)
5252
vm.Installation = install;
5353
vm.PrimaryButton = ReactiveCommand.CreateFromTask(async () =>
5454
{
55-
await Task.Run(async () =>
56-
{
57-
await ManageGame(install);
58-
});
55+
await Task.Run(async () => await ManageGame(install));
5956
});
6057
return vm;
6158
});

src/NexusMods.DataModel/LoadoutSynchronizer/ALoadoutSynchronizer.cs

+2-1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
using NexusMods.DataModel.Loadouts.LoadoutSynchronizerDTOs;
99
using NexusMods.DataModel.Loadouts.ModFiles;
1010
using NexusMods.DataModel.Loadouts.Mods;
11+
using NexusMods.DataModel.LoadoutSynchronizer.Exceptions;
1112
using NexusMods.DataModel.Sorting;
1213
using NexusMods.DataModel.Sorting.Rules;
1314
using NexusMods.FileExtractor.StreamFactories;
@@ -252,7 +253,7 @@ public virtual async Task<DiskState> GetDiskState(GameInstallation installation)
252253
/// <param name="entry"></param>
253254
public virtual void HandleNeedIngest(HashedEntry entry)
254255
{
255-
throw new Exception("File changed during apply, need to ingest");
256+
throw new NeedsIngestException();
256257
}
257258

258259
/// <inheritdoc />
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
namespace NexusMods.DataModel.LoadoutSynchronizer.Exceptions;
2+
3+
/// <summary>
4+
/// Thrown when there are changes in the game folder that need to be ingested before a loadout can be applied
5+
/// </summary>
6+
public class NeedsIngestException : Exception
7+
{
8+
/// <summary>
9+
/// Thrown when a loadout needs to be ingested before it can be applied
10+
/// </summary>
11+
public NeedsIngestException() : base("Loadout needs to be ingested before it can be applied")
12+
{
13+
14+
}
15+
16+
}

src/NexusMods.DataModel/ToolManager.cs

+20-3
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
1-
using NexusMods.DataModel.Abstractions;
1+
using Microsoft.Extensions.Logging;
2+
using NexusMods.DataModel.Abstractions;
23
using NexusMods.DataModel.Games;
34
using NexusMods.DataModel.Loadouts;
45
using NexusMods.DataModel.Loadouts.Extensions;
56
using NexusMods.DataModel.Loadouts.Mods;
7+
using NexusMods.DataModel.LoadoutSynchronizer.Exceptions;
68

79
namespace NexusMods.DataModel;
810

@@ -14,6 +16,7 @@ public class ToolManager : IToolManager
1416
private readonly ILookup<GameDomain,ITool> _tools;
1517
private readonly IDataStore _dataStore;
1618
private readonly LoadoutRegistry _loadoutRegistry;
19+
private readonly ILogger<ToolManager> _logger;
1720

1821
/// <summary>
1922
/// DI Constructor
@@ -22,8 +25,9 @@ public class ToolManager : IToolManager
2225
/// <param name="loadoutSynchronizer"></param>
2326
/// <param name="dataStore"></param>
2427
/// <param name="loadoutRegistry"></param>
25-
public ToolManager(IEnumerable<ITool> tools, IDataStore dataStore, LoadoutRegistry loadoutRegistry)
28+
public ToolManager(ILogger<ToolManager> logger, IEnumerable<ITool> tools, IDataStore dataStore, LoadoutRegistry loadoutRegistry)
2629
{
30+
_logger = logger;
2731
_dataStore = dataStore;
2832
_tools = tools.SelectMany(tool => tool.Domains.Select(domain => (domain, tool)))
2933
.ToLookup(t => t.domain, t => t.tool);
@@ -43,10 +47,23 @@ public async Task<Loadout> RunTool(ITool tool, Loadout loadout, ModId? generated
4347
if (!tool.Domains.Contains(loadout.Installation.Game.Domain))
4448
throw new Exception("Tool does not support this game");
4549

46-
await loadout.Apply();
50+
_logger.LogInformation("Applying loadout {LoadoutId} to {GameName} {GameVersion}", loadout.LoadoutId, loadout.Installation.Game.Name, loadout.Installation.Version);
51+
try
52+
{
53+
await loadout.Apply();
54+
}
55+
catch (NeedsIngestException)
56+
{
57+
_logger.LogInformation("Ingesting loadout {LoadoutId} from {GameName} {GameVersion}", loadout.LoadoutId, loadout.Installation.Game.Name, loadout.Installation.Version);
58+
await loadout.Ingest();
59+
_logger.LogInformation("Applying loadout {LoadoutId} to {GameName} {GameVersion}", loadout.LoadoutId, loadout.Installation.Game.Name, loadout.Installation.Version);
60+
await loadout.Apply();
61+
}
4762

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

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

0 commit comments

Comments
 (0)