Files
UnrealEngine/Engine/Source/Programs/UnrealBuildTool/Platform/TVOS/UEDeployTVOS.cs
2025-05-18 13:04:45 +08:00

211 lines
8.7 KiB
C#

// Copyright Epic Games, Inc. All Rights Reserved.
using System;
using System.Collections.Generic;
using System.IO;
using System.Text;
using System.Xml.Linq;
using EpicGames.Core;
using Microsoft.Extensions.Logging;
namespace UnrealBuildTool
{
class UEDeployTVOS : UEDeployIOS
{
public UEDeployTVOS(ILogger InLogger)
: base(InLogger)
{
}
protected override string GetTargetPlatformName()
{
return "TVOS";
}
public static bool GenerateTVOSPList(string ProjectDirectory, bool bIsUnrealGame, string GameName, bool bIsClient, string ProjectName, string InEngineDir, string AppDirectory, UnrealPluginLanguage? UPL, string? BundleID, ILogger Logger)
{
// @todo tvos: THIS!
// generate the Info.plist for future use
string BuildDirectory = ProjectDirectory + "/Build/TVOS";
bool bSkipDefaultPNGs = false;
string IntermediateDirectory = (bIsUnrealGame ? InEngineDir : ProjectDirectory) + "/Intermediate/TVOS";
string PListFile = IntermediateDirectory + "/" + GameName + "-Info.plist";
// @todo tvos: This is really nasty - both IOS and TVOS are setting static vars
VersionUtilities.BuildDirectory = BuildDirectory;
VersionUtilities.GameName = GameName;
// read the old file
string OldPListData = File.Exists(PListFile) ? File.ReadAllText(PListFile) : "";
// get the settings from the ini file
// plist replacements
// @todo tvos: Are we going to make TVOS specific .ini files?
DirectoryReference? DirRef = bIsUnrealGame ? (!String.IsNullOrEmpty(UnrealBuildTool.GetRemoteIniPath()) ? new DirectoryReference(UnrealBuildTool.GetRemoteIniPath()!) : null) : new DirectoryReference(ProjectDirectory);
ConfigHierarchy Ini = ConfigCache.ReadHierarchy(ConfigHierarchyType.Engine, DirRef, UnrealTargetPlatform.IOS);
// bundle display name
string BundleDisplayName;
Ini.GetString("/Script/IOSRuntimeSettings.IOSRuntimeSettings", "BundleDisplayName", out BundleDisplayName);
// bundle identifier
string BundleIdentifier;
Ini.GetString("/Script/IOSRuntimeSettings.IOSRuntimeSettings", "BundleIdentifier", out BundleIdentifier);
if (!String.IsNullOrEmpty(BundleID))
{
BundleIdentifier = BundleID;
}
// bundle name
string BundleName;
Ini.GetString("/Script/IOSRuntimeSettings.IOSRuntimeSettings", "BundleName", out BundleName);
// short version string
string BundleShortVersion;
Ini.GetString("/Script/IOSRuntimeSettings.IOSRuntimeSettings", "VersionInfo", out BundleShortVersion);
// required capabilities
string RequiredCaps = "\t\t<string>arm64</string>\n";
// minimum iOS version
string MinVersionSetting = "";
Ini.GetString("/Script/IOSRuntimeSettings.IOSRuntimeSettings", "MinimumiOSVersion", out MinVersionSetting);
string MinVersion = GetMinimumOSVersion(MinVersionSetting, Logger);
// extra plist data
string ExtraData = "";
Ini.GetString("/Script/IOSRuntimeSettings.IOSRuntimeSettings", "AdditionalPlistData", out ExtraData);
// create the final display name, including converting all entities for XML use
string FinalDisplayName = BundleDisplayName.Replace("[PROJECT_NAME]", ProjectName).Replace("_", "");
FinalDisplayName = FinalDisplayName.Replace("&", "&amp;");
FinalDisplayName = FinalDisplayName.Replace("\"", "&quot;");
FinalDisplayName = FinalDisplayName.Replace("\'", "&apos;");
FinalDisplayName = FinalDisplayName.Replace("<", "&lt;");
FinalDisplayName = FinalDisplayName.Replace(">", "&gt;");
// generate the plist file
StringBuilder Text = new StringBuilder();
Text.AppendLine("<?xml version=\"1.0\" encoding=\"UTF-8\"?>");
Text.AppendLine("<!DOCTYPE plist PUBLIC \"-//Apple//DTD PLIST 1.0//EN\" \"http://www.apple.com/DTDs/PropertyList-1.0.dtd\">");
Text.AppendLine("<plist version=\"1.0\">");
Text.AppendLine("<dict>");
Text.AppendLine("\t<key>CFBundleDevelopmentRegion</key>");
Text.AppendLine("\t<string>en</string>");
Text.AppendLine("\t<key>CFBundleDisplayName</key>");
Text.AppendLine(String.Format("\t<string>{0}</string>", EncodeBundleName(BundleDisplayName, ProjectName)));
Text.AppendLine("\t<key>CFBundleExecutable</key>");
string BundleExecutable = bIsUnrealGame ?
(bIsClient ? "UnrealClient" : "UnrealGame") :
(bIsClient ? GameName + "Client" : GameName);
Text.AppendLine(String.Format("\t<string>{0}</string>", BundleExecutable));
Text.AppendLine("\t<key>CFBundleIdentifier</key>");
Text.AppendLine(String.Format("\t<string>{0}</string>", BundleIdentifier.Replace("[PROJECT_NAME]", ProjectName).Replace("_", "")));
Text.AppendLine("\t<key>CFBundleInfoDictionaryVersion</key>");
Text.AppendLine("\t<string>6.0</string>");
Text.AppendLine("\t<key>CFBundleName</key>");
Text.AppendLine(String.Format("\t<string>{0}</string>", EncodeBundleName(BundleName, ProjectName)));
Text.AppendLine("\t<key>CFBundlePackageType</key>");
Text.AppendLine("\t<string>APPL</string>");
Text.AppendLine("\t<key>CFBundleSignature</key>");
Text.AppendLine("\t<string>????</string>");
Text.AppendLine("\t<key>CFBundleVersion</key>");
Text.AppendLine(String.Format("\t<string>{0}</string>", VersionUtilities.UpdateBundleVersion(OldPListData, InEngineDir)));
Text.AppendLine("\t<key>CFBundleShortVersionString</key>");
Text.AppendLine(String.Format("\t<string>{0}</string>", BundleShortVersion));
Text.AppendLine("\t<key>LSRequiresIPhoneOS</key>");
Text.AppendLine("\t<true/>");
Text.AppendLine("\t<key>UIRequiredDeviceCapabilities</key>");
Text.AppendLine("\t<array>");
foreach (string Line in RequiredCaps.Split("\r\n".ToCharArray()))
{
if (!String.IsNullOrWhiteSpace(Line))
{
Text.AppendLine(Line);
}
}
Text.AppendLine("\t</array>");
Text.AppendLine("\t<key>TVTopShelfImage</key>");
Text.AppendLine("\t<dict>");
Text.AppendLine("\t\t<key>TVTopShelfPrimaryImageWide</key>");
Text.AppendLine("\t\t<string>Top Shelf Image Wide</string>");
Text.AppendLine("\t</dict>");
Text.AppendLine("\t<key>CFBundleIcons</key>");
Text.AppendLine("\t<dict>");
Text.AppendLine("\t\t<key>CFBundlePrimaryIcon</key>");
Text.AppendLine("\t\t<string>App Icon</string>");
Text.AppendLine("\t</dict>");
Text.AppendLine("\t<key>UILaunchStoryboardName</key>");
Text.AppendLine("\t<string>LaunchScreen</string>");
// write the iCloud container identifier, if present in the old file
if (!String.IsNullOrEmpty(OldPListData))
{
int index = OldPListData.IndexOf("ICloudContainerIdentifier");
if (index > 0)
{
index = OldPListData.IndexOf("<string>", index) + 8;
int length = OldPListData.IndexOf("</string>", index) - index;
string ICloudContainerIdentifier = OldPListData.Substring(index, length);
Text.AppendLine("\t<key>ICloudContainerIdentifier</key>");
Text.AppendLine(String.Format("\t<string>{0}</string>", ICloudContainerIdentifier));
}
}
Text.AppendLine("</dict>");
Text.AppendLine("</plist>");
// Create the intermediate directory if needed
if (!Directory.Exists(IntermediateDirectory))
{
Directory.CreateDirectory(IntermediateDirectory);
}
if (UPL != null)
{
// Allow UPL to modify the plist here
XDocument XDoc;
try
{
XDoc = XDocument.Parse(Text.ToString());
}
catch (Exception e)
{
throw new BuildException("plist is invalid {0}\n{1}", e, Text.ToString());
}
XDoc.DocumentType!.InternalSubset = "";
UPL.ProcessPluginNode("None", "iosPListUpdates", "", ref XDoc);
string result = XDoc.Declaration?.ToString() + "\n" + XDoc.ToString().Replace("<!DOCTYPE plist PUBLIC \"-//Apple//DTD PLIST 1.0//EN\" \"http://www.apple.com/DTDs/PropertyList-1.0.dtd\"[]>", "<!DOCTYPE plist PUBLIC \"-//Apple//DTD PLIST 1.0//EN\" \"http://www.apple.com/DTDs/PropertyList-1.0.dtd\">");
File.WriteAllText(PListFile, result);
}
else
{
File.WriteAllText(PListFile, Text.ToString());
}
if (BuildHostPlatform.Current.Platform == UnrealTargetPlatform.Mac)
{
if (!Directory.Exists(AppDirectory))
{
Directory.CreateDirectory(AppDirectory);
}
File.WriteAllText(AppDirectory + "/Info.plist", Text.ToString());
}
return bSkipDefaultPNGs;
}
public override bool GeneratePList(FileReference? ProjectFile, UnrealTargetConfiguration Config, string ProjectDirectory, bool bIsUnrealGame, string GameName, bool bIsClient, string ProjectName, string InEngineDir, string AppDirectory, List<string> UPLScripts, string? BundleID, bool bBuildAsFramework)
{
if (AppleExports.UseModernXcode(ProjectFile))
{
return base.GeneratePList(ProjectFile, Config, ProjectDirectory, bIsUnrealGame, GameName, bIsClient, ProjectName, InEngineDir, AppDirectory, UPLScripts, BundleID, bBuildAsFramework);
}
return GenerateTVOSPList(ProjectDirectory, bIsUnrealGame, GameName, bIsClient, ProjectName, InEngineDir, AppDirectory, null, BundleID, Logger);
}
}
}