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 System.IO;
8using Nuke.Common;
9using System.Linq;
10using Nuke.Common.Utilities;
11
12namespace Nuke.Unreal;
13
15{
16 public IEnumerable<UnrealInstance> Instances
17 {
18 get
19 {
20 if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
21 {
22 var discovered = new HashSet<AbsolutePath>();
23 var launcherDatRelative = "UnrealEngineLauncher/LauncherInstalled.dat";
24 var centralLauncherDat = EnvironmentInfo.SpecialFolder(SpecialFolders.CommonApplicationData) / "Epic" / launcherDatRelative;
25 var userLauncherDat = EnvironmentInfo.SpecialFolder(SpecialFolders.LocalApplicationData) / launcherDatRelative;
26
27 foreach (var instance in LauncherInstalledList.FromFile(centralLauncherDat))
28 {
29 if (discovered.Add(instance.Path))
30 yield return instance;
31 }
32 foreach (var instance in LauncherInstalledList.FromFile(userLauncherDat))
33 {
34 if (discovered.Add(instance.Path))
35 yield return instance;
36 }
37
38 // Engines installed into program files may not be submitted in registry automatically, pure speculation tho
39 // var epicGamesProgramFiles = EnvironmentInfo.SpecialFolder(SpecialFolders.ProgramFiles) / "Epic Games";
40 // foreach (var engineCandidate in epicGamesProgramFiles.GlobDirectories("UE_*"))
41 // {
42 // if ((engineCandidate / "Engine/Build/Build.version").FileExists())
43 // {
44 // var name = engineCandidate.Name.Replace("UE_", "");
45 //
46 // if (discovered.Add(engineCandidate))
47 // yield return new (name, engineCandidate);
48 // }
49 // }
50 using (var installed = Registry.LocalMachine.OpenSubKey(@"SOFTWARE\EpicGames\Unreal Engine"))
51 {
52 if (installed != null)
53 {
54 foreach (var subKeyName in installed.GetSubKeyNames())
55 {
56 using var subKey = installed.OpenSubKey(subKeyName)!;
57 var candidate = subKey.GetValue("InstalledDirectory") as string;
58 if (candidate == null) continue;
59
60 var path = AbsolutePath.Create(candidate);
61 if (!path.DirectoryExists()) continue;
62
63 if (discovered.Add(path))
64 yield return new(subKeyName, path);
65 }
66 }
67 }
68 using (var sources = Registry.CurrentUser.OpenSubKey(@"Software\Epic Games\Unreal Engine\Builds"))
69 {
70 if (sources != null)
71 {
72 foreach (var valueName in sources.GetValueNames())
73 {
74 var candidate = sources.GetValue(valueName) as string;
75 if (candidate == null) continue;
76
77 var path = AbsolutePath.Create(candidate);
78 if (!path.DirectoryExists()) continue;
79
80 var instanceName = valueName;
81 if (Unreal.IsInstalled(path))
82 {
83 var buildVersion = Unreal.GetBuildVersion(path);
84 instanceName = $"{buildVersion.MajorVersion}.{buildVersion.MinorVersion}";
85 }
86
87 if (discovered.Add(path))
88 yield return new(instanceName, path);
89 }
90 }
91 }
92 yield break;
93 }
94 else throw new Exception("Trying to use windows implementation of IUnrealLocator on a non-windows platform");
95 }
96 }
97
98 public AbsolutePath? GetEngine(string name)
99 {
100 var explicitPath = UnrealLocator.GetExistingUnrealEngine(name);
101 if (explicitPath != null) return explicitPath;
102
103 var instance = Instances.FirstOrDefault(i => i.Name.EqualsOrdinalIgnoreCase(name));
104 return instance?.Path;
105 }
106}
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.
A collection of utilities around basic functions regarding the environment of the Engine we're workin...
Definition Unreal.cs:24
static UnrealBuildVersion GetBuildVersion(AbsolutePath enginePath)
Gets the parsed content of Build.version file of an engine instance.
Definition Unreal.cs:162
static bool IsInstalled(AbsolutePath enginePath)
Is given path a vanilla engine most probably installed via the Marketplace?
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.
record class LauncherInstalledList(List< LauncherInstalledItem > InstallationList)
Represents the whole LauncherInstalled file.