using System.Reflection; using System; using System.Text.RegularExpressions; using System.Linq; using UnityEngine; using Perforce.P4; namespace P4Connect { /// /// Version wrappers for P4Connect /// public static class Version { public static string appName = "p4connect"; public static string perforceRelease = "2016.1.0.0"; // Cache _PerforceReleaseString for re-use private static string _PerforceReleaseString = null; private static string _BuildType = ""; private static string _BuildString = ""; private static string changeIdStr; #if DEBUG private static string _build = "Debug"; #else private static string _build = "Release"; #endif public static string Build { get { if (_BuildString != null) { _BuildString = _build; } return _BuildString; } } public static string ChangeId { get { string change = " $Change: 18418 $"; // File must be stored +k so the RCS Keyword expands if (String.IsNullOrEmpty(changeIdStr)) { changeIdStr = Regex.Match(change, @"\d+").Value; } return changeIdStr; } } public static string PerforceReleaseString { get { if (_PerforceReleaseString != null) return _PerforceReleaseString; char[] delims = { '.' }; string[] fields = perforceRelease.Split(delims); // If UpdateVersion.exe is missing, perforceRelease will be unchanged, // so we instead generate the last two version fields from the contents of the "Change" RCS Keyword if (fields[2].Equals("0") && fields[3].Equals("0") && ChangeId.ToCharArray().Any(char.IsDigit)) { // Convert change ID into last two fields of version string. each field is limited to 16 bits, so we split values so they look appropriate in decimal. int changeId = Convert.ToInt32(ChangeId); fields[2] = (changeId / 10000).ToString(); fields[3] = (changeId % 10000).ToString(); _BuildType = "W"; // Mark workshop builds } _PerforceReleaseString = string.Join(".",fields) + _BuildType; return _PerforceReleaseString; } } static Options NameVerOpts = null; // Create an Array of options for the Connect call. You can see these in the Perforce server log public static Options ConnectOptions { get { if (NameVerOpts == null) { NameVerOpts = new Options(); NameVerOpts.Add("ProgramName", appName); NameVerOpts.Add("ProgramVersion", PerforceReleaseString); } return NameVerOpts; } } } }