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