Skip to content

Commit

Permalink
Fix tons of little issues found while running the app through the UI (#…
Browse files Browse the repository at this point in the history
…757)

* Fix tons of little issues found while running the app through the UI

* Fix a few tests
  • Loading branch information
halgari committed Nov 8, 2023
1 parent 7a99726 commit 7130223
Show file tree
Hide file tree
Showing 6 changed files with 65 additions and 3 deletions.
5 changes: 4 additions & 1 deletion src/NexusMods.App.UI/LeftMenu/Items/LaunchButtonViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,10 @@ private async Task LaunchGame(CancellationToken token)
Label = Language.LaunchButtonViewModel_LaunchGame_RUNNING;
var marker = _loadoutRegistry.GetMarker(LoadoutId);
var tool = _toolManager.GetTools(marker.Value).OfType<IRunGameTool>().First();
await _toolManager.RunTool(tool, marker.Value, token: token);
await Task.Run(async () =>
{
await _toolManager.RunTool(tool, marker.Value, token: token);
}, token);
Label = Language.LaunchButtonViewModel_LaunchGame_LAUNCH;
}
}
8 changes: 7 additions & 1 deletion src/NexusMods.App.UI/RightContent/FoundGamesViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,13 @@ public void InitializeFromFound(IEnumerable<IGame> games)
{
var vm = _provider.GetRequiredService<IGameWidgetViewModel>();
vm.Installation = install;
vm.PrimaryButton = ReactiveCommand.CreateFromTask(() => ManageGame(install));
vm.PrimaryButton = ReactiveCommand.CreateFromTask(async () =>
{
await Task.Run(async () =>
{
await ManageGame(install);
});
});
return vm;
});
Games = new ReadOnlyObservableCollection<IGameWidgetViewModel>(new ObservableCollection<IGameWidgetViewModel>(installed));
Expand Down
1 change: 1 addition & 0 deletions src/NexusMods.CLI/Services.cs
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ public static IServiceCollection AddCLI(this IServiceCollection services)
.AddVerb<AddGame>()
.AddVerb<AnalyzeArchive>()
.AddVerb<Apply>()
.AddVerb<Ingest>()
.AddVerb<AssociateNxm>()
.AddVerb<ChangeTracking>()
.AddVerb<DownloadAndInstallMod>()
Expand Down
43 changes: 43 additions & 0 deletions src/NexusMods.CLI/Verbs/Ingest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
using NexusMods.Abstractions.CLI;
using NexusMods.DataModel.Loadouts.Extensions;
using NexusMods.DataModel.Loadouts.Markers;
using NexusMods.Paths;

namespace NexusMods.CLI.Verbs;

// ReSharper disable once ClassNeverInstantiated.Global
/// <summary>
/// Compute and run the steps needed to apply a Loadout to a game folder
/// </summary>
public class Ingest : AVerb<LoadoutMarker>, IRenderingVerb
{
/// <inheritdoc />
public IRenderer Renderer { get; set; } = null!;

/// <summary>
/// DI constructor
/// </summary>
/// <param name="loadoutSynchronizer"></param>
public Ingest()
{
}

/// <inheritdoc />
public static VerbDefinition Definition => new("ingest", "Ingest changes from the game folders into the given loadout", new OptionDefinition[]
{
new OptionDefinition<LoadoutMarker>("l", "loadout", "Loadout ingest changes into"),
});

/// <inheritdoc />
public async Task<int> Run(LoadoutMarker loadout, CancellationToken token)
{
var state = await Renderer.WithProgress(token,
async () => await loadout.Value.Ingest());

loadout.Alter("Ingest changes from the game folder", _ => state);

await Renderer.Render($"Ingested game folder changes into {loadout.Value.Name}");

return 0;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -137,13 +137,19 @@ await foreach (var entry in _hashCache.IndexFolderAsync(location))
continue;
}

resultingItems.Add(newEntry.Path, prevEntry.Value);
switch (newEntry.Value!)
{

case StoredFile fa:
// StoredFile files are special cased so we can batch them up and extract them all at once.
// Don't add toExtract to the results yet as we'll need to get the modified file times
// after we extract them

// If both hashes are the same, we can skip this file
if (fa.Hash == entry.Hash)
continue;

toExtract.Add(KeyValuePair.Create(entry.Path, fa));
continue;
case IGeneratedFile gf and IToFile:
Expand Down Expand Up @@ -473,6 +479,7 @@ public virtual async Task<Loadout> Ingest(Loadout loadout)
var newLoadout = await FlattenedLoadoutToLoadout(flattenedLoadout, loadout, prevFlattenedLoadout);

await BackupNewFiles(loadout, fileTree);
_diskStateRegistry.SaveState(loadout.LoadoutId, diskState);

return newLoadout;
}
Expand Down
4 changes: 3 additions & 1 deletion src/NexusMods.DataModel/Loadouts/LoadoutRegistry.cs
Original file line number Diff line number Diff line change
Expand Up @@ -426,11 +426,13 @@ public async Task<LoadoutMarker> Manage(GameInstallation installation, string na
name = SuggestName(installation);

var result = await installation.Game.Synchronizer.Manage(installation);
Alter(result.LoadoutId, $"Manage new instance of {installation.Game.Name} as {name}",
result = Alter(result.LoadoutId, $"Manage new instance of {installation.Game.Name} as {name}",
_ => result with
{
Name = name
});
var withExtraFiles = await installation.Game.Synchronizer.Ingest(result);
Alter(result.LoadoutId, $"Adding extra files found in game folder", _ => withExtraFiles);
return GetMarker(result.LoadoutId);
}

Expand Down

0 comments on commit 7130223

Please sign in to comment.