Nuke.Unreal
Build Unreal apps in Style.
Loading...
Searching...
No Matches
EngineVersion.cs
1using System;
2using System.Text.RegularExpressions;
3using System.IO;
4using Nuke.Common;
5using Nuke.Common.IO;
6using Newtonsoft.Json.Linq;
7using Serilog;
8
9using Nuke.Common.Utilities;
10
11namespace Nuke.Unreal
12{
13 /// <summary>
14 /// High level representation of an Unreal Engine version
15 /// </summary>
16 public partial class EngineVersion
17 {
18 private Version GetEngineSemVersion()
19 {
20 var buildVersionPath = EnginePath / "Engine" / "Build" / "Build.version";
21 Assert.FileExists(buildVersionPath, $"Specified path was not an Unreal Engine instance ({buildVersionPath})");
22
23 var buildVersion = JObject.Parse(File.ReadAllText(buildVersionPath));
24 return new(
25 buildVersion.GetPropertyValue<int>("MajorVersion"),
26 buildVersion.GetPropertyValue<int>("MinorVersion"),
27 buildVersion.GetPropertyValue<int>("PatchVersion")
28 );
29 }
30
31 /// <summary>
32 /// Parse a high-level version from an input version identifier (semantic, guid or path)
33 /// </summary>
34 public EngineVersion(string versionName)
35 {
36 VersionName = versionName;
37 EnginePath = Unreal.GetEnginePath(versionName);
38 }
39
40 /// <summary>
41 /// The canonical engine version name, only contains Major.Minor and may contain suffixes
42 /// like how Unreal Engine 5 Early Access did once (5.0AE)
43 /// </summary>
44 public string VersionName;
45 private Version? _semVersion = null;
46
47 /// <summary>
48 /// Semantical version representation of the given Unreal Engine
49 /// </summary>
50 public Version SemanticalVersion => _semVersion ??= GetEngineSemVersion();
51
52 /// <summary>
53 /// Only the Major.Minor version components, with extra information trimmed.
54 /// </summary>
55 public string VersionMinor => SemanticalVersion.Major + "." + SemanticalVersion.Minor;
56
57 /// <summary>
58 /// Only the full Major.Minor.Patch version components, with additional information trimmed.
59 /// </summary>
60 public string VersionPatch => SemanticalVersion.Major + "." + SemanticalVersion.Minor + "." + SemanticalVersion.Build;
61
62 /// <summary>
63 /// Cached engine path.
64 /// </summary>
65 public AbsolutePath EnginePath;
66
67 private int CompatibilityBaseExponent => SemanticalVersion.Major > 4 ? 32 : 0;
68 private ulong CompatibilityFlag => 1UL << (CompatibilityBaseExponent + SemanticalVersion.Minor);
69
70 /// <summary>
71 /// Compatibility flag equivalent for this version.
72 /// </summary>
74
75 /// <summary>
76 /// Check if given compatibility mask applies to this version too.
77 /// </summary>
78 public bool IsCompatibleWith(UnrealCompatibility compatibility)
79 {
80 return (compatibility & Compatibility) > 0;
81 }
82 }
83}
High level representation of an Unreal Engine version.
string VersionMinor
Only the Major.Minor version components, with extra information trimmed.
Version SemanticalVersion
Semantical version representation of the given Unreal Engine.
bool IsCompatibleWith(UnrealCompatibility compatibility)
Check if given compatibility mask applies to this version too.
AbsolutePath EnginePath
Cached engine path.
string VersionName
The canonical engine version name, only contains Major.Minor and may contain suffixes like how Unreal...
string VersionPatch
Only the full Major.Minor.Patch version components, with additional information trimmed.
UnrealCompatibility Compatibility
Compatibility flag equivalent for this version.
EngineVersion(string versionName)
Parse a high-level version from an input version identifier (semantic, guid or path)
A collection of utilities around basic functions regarding the environment of the Engine we're workin...
Definition Unreal.cs:24
static AbsolutePath GetEnginePath(string engineAssociation, bool ignoreCache=false)
Get the Unreal Engine path based on an input association text. (version, GUID or absolute path)
Definition Unreal.cs:116
UnrealCompatibility
A flag enum representation for checking the Unreal version compatibility of various features....