|
|
|
|
| using System;
|
| using System.Collections.Generic;
|
| using System.Diagnostics;
|
| using System.IO;
|
| using System.Linq;
|
| using System.Net;
|
| using System.Text;
|
| using System.Threading;
|
| using System.Threading.Tasks;
|
| using AutomationTool;
|
| using FileLockInfo;
|
| using Microsoft.Extensions.Logging;
|
|
|
| using static AutomationTool.CommandUtils;
|
|
|
| #pragma warning disable SYSLIB0014
|
|
|
| namespace LyraDeployment
|
| {
|
|
|
|
|
|
|
| public class DeployToEpicGameStore : BuildCommand
|
| {
|
| static string DownloadBuildPackageTool()
|
| {
|
|
|
| string BuildPackageToolUrl = "https://launcher-public-service-prod.ol.epicgames.com/launcher/api/installer/download/BuildPatchTool.zip";
|
|
|
| var BuildPathToolDownloadPath = CommandUtils.CombinePaths(CommandUtils.CmdEnv.LocalRoot, "BuildPatchTool.zip");
|
| var BuildPathToolInstallPath = CommandUtils.CombinePaths(CommandUtils.CmdEnv.LocalRoot, "BPT");
|
| var BuildPathToolPath = CommandUtils.CombinePaths(BuildPathToolInstallPath, "Engine/Binaries/Win64/BuildPatchTool.exe");
|
|
|
| if (Directory.Exists(BuildPathToolInstallPath))
|
| {
|
| Directory.Delete(BuildPathToolInstallPath, true);
|
| }
|
|
|
| using (var client = new WebClient())
|
| {
|
| client.DownloadFile(BuildPackageToolUrl, BuildPathToolDownloadPath);
|
| }
|
|
|
|
|
| Logger.LogInformation("Decompressing to {BuildPathToolInstallPath}...", BuildPathToolInstallPath);
|
| CommandUtils.LegacyUnzipFiles(BuildPathToolDownloadPath, BuildPathToolInstallPath);
|
| CommandUtils.DeleteFile(BuildPathToolDownloadPath);
|
|
|
|
|
| CommandUtils.FileExists(false, BuildPathToolPath);
|
|
|
| return BuildPathToolPath;
|
| }
|
|
|
| public DeployToEpicGameStore()
|
| {
|
| }
|
|
|
| public override void ExecuteBuild()
|
| {
|
| Logger.LogInformation("*************************");
|
|
|
| var LogInstanceId = Guid.NewGuid().ToString("N");
|
| var LogFileDirectory = CommandUtils.CombinePaths(CommandUtils.CmdEnv.LocalRoot, "Saved", "Logs", "BuildPatchToolLog");
|
|
|
| var BuildPathToolPath = DownloadBuildPackageTool();
|
|
|
| string ArtifactId = ParseParamValue("ArtifactId", null);
|
| string BuildRoot = ParseParamValue("BuildRoot", null);
|
| string CloudDir = ParseParamValue("CloudDir", null);
|
| string BuildVersion = ParseParamValue("BuildVersion", null);
|
| string AppLaunch = ParseParamValue("AppLaunch", null);
|
| string AppArgs = ParseParamValue("AppArgs", null);
|
| string FileAttributeList = ParseParamValue("FileAttributeList", null);
|
| string FileIgnoreList = ParseParamValue("FileIgnoreList", null);
|
| string Platform = ParseParamValue("Platform", null);
|
| string Label = ParseParamValue("Label", null);
|
| string CommandLineFile = ParseParamValue("CommandLineFile", null);
|
|
|
| if (Directory.Exists(CloudDir))
|
| {
|
| Directory.Delete(CloudDir, true);
|
| }
|
|
|
|
|
| {
|
| Logger.LogInformation("Are Build Files Are Unlocked: Starting");
|
|
|
| string[] FilesInBuildRoot = Directory.GetFiles(BuildRoot);
|
|
|
|
|
| Stopwatch stopwatch = new Stopwatch();
|
| stopwatch.Start();
|
| while (stopwatch.Elapsed.TotalSeconds < 30)
|
| {
|
| List<Process> LockingProcesses = Win32Processes.GetProcessesLockingFiles(FilesInBuildRoot);
|
| if (LockingProcesses.Count > 0)
|
| {
|
| string LockingProcessesString = string.Join(", ", LockingProcesses.Select(c => c.ProcessName));
|
| Logger.LogInformation("The following processes are locking files, {LockingProcessesString}", LockingProcessesString);
|
| Thread.Sleep(2000);
|
| }
|
| }
|
| stopwatch.Stop();
|
|
|
| Logger.LogInformation("Are Build Files Are Unlocked: Done");
|
| }
|
|
|
| Logger.LogInformation("Running BuildPatchTool Patch Generation on {ArtifactId}", ArtifactId);
|
| {
|
| string Args = "";
|
| Args += Arg("mode", "PatchGeneration");
|
| Args += Arg("ArtifactId", ArtifactId);
|
| Args += Arg("BuildRoot", Path.GetFullPath(BuildRoot));
|
| Args += Arg("CloudDir", Path.GetFullPath(CloudDir));
|
| Args += Arg("BuildVersion", BuildVersion);
|
| Args += Arg("AppLaunch", AppLaunch);
|
| Args += Arg("AppArgs", AppArgs);
|
| Args += Arg("FileAttributeList", FileAttributeList);
|
| Args += Arg("FileIgnoreList", FileIgnoreList);
|
|
|
| if (!String.IsNullOrEmpty(CommandLineFile))
|
| {
|
| Args += " " + File.ReadAllText(Path.GetFullPath(CommandLineFile));
|
| }
|
|
|
|
|
| Args += Arg("stdout");
|
|
|
|
|
|
|
|
|
| try
|
| {
|
| CommandUtils.RunAndLog(BuildPathToolPath, Args);
|
| }
|
| catch (AutomationException Ex)
|
| {
|
| Logger.LogError("{Text}", Ex.ToString());
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| throw;
|
| }
|
| }
|
| Logger.LogInformation("BuildPatchTool Patch Generation Done!");
|
|
|
| Logger.LogInformation("Running BuildPatchTool LabelBuild on {ArtifactId}", ArtifactId);
|
| {
|
| string Args = "";
|
| Args += Arg("mode", "LabelBuild");
|
| Args += Arg("ArtifactId", ArtifactId);
|
| Args += Arg("BuildRoot", Path.GetFullPath(BuildRoot));
|
| Args += Arg("CloudDir", Path.GetFullPath(CloudDir));
|
| Args += Arg("BuildVersion", BuildVersion);
|
| Args += Arg("Platform", Platform);
|
| Args += Arg("Label", Label);
|
|
|
| if (!String.IsNullOrEmpty(CommandLineFile))
|
| {
|
| Args += " " + File.ReadAllText(Path.GetFullPath(CommandLineFile));
|
| }
|
|
|
|
|
| Args += Arg("stdout");
|
|
|
|
|
|
|
|
|
| try
|
| {
|
| CommandUtils.RunAndLog(BuildPathToolPath, Args);
|
| }
|
| catch (AutomationException Ex)
|
| {
|
| Logger.LogError("{Text}", Ex.ToString());
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| throw;
|
| }
|
| }
|
| Logger.LogInformation("BuildPatchTool Patch Generation Done!");
|
|
|
|
|
| Logger.LogInformation("*************************");
|
| }
|
|
|
| private static string Arg(string Key, string Value)
|
| {
|
| return Value == null ? "" : " -" + Key + "=\"" + Value + "\"";
|
| }
|
| private static string Arg(string Key, int Value)
|
| {
|
| return " -" + Key + "=" + Value;
|
| }
|
| private static string Arg(string Key, ulong Value)
|
| {
|
| return " -" + Key + "=" + Value;
|
| }
|
| private static string Arg(string Key)
|
| {
|
| return " -" + Key;
|
| }
|
|
|
| private static string Arg(string Key, IEnumerable<string> Value)
|
| {
|
| return " -" + Key + "=\"" + string.Join(",", Value) + "\"";
|
| }
|
| private static string CustomArgs<T>(string ArgName, List<KeyValuePair<string, T>> CustomArgs)
|
| {
|
| var Result = new StringBuilder();
|
| if (CustomArgs != null)
|
| {
|
| foreach (var CustomArg in CustomArgs)
|
| {
|
| Result.Append(string.Format(" -{0}=\"{1}={2}\"", ArgName, CustomArg.Key, CustomArg.Value.ToString()));
|
| }
|
| }
|
| return Result.ToString();
|
| }
|
| }
|
| }
|
|
|