-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathGameExecutableFileUtilities.cs
More file actions
61 lines (52 loc) · 2.34 KB
/
Copy pathGameExecutableFileUtilities.cs
File metadata and controls
61 lines (52 loc) · 2.34 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
using System;
using System.IO;
using System.IO.Abstractions;
using System.Linq;
using PG.StarWarsGame.Infrastructure.Games;
namespace PG.StarWarsGame.Infrastructure.Clients.Utilities;
/// <summary>
/// Provides utility methods for locating game executable files for different game platforms and build types.
/// </summary>
public static class GameExecutableFileUtilities
{
private const string SteamFileNameBase = "StarWars";
private const string SteamReleaseSuffix = "G";
private const string SteamDebugSuffix = "I";
/// <summary>
/// Gets the executable file for the specified game and build type or <see langword="null"/> if not found.
/// </summary>
/// <param name="game">The game for which to locate the executable file.</param>
/// <param name="buildType">The build type of the game executable to locate.</param>
/// <returns>An <see cref="IFileInfo"/> representing the executable file if found; otherwise, <see langword="null"/>.</returns>
/// <exception cref="ArgumentNullException"><paramref name="game"/> is <see langword="null"/>.</exception>
public static IFileInfo? GetExecutableForGame(IGame game, GameBuildType buildType)
{
if (game == null)
throw new ArgumentNullException(nameof(game));
// Only SteamGold supports debug builds
if (buildType == GameBuildType.Debug && game.Platform != GamePlatform.SteamGold)
return null;
var exeFileName = GetExecutableFileName(game, buildType);
return game.Directory
.EnumerateFiles(exeFileName, SearchOption.TopDirectoryOnly)
.FirstOrDefault();
}
private static string GetExecutableFileName(IGame game, GameBuildType buildType)
{
if (game.Platform == GamePlatform.SteamGold)
return GetSteamFileName(buildType);
return game.Type switch
{
GameType.Eaw => PetroglyphStarWarsGameConstants.EmpireAtWarExeFileName,
GameType.Foc => PetroglyphStarWarsGameConstants.ForcesOfCorruptionExeFileName,
_ => throw new ArgumentOutOfRangeException()
};
}
private static string GetSteamFileName(GameBuildType buildType)
{
var suffix = SteamReleaseSuffix;
if (buildType == GameBuildType.Debug)
suffix = SteamDebugSuffix;
return $"{SteamFileNameBase}{suffix}.exe";
}
}