Skip to content

feat(#6): Auto-detect game installation directory#46

Open
ModerRAS wants to merge 1 commit intomasterfrom
feature/issue-6-auto-detect-game-directory
Open

feat(#6): Auto-detect game installation directory#46
ModerRAS wants to merge 1 commit intomasterfrom
feature/issue-6-auto-detect-game-directory

Conversation

@ModerRAS
Copy link
Copy Markdown
Contributor

Summary

  • Create IGameDirectoryScanner interface for game directory scanning
  • Implement GameDirectoryScanner with Steam/GOG/Epic detection
  • Support cross-platform paths (Windows, Linux, macOS)
  • Add comprehensive unit tests
  • Register service in DI container

Changes

  • BannerlordModEditor.Common/Services/IGameDirectoryScanner.cs - Interface definition
  • BannerlordModEditor.Common/Services/GameDirectoryScanner.cs - Implementation
  • BannerlordModEditor.Common.Tests/Services/GameDirectoryScannerTests.cs - Unit tests
  • BannerlordModEditor.UI/App.axaml.cs - DI registration

Closes #6

- Create IGameDirectoryScanner interface for game directory scanning
- Implement GameDirectoryScanner with Steam/GOG/Epic detection
- Support cross-platform paths (Windows, Linux, macOS)
- Add comprehensive unit tests
- Register service in DI container

Closes #6
Copilot AI review requested due to automatic review settings March 20, 2026 01:17
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds an auto-detection service to locate Mount & Blade II: Bannerlord installation directories across common launchers/platforms, and wires it into the UI via DI.

Changes:

  • Introduced IGameDirectoryScanner + DTO (GameDirectoryInfo) for reporting detected installs
  • Implemented GameDirectoryScanner with Steam/GOG/Epic path heuristics and basic validation/version reading
  • Added xUnit tests and registered the scanner in the UI DI container

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 5 comments.

File Description
BannerlordModEditor.UI/App.axaml.cs Registers the new directory scanner service in DI
BannerlordModEditor.Common/Services/IGameDirectoryScanner.cs Defines scanning API and the GameDirectoryInfo model
BannerlordModEditor.Common/Services/GameDirectoryScanner.cs Implements multi-launcher directory detection + validation/version parsing
BannerlordModEditor.Common.Tests/Services/GameDirectoryScannerTests.cs Adds unit tests for validation/version parsing and scan behavior

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +169 to +181
var trimmed = line.Trim();
if (trimmed.StartsWith("\"path\"", StringComparison.OrdinalIgnoreCase))
{
var parts = trimmed.Split('"', StringSplitOptions.RemoveEmptyEntries);
if (parts.Length >= 4)
{
var path = parts[3].Replace("\\\\", "\\");
if (Directory.Exists(path))
{
paths.Add(path);
}
}
}
Copy link

Copilot AI Mar 20, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

libraryfolders.vdf lines like "path" "D:\\SteamLibrary" will typically split into 2 tokens (path, D:\\SteamLibrary) with the current Split('"', RemoveEmptyEntries) usage, so parts.Length >= 4 will never be satisfied and Steam libraries from the VDF won’t be discovered. Consider parsing the VDF with a more robust approach (e.g., regex to capture the second quoted string, or a minimal VDF parser) and extracting the value token directly.

Copilot uses AI. Check for mistakes.
Comment on lines +184 to +186
catch
{
}
Copy link

Copilot AI Mar 20, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Swallowing all exceptions silently makes detection failures hard to diagnose (e.g., malformed VDF, permission issues). At minimum, catch specific exceptions and either log/debug-trace them or include a comment explaining why it’s safe to ignore; otherwise troubleshooting “why auto-detect doesn’t work” becomes very difficult.

Copilot uses AI. Check for mistakes.
Comment on lines +65 to +67
/// ModuleData目录路径
/// </summary>
public string ModuleDataPath { get; set; } = string.Empty;
Copy link

Copilot AI Mar 20, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ModuleDataPath (and its comment) is misleading: the implementation sets this to the Modules directory, not a ModuleData directory. Since this is a public DTO, it will leak into consumers and be confusing; rename to something accurate like ModulesPath (and update the XML comment accordingly).

Suggested change
/// ModuleData目录路径
/// </summary>
public string ModuleDataPath { get; set; } = string.Empty;
/// Modules目录路径
/// </summary>
public string ModulesPath { get; set; } = string.Empty;

Copilot uses AI. Check for mistakes.
{
public class GameDirectoryScanner : IGameDirectoryScanner
{
private const string BannerlordAppId = "261550";
Copy link

Copilot AI Mar 20, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

BannerlordAppId is currently unused in this implementation, which adds noise and suggests incomplete/abandoned logic. Either remove it, or use it to improve Steam/Epic detection (e.g., by correlating app manifests) so the constant has a clear purpose.

Suggested change
private const string BannerlordAppId = "261550";

Copilot uses AI. Check for mistakes.
Comment on lines +18 to +23
[Fact]
public async Task ScanForGameDirectoriesAsync_ReturnsEmptyListWhenNoGameInstalled()
{
var result = await _scanner.ScanForGameDirectoriesAsync();
Assert.NotNull(result);
}
Copy link

Copilot AI Mar 20, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This test name claims the result is empty “when no game installed”, but it only asserts NotNull and also depends on the machine’s real Steam/GOG/Epic state (making it non-deterministic and potentially slow). To make it a real unit test, inject filesystem/environment dependencies (or an abstraction) and assert the expected contents (e.g., empty list) using a controlled fake setup.

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Feature] 自动识别骑砍2的安装目录

2 participants