113 lines
3.6 KiB
C#
113 lines
3.6 KiB
C#
using System;
|
|
using System.ComponentModel;
|
|
using System.IO;
|
|
using System.Threading;
|
|
using JD.Core.ProjectManaging;
|
|
using Packager.Parameters;
|
|
|
|
using RunOnIsc;
|
|
using Ubisoft.Collections;
|
|
using LogCategory = JD.LogService.LogCategory;
|
|
|
|
namespace Packager.Tasks
|
|
{
|
|
[DisplayName("Linearize Common")]
|
|
[Category("Extern Tools")]
|
|
public class LinearizeCommonTask : Task, IDisposable
|
|
{
|
|
private Worker _worker;
|
|
|
|
private readonly string _inputFileName = "game.log";
|
|
|
|
private readonly AutoResetEvent _signalContinueExecution = new AutoResetEvent(false);
|
|
|
|
[Output("Loading Logs", IOType.File)]
|
|
public SingleReference LoadingLogs = new SingleReference();
|
|
|
|
[Output("Engine Log File", IOType.File)]
|
|
public SingleReference EngineErrorLogFile = new SingleReference();
|
|
|
|
private RunOnIscParams InitParams()
|
|
{
|
|
var parameters = new RunOnIscParams
|
|
{
|
|
Root = DataPath.Value,
|
|
MapMinLaunchTime = 420,
|
|
AlwaysReportOpenFile = true,
|
|
OutputDirectory = TaskOutputFolder,
|
|
OutputFormat = "{0}.log",
|
|
LaunchGame = true,
|
|
ExecutableFile = EnginePath.FindExecutable("UA_Engine.exe"),
|
|
Arguments = "noonline=1;nocrashreporter=1;filelogging=1;hiddenatboot=1;game=1;silent=1;nosound=1;logFile=" + EngineErrorLogFile.Value
|
|
};
|
|
|
|
return parameters;
|
|
}
|
|
|
|
private void WorkerLog(string message, LogCategory messageCategory)
|
|
{
|
|
LogMessage(message, messageCategory);
|
|
}
|
|
|
|
private void WorkerCompleted(int numMapsSuccess, int numMapsFailed)
|
|
{
|
|
_signalContinueExecution.Set();
|
|
}
|
|
|
|
protected override void StartInternal(BuildConfiguration profile, cookerWrapper cooker)
|
|
{
|
|
try
|
|
{
|
|
EngineErrorLogFile.Value = Path.Combine(TaskOutputFolder, "LineraizeCommonEngineLog.txt");
|
|
|
|
//Run on ISC step
|
|
var parameters = InitParams();
|
|
|
|
using (_worker = new Worker(parameters))
|
|
{
|
|
_worker.OnLog += WorkerLog;
|
|
_worker.OnCompleted += WorkerCompleted;
|
|
|
|
var result = _worker.Start();
|
|
_signalContinueExecution.WaitOne();
|
|
|
|
if (result != 0)
|
|
{
|
|
LogMessage(true, "Failed to start the Worker for RunOnIscParams");
|
|
return;
|
|
}
|
|
|
|
LoadingLogs.Value = Path.Combine(TaskOutputFolder, _inputFileName);
|
|
ReportEngineErrors();
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
LogMessage(true, ex.Message);
|
|
}
|
|
}
|
|
|
|
private void ReportEngineErrors()
|
|
{
|
|
if (HasError)
|
|
{
|
|
LogEngineError();
|
|
}
|
|
}
|
|
|
|
private void LogEngineError()
|
|
{
|
|
if (!File.Exists(EngineErrorLogFile.Value)) return;
|
|
var fileData = File.ReadAllLines(EngineErrorLogFile.Value);
|
|
LogMessage("**********************Starting Engine Error Log********************************", LogCategory.Error);
|
|
fileData.ForEach(x => LogMessage(x, LogCategory.Message));
|
|
LogMessage("**********************Ending Engine Error Log**********************************", LogCategory.Error);
|
|
}
|
|
|
|
public void Dispose()
|
|
{
|
|
_worker?.Dispose();
|
|
_signalContinueExecution?.Dispose();
|
|
}
|
|
}
|
|
}
|