|
6 | 6 |
|
7 | 7 | namespace PG.StarWarsGame.Infrastructure.Clients.Utilities; |
8 | 8 |
|
9 | | -internal class GameExecutableFileUtilities |
| 9 | +/// <summary> |
| 10 | +/// Provides utility methods for locating game executable files for different game platforms and build types. |
| 11 | +/// </summary> |
| 12 | +public static class GameExecutableFileUtilities |
10 | 13 | { |
11 | 14 | private const string SteamFileNameBase = "StarWars"; |
12 | 15 | private const string SteamReleaseSuffix = "G"; |
13 | 16 | private const string SteamDebugSuffix = "I"; |
14 | 17 |
|
| 18 | + /// <summary> |
| 19 | + /// Gets the executable file for the specified game and build type or <see langword="null"/> if not found. |
| 20 | + /// </summary> |
| 21 | + /// <param name="game">The game for which to locate the executable file.</param> |
| 22 | + /// <param name="buildType">The build type of the game executable to locate.</param> |
| 23 | + /// <returns>An <see cref="IFileInfo"/> representing the executable file if found; otherwise, <see langword="null"/>.</returns> |
| 24 | + /// <exception cref="ArgumentNullException"><paramref name="game"/> is <see langword="null"/>.</exception> |
15 | 25 | public static IFileInfo? GetExecutableForGame(IGame game, GameBuildType buildType) |
16 | 26 | { |
17 | | - var exeFileName = GetExecutableFileName(game, buildType); |
| 27 | + if (game == null) |
| 28 | + throw new ArgumentNullException(nameof(game)); |
18 | 29 |
|
19 | | - if (string.IsNullOrEmpty(exeFileName)) |
| 30 | + // Only SteamGold supports debug builds |
| 31 | + if (buildType == GameBuildType.Debug && game.Platform != GamePlatform.SteamGold) |
20 | 32 | return null; |
21 | 33 |
|
| 34 | + var exeFileName = GetExecutableFileName(game, buildType); |
| 35 | + |
22 | 36 | return game.Directory |
23 | | - .EnumerateFiles(exeFileName!, SearchOption.TopDirectoryOnly) |
| 37 | + .EnumerateFiles(exeFileName, SearchOption.TopDirectoryOnly) |
24 | 38 | .FirstOrDefault(); |
25 | 39 | } |
26 | 40 |
|
27 | | - private static string? GetExecutableFileName(IGame game, GameBuildType buildType) |
| 41 | + private static string GetExecutableFileName(IGame game, GameBuildType buildType) |
28 | 42 | { |
29 | 43 | if (game.Platform == GamePlatform.SteamGold) |
30 | 44 | return GetSteamFileName(buildType); |
31 | 45 |
|
32 | | - if (buildType is GameBuildType.Debug) |
33 | | - return null; |
34 | | - |
35 | 46 | return game.Type switch |
36 | 47 | { |
37 | 48 | GameType.Eaw => PetroglyphStarWarsGameConstants.EmpireAtWarExeFileName, |
|
0 commit comments