using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace UnrealBuildTool
{
///
/// Holds information about the current engine version
///
[Serializable]
public class BuildVersion
{
///
/// The major engine version (4 for UE4)
///
public int MajorVersion;
///
/// The minor engine version
///
public int MinorVersion;
///
/// The hotfix/patch version
///
public int PatchVersion;
///
/// The changelist that the engine is being built from
///
public int Changelist;
///
/// The changelist that the engine maintains compatibility with
///
public int CompatibleChangelist;
///
/// Whether the changelist numbers are a licensee changelist
///
public int IsLicenseeVersion;
///
/// Whether the current build is a promoted build, that is, built strictly from a clean sync of the given changelist
///
public int IsPromotedBuild;
///
/// Name of the current branch, with '/' characters escaped as '+'
///
public string BranchName;
///
/// Returns the value which can be used as the compatible changelist. Requires that the regular changelist is also set, and defaults to the
/// regular changelist if a specific compatible changelist is not set.
///
public int EffectiveCompatibleChangelist
{
get { return (Changelist != 0 && CompatibleChangelist != 0)? CompatibleChangelist : Changelist; }
}
///
/// Try to read a version file from disk
///
/// The version information
/// True if the version was read sucessfully, false otherwise
public static bool TryRead(out BuildVersion Version)
{
return TryRead(GetDefaultFileName(), out Version);
}
///
/// Try to read a version file from disk
///
/// Path to the version file
/// The version information
/// True if the version was read sucessfully, false otherwise
public static bool TryRead(string FileName, out BuildVersion Version)
{
JsonObject Object;
if (!JsonObject.TryRead(FileName, out Object))
{
Version = null;
return false;
}
return TryParse(Object, out Version);
}
///
/// Get the default path to the build.version file on disk
///
/// Path to the Build.version file
public static string GetDefaultFileName()
{
return FileReference.Combine(UnrealBuildTool.EngineDirectory, "Build", "Build.version").FullName;
}
///
/// Parses a build version from a JsonObject
///
/// The object to read from
/// The resulting version field
/// True if the build version could be read, false otherwise
public static bool TryParse(JsonObject Object, out BuildVersion Version)
{
BuildVersion NewVersion = new BuildVersion();
if (!Object.TryGetIntegerField("MajorVersion", out NewVersion.MajorVersion) || !Object.TryGetIntegerField("MinorVersion", out NewVersion.MinorVersion) || !Object.TryGetIntegerField("PatchVersion", out NewVersion.PatchVersion))
{
Version = null;
return false;
}
Object.TryGetIntegerField("Changelist", out NewVersion.Changelist);
Object.TryGetIntegerField("CompatibleChangelist", out NewVersion.CompatibleChangelist);
Object.TryGetIntegerField("IsLicenseeVersion", out NewVersion.IsLicenseeVersion);
Object.TryGetIntegerField("IsPromotedBuild", out NewVersion.IsPromotedBuild);
Object.TryGetStringField("BranchName", out NewVersion.BranchName);
Version = NewVersion;
return true;
}
///
/// Exports this object as Json
///
/// The filename to write to
/// True if the build version could be read, false otherwise
public void Write(string FileName)
{
using (JsonWriter Writer = new JsonWriter(FileName))
{
Writer.WriteObjectStart();
WriteProperties(Writer);
Writer.WriteObjectEnd();
}
}
///
/// Exports this object as Json
///
/// The json writer to receive the version settings
/// True if the build version could be read, false otherwise
public void WriteProperties(JsonWriter Writer)
{
Writer.WriteValue("MajorVersion", MajorVersion);
Writer.WriteValue("MinorVersion", MinorVersion);
Writer.WriteValue("PatchVersion", PatchVersion);
Writer.WriteValue("Changelist", Changelist);
Writer.WriteValue("CompatibleChangelist", CompatibleChangelist);
Writer.WriteValue("IsLicenseeVersion", IsLicenseeVersion);
Writer.WriteValue("IsPromotedBuild", IsPromotedBuild);
Writer.WriteValue("BranchName", BranchName);
}
}
}