Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update CLI params #5

Merged
merged 6 commits into from
Aug 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,6 @@ jobs:
# Change into the artifacts directory to avoid including the directory itself in the zip archive
working-directory: ./releases/net8.0
run: zip -r ../ModVerify-Net8.zip .
- name: Rename .NET Framework executable
run: mv ./releases/net48/ModVerify.CliApp.exe ./releases/net48/ModVerify.exe
- uses: dotnet/[email protected]
id: nbgv
- name: Create GitHub release
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ A `.JSON` file lists all found issues. Into seperate `.txt` files the same error

You can also run the tool with command line arguments to adjust the tool to your needs.

To see all available options, open the command line and type:
To see all available options, especially if you have custom folder setups, open the command line and type:

```bash
ModVerify.exe --help
Expand Down
17 changes: 17 additions & 0 deletions src/ModVerify.CliApp/ExtensionMethods.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
using PG.StarWarsGame.Engine;
using PG.StarWarsGame.Infrastructure.Games;

namespace AET.ModVerifyTool;

internal static class ExtensionMethods
{
public static GameEngineType ToEngineType(this GameType type)
{
return type == GameType.Foc ? GameEngineType.Foc : GameEngineType.Eaw;
}

public static GameType FromEngineType(this GameEngineType type)
{
return type == GameEngineType.Foc ? GameType.Foc : GameType.Eaw;
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
using PG.StarWarsGame.Infrastructure.Games;

namespace ModVerify.CliApp;
namespace AET.ModVerifyTool.GameFinder;

internal record GameFinderResult(IGame Game, IGame? FallbackGame);
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
using System.Globalization;
using System.IO.Abstractions;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
Expand All @@ -10,7 +11,7 @@
using PG.StarWarsGame.Infrastructure.Services.Dependencies;
using PG.StarWarsGame.Infrastructure.Services.Detection;

namespace ModVerify.CliApp;
namespace AET.ModVerifyTool.GameFinder;

internal class GameFinderService
{
Expand Down Expand Up @@ -40,33 +41,34 @@ public GameFinderResult FindGames()
return FindGames(detectors);
}

public GameFinderResult FindGamesFromPath(string path)
public GameFinderResult FindGamesFromPathOrGlobal(string path)
{
// There are three common situations:
// There are four common situations:
// 1. path points to the actual game directory
// 2. path points to a local mod in game/Mods/ModDir
// 3. path points to a workshop mod
// 4. path points to a "detached mod" at a completely different location
var givenDirectory = _fileSystem.DirectoryInfo.New(path);
var possibleGameDir = givenDirectory.Parent?.Parent;
var possibleSteamAppsFolder = givenDirectory.Parent?.Parent?.Parent?.Parent?.Parent;

var detectors = new List<IGameDetector>
{
// Case 1
new DirectoryGameDetector(givenDirectory, _serviceProvider)
};

// Case 2
if (possibleGameDir is not null)
detectors.Add(new DirectoryGameDetector(possibleGameDir, _serviceProvider));

if (possibleSteamAppsFolder is not null && possibleSteamAppsFolder.Name == "steamapps" && uint.TryParse(givenDirectory.Name, out _))
detectors.Add(new SteamPetroglyphStarWarsGameDetector(_serviceProvider));

// Cases 3 & 4
detectors.Add(new SteamPetroglyphStarWarsGameDetector(_serviceProvider));
return FindGames(detectors);
}

private bool TryDetectGame(GameType gameType, IList<IGameDetector> detectors, out GameDetectionResult result)
{
var gd = new CompositeGameDetector(detectors, _serviceProvider, true);
var gd = new CompositeGameDetector(detectors, _serviceProvider);
result = gd.Detect(new GameDetectorOptions(gameType));

if (result.Error is not null)
Expand All @@ -80,48 +82,22 @@ private bool TryDetectGame(GameType gameType, IList<IGameDetector> detectors, ou
return true;
}


private void SetupMods(IGame game)
{
var modFinder = _serviceProvider.GetRequiredService<IModReferenceFinder>();
var modRefs = modFinder.FindMods(game);

var mods = new List<IMod>();

foreach (var modReference in modRefs)
{
var mod = _modFactory.FromReference(game, modReference);
mods.AddRange(mod);
}

foreach (var mod in mods)
game.AddMod(mod);

// Mods need to be added to the game first, before resolving their dependencies.
foreach (var mod in mods)
{
var resolver = _serviceProvider.GetRequiredService<IDependencyResolver>();
mod.ResolveDependencies(resolver,
new DependencyResolverOptions { CheckForCycle = true, ResolveCompleteChain = true });
}
}

private GameFinderResult FindGames(IList<IGameDetector> detectors)
{
// FoC needs to be tried first
if (!TryDetectGame(GameType.Foc, detectors, out var result))
{
_logger?.LogTrace("Unable to find FoC installation. Trying again with EaW...");
if (!TryDetectGame(GameType.EaW, detectors, out result))
throw new GameException("Unable to find game installation: Wrong install path?");
if (!TryDetectGame(GameType.Eaw, detectors, out result))
throw new GameNotFoundException("Unable to find game installation: Wrong install path?");
}

if (result.GameLocation is null)
throw new GameException("Unable to find game installation: Wrong install path?");
throw new GameNotFoundException("Unable to find game installation: Wrong install path?");

_logger?.LogTrace($"Found game installation: {result.GameIdentity} at {result.GameLocation.FullName}");

var game = _gameFactory.CreateGame(result);
var game = _gameFactory.CreateGame(result, CultureInfo.InvariantCulture);

SetupMods(game);

Expand All @@ -137,16 +113,41 @@ private GameFinderResult FindGames(IList<IGameDetector> detectors)
else
throw new NotImplementedException("Searching fallback game for non-Steam games is currently is not yet implemented.");

if (!TryDetectGame(GameType.EaW, fallbackDetectors, out var fallbackResult) || fallbackResult.GameLocation is null)
throw new GameException("Unable to find fallback game installation: Wrong install path?");
if (!TryDetectGame(GameType.Eaw, fallbackDetectors, out var fallbackResult) || fallbackResult.GameLocation is null)
throw new GameNotFoundException("Unable to find fallback game installation: Wrong install path?");

_logger?.LogTrace($"Found fallback game installation: {fallbackResult.GameIdentity} at {fallbackResult.GameLocation.FullName}");

fallbackGame = _gameFactory.CreateGame(fallbackResult);
fallbackGame = _gameFactory.CreateGame(fallbackResult, CultureInfo.InvariantCulture);

SetupMods(fallbackGame);
}

return new GameFinderResult(game, fallbackGame);
}

private void SetupMods(IGame game)
{
var modFinder = _serviceProvider.GetRequiredService<IModReferenceFinder>();
var modRefs = modFinder.FindMods(game);

var mods = new List<IMod>();

foreach (var modReference in modRefs)
{
var mod = _modFactory.FromReference(game, modReference, CultureInfo.InvariantCulture);
mods.AddRange(mod);
}

foreach (var mod in mods)
game.AddMod(mod);

// Mods need to be added to the game first, before resolving their dependencies.
foreach (var mod in mods)
{
var resolver = _serviceProvider.GetRequiredService<IDependencyResolver>();
mod.ResolveDependencies(resolver,
new DependencyResolverOptions { CheckForCycle = true, ResolveCompleteChain = true });
}
}
}
5 changes: 5 additions & 0 deletions src/ModVerify.CliApp/GameNotFoundException.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
using PG.StarWarsGame.Infrastructure.Games;

namespace AET.ModVerifyTool;

internal class GameNotFoundException(string message) : GameException(message);
141 changes: 0 additions & 141 deletions src/ModVerify.CliApp/ModOrGameSelector.cs

This file was deleted.

10 changes: 0 additions & 10 deletions src/ModVerify.CliApp/ModSelectionResult.cs

This file was deleted.

Loading
Loading