Skip to content

Commit 7130223

Browse files
authored
Fix tons of little issues found while running the app through the UI (#757)
* Fix tons of little issues found while running the app through the UI * Fix a few tests
1 parent 7a99726 commit 7130223

File tree

6 files changed

+65
-3
lines changed

6 files changed

+65
-3
lines changed

src/NexusMods.App.UI/LeftMenu/Items/LaunchButtonViewModel.cs

+4-1
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,10 @@ private async Task LaunchGame(CancellationToken token)
6161
Label = Language.LaunchButtonViewModel_LaunchGame_RUNNING;
6262
var marker = _loadoutRegistry.GetMarker(LoadoutId);
6363
var tool = _toolManager.GetTools(marker.Value).OfType<IRunGameTool>().First();
64-
await _toolManager.RunTool(tool, marker.Value, token: token);
64+
await Task.Run(async () =>
65+
{
66+
await _toolManager.RunTool(tool, marker.Value, token: token);
67+
}, token);
6568
Label = Language.LaunchButtonViewModel_LaunchGame_LAUNCH;
6669
}
6770
}

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

+7-1
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,13 @@ public void InitializeFromFound(IEnumerable<IGame> games)
5050
{
5151
var vm = _provider.GetRequiredService<IGameWidgetViewModel>();
5252
vm.Installation = install;
53-
vm.PrimaryButton = ReactiveCommand.CreateFromTask(() => ManageGame(install));
53+
vm.PrimaryButton = ReactiveCommand.CreateFromTask(async () =>
54+
{
55+
await Task.Run(async () =>
56+
{
57+
await ManageGame(install);
58+
});
59+
});
5460
return vm;
5561
});
5662
Games = new ReadOnlyObservableCollection<IGameWidgetViewModel>(new ObservableCollection<IGameWidgetViewModel>(installed));

src/NexusMods.CLI/Services.cs

+1
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ public static IServiceCollection AddCLI(this IServiceCollection services)
5656
.AddVerb<AddGame>()
5757
.AddVerb<AnalyzeArchive>()
5858
.AddVerb<Apply>()
59+
.AddVerb<Ingest>()
5960
.AddVerb<AssociateNxm>()
6061
.AddVerb<ChangeTracking>()
6162
.AddVerb<DownloadAndInstallMod>()

src/NexusMods.CLI/Verbs/Ingest.cs

+43
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
using NexusMods.Abstractions.CLI;
2+
using NexusMods.DataModel.Loadouts.Extensions;
3+
using NexusMods.DataModel.Loadouts.Markers;
4+
using NexusMods.Paths;
5+
6+
namespace NexusMods.CLI.Verbs;
7+
8+
// ReSharper disable once ClassNeverInstantiated.Global
9+
/// <summary>
10+
/// Compute and run the steps needed to apply a Loadout to a game folder
11+
/// </summary>
12+
public class Ingest : AVerb<LoadoutMarker>, IRenderingVerb
13+
{
14+
/// <inheritdoc />
15+
public IRenderer Renderer { get; set; } = null!;
16+
17+
/// <summary>
18+
/// DI constructor
19+
/// </summary>
20+
/// <param name="loadoutSynchronizer"></param>
21+
public Ingest()
22+
{
23+
}
24+
25+
/// <inheritdoc />
26+
public static VerbDefinition Definition => new("ingest", "Ingest changes from the game folders into the given loadout", new OptionDefinition[]
27+
{
28+
new OptionDefinition<LoadoutMarker>("l", "loadout", "Loadout ingest changes into"),
29+
});
30+
31+
/// <inheritdoc />
32+
public async Task<int> Run(LoadoutMarker loadout, CancellationToken token)
33+
{
34+
var state = await Renderer.WithProgress(token,
35+
async () => await loadout.Value.Ingest());
36+
37+
loadout.Alter("Ingest changes from the game folder", _ => state);
38+
39+
await Renderer.Render($"Ingested game folder changes into {loadout.Value.Name}");
40+
41+
return 0;
42+
}
43+
}

src/NexusMods.DataModel/LoadoutSynchronizer/ALoadoutSynchronizer.cs

+7
Original file line numberDiff line numberDiff line change
@@ -137,13 +137,19 @@ public async Task<DiskState> FileTreeToDisk(FileTree fileTree, Loadout loadout,
137137
continue;
138138
}
139139

140+
resultingItems.Add(newEntry.Path, prevEntry.Value);
140141
switch (newEntry.Value!)
141142
{
142143

143144
case StoredFile fa:
144145
// StoredFile files are special cased so we can batch them up and extract them all at once.
145146
// Don't add toExtract to the results yet as we'll need to get the modified file times
146147
// after we extract them
148+
149+
// If both hashes are the same, we can skip this file
150+
if (fa.Hash == entry.Hash)
151+
continue;
152+
147153
toExtract.Add(KeyValuePair.Create(entry.Path, fa));
148154
continue;
149155
case IGeneratedFile gf and IToFile:
@@ -473,6 +479,7 @@ public virtual async Task<Loadout> Ingest(Loadout loadout)
473479
var newLoadout = await FlattenedLoadoutToLoadout(flattenedLoadout, loadout, prevFlattenedLoadout);
474480

475481
await BackupNewFiles(loadout, fileTree);
482+
_diskStateRegistry.SaveState(loadout.LoadoutId, diskState);
476483

477484
return newLoadout;
478485
}

src/NexusMods.DataModel/Loadouts/LoadoutRegistry.cs

+3-1
Original file line numberDiff line numberDiff line change
@@ -426,11 +426,13 @@ public async Task<LoadoutMarker> Manage(GameInstallation installation, string na
426426
name = SuggestName(installation);
427427

428428
var result = await installation.Game.Synchronizer.Manage(installation);
429-
Alter(result.LoadoutId, $"Manage new instance of {installation.Game.Name} as {name}",
429+
result = Alter(result.LoadoutId, $"Manage new instance of {installation.Game.Name} as {name}",
430430
_ => result with
431431
{
432432
Name = name
433433
});
434+
var withExtraFiles = await installation.Game.Synchronizer.Ingest(result);
435+
Alter(result.LoadoutId, $"Adding extra files found in game folder", _ => withExtraFiles);
434436
return GetMarker(result.LoadoutId);
435437
}
436438

0 commit comments

Comments
 (0)