Nuke.Unreal
Build Unreal apps in Style.
Loading...
Searching...
No Matches
WindowsUnrealLocator.cs
1
2using System.Collections.Generic;
3using Nuke.Common.IO;
4using Microsoft.Win32;
5using System.Runtime.InteropServices;
6using System;
7using Nuke.Common;
8using System.Linq;
9using Nuke.Common.Utilities;
10
11namespace Nuke.Unreal;
12
14{
15 public IEnumerable<UnrealInstance> Instances
16 {
17 get
18 {
19 if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
20 {
21 using (var installed = Registry.LocalMachine.OpenSubKey(@"SOFTWARE\EpicGames\Unreal Engine"))
22 {
23 if (installed != null)
24 {
25 foreach (var subKeyName in installed.GetSubKeyNames())
26 {
27 using var subKey = installed.OpenSubKey(subKeyName)!;
28 var candidate = subKey.GetValue("InstalledDirectory") as string;
29 if (candidate == null) continue;
30
31 var path = AbsolutePath.Create(candidate);
32 if (!path.DirectoryExists()) continue;
33 yield return new(subKeyName, path);
34 }
35 }
36 }
37 using (var sources = Registry.CurrentUser.OpenSubKey(@"Software\Epic Games\Unreal Engine\Builds"))
38 {
39 if (sources != null)
40 {
41 foreach (var valueName in sources.GetValueNames())
42 {
43 var candidate = sources.GetValue(valueName) as string;
44 if (candidate == null) continue;
45
46 var path = AbsolutePath.Create(candidate);
47 if (!path.DirectoryExists()) continue;
48 yield return new(valueName, path);
49 }
50 }
51 }
52 yield break;
53 }
54 else throw new Exception("Trying to use windows implementation of IUnrealLocator on a non-windows platform");
55 }
56 }
57
58 public AbsolutePath? GetEngine(string name)
59 {
60 var explicitPath = UnrealLocator.GetExistingUnrealEngine(name);
61 if (explicitPath != null) return explicitPath;
62
63 var instance = Instances.FirstOrDefault(i => i.Name.EqualsOrdinalIgnoreCase(name));
64 return instance?.Path;
65 }
66}
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.
IEnumerable< UnrealInstance > Instances
List all installed Unreal Engine installation on current system.
AbsolutePath? GetEngine(string name)
Get the path to an installed engine by its name or its absolute path.
Common interface for locating Unreal Engine instances in different environments.