Nuke.Unreal
Build Unreal apps in Style.
Loading...
Searching...
No Matches
IUnrealLocator.cs
1
2using System.Collections.Generic;
3using System.IO;
4using Nuke.Common.IO;
5
6namespace Nuke.Unreal;
7
8/// <summary>
9/// Group an Unreal association with its actual path
10/// </summary>
11public record class UnrealInstance(string Name, AbsolutePath Path);
12
13/// <summary>
14/// Common interface for locating Unreal Engine instances in different environments
15/// </summary>
16public interface IUnrealLocator
17{
18 /// <summary>
19 /// List all installed Unreal Engine installation on current system
20 /// </summary>
21 IEnumerable<UnrealInstance> Instances { get; }
22
23 /// <summary>
24 /// Get the path to an installed engine by its name or its absolute path
25 /// </summary>
26 /// <param name="name">
27 /// Engine association name, source GUID, plain version or absolute path to/of an installed engine
28 /// </param>
29 /// <returns>Path to engine or null if that couldn't have been inferred</returns>
30 AbsolutePath? GetEngine(string name);
31}
32
33/// <summary>
34/// Static functions and common utilities for locating Unreal Engine
35/// </summary>
36public static class UnrealLocator
37{
38 /// <summary>
39 /// Extend input path (presumably to an Unreal Engine installation) to its location of Build.version
40 /// </summary>
41 public static AbsolutePath GetUnrealBuildVersionPath(this AbsolutePath enginePath)
42 => enginePath / "Engine" / "Build" / "Build.version";
43
44 /// <summary>
45 /// Validate input path if it's a proper Unreal Engine installation, return null if it isn't
46 /// </summary>
47 public static AbsolutePath? ExistingUnrealEngine(this AbsolutePath? enginePath)
48 => enginePath?.GetUnrealBuildVersionPath()?.FileExists() ?? false
49 ? enginePath
50 : null;
51
52 /// <summary>
53 /// Validate input path (as string) if it's a proper Unreal Engine installation, return null if it isn't
54 /// </summary>
55 public static AbsolutePath? GetExistingUnrealEngine(string name)
56 => Path.IsPathRooted(name)
57 ? AbsolutePath.Create(name).ExistingUnrealEngine()
58 : null;
59
60 /// <summary>
61 /// Is input path points to a valid Unreal Engine installation
62 /// </summary>
63 /// <param name="enginePath"></param>
64 /// <returns></returns>
65 public static bool IsUnrealEnginePath(this AbsolutePath? enginePath)
66 => enginePath.ExistingUnrealEngine() != null;
67}
68
69/// <summary>
70/// An empty Unreal Locator implementation which doesn't know about installed instances, but it will
71/// validate an absolute input path of a potential Unreal Engine installation
72/// </summary>
74{
75 public IEnumerable<UnrealInstance> Instances => [];
76
77 public AbsolutePath? GetEngine(string name) => UnrealLocator.GetExistingUnrealEngine(name);
78}
An empty Unreal Locator implementation which doesn't know about installed instances,...
AbsolutePath? GetEngine(string name)
Get the path to an installed engine by its name or its absolute path.
Static functions and common utilities for locating Unreal Engine.
static ? AbsolutePath GetExistingUnrealEngine(string name)
Validate input path (as string) if it's a proper Unreal Engine installation, return null if it isn't.
static bool IsUnrealEnginePath(this AbsolutePath? enginePath)
Is input path points to a valid Unreal Engine installation.
static AbsolutePath GetUnrealBuildVersionPath(this AbsolutePath enginePath)
Extend input path (presumably to an Unreal Engine installation) to its location of Build....
static ? AbsolutePath ExistingUnrealEngine(this AbsolutePath? enginePath)
Validate input path if it's a proper Unreal Engine installation, return null if it isn't.
Common interface for locating Unreal Engine instances in different environments.
AbsolutePath? GetEngine(string name)
Get the path to an installed engine by its name or its absolute path.
record class UnrealInstance(string Name, AbsolutePath Path)
Group an Unreal association with its actual path.