2021-04-29 15:10:34 -04:00
|
|
|
// Copyright Epic Games, Inc. All Rights Reserved.
|
|
|
|
|
|
|
|
|
|
using System;
|
2022-05-17 15:43:35 -04:00
|
|
|
using System.Collections.Generic;
|
2021-04-29 15:10:34 -04:00
|
|
|
using System.Diagnostics;
|
|
|
|
|
using System.IO;
|
|
|
|
|
using System.Reflection;
|
|
|
|
|
using System.Runtime.InteropServices;
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
using EpicGames.Core;
|
2022-03-23 10:41:59 -04:00
|
|
|
using Microsoft.Extensions.DependencyInjection;
|
|
|
|
|
using Microsoft.Extensions.Logging;
|
2021-04-29 15:10:34 -04:00
|
|
|
|
2022-03-16 11:18:39 -04:00
|
|
|
namespace Horde.Agent
|
2021-04-29 15:10:34 -04:00
|
|
|
{
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Entry point
|
|
|
|
|
/// </summary>
|
|
|
|
|
public static class Program
|
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Name of the http client
|
|
|
|
|
/// </summary>
|
|
|
|
|
public const string HordeServerClientName = "HordeServer";
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Path to the root application directory
|
|
|
|
|
/// </summary>
|
2021-06-04 17:04:09 -04:00
|
|
|
public static DirectoryReference AppDir { get; } = GetAppDir();
|
2021-04-29 15:10:34 -04:00
|
|
|
|
|
|
|
|
/// <summary>
|
2021-06-04 17:04:09 -04:00
|
|
|
/// Path to the default data directory
|
2021-04-29 15:10:34 -04:00
|
|
|
/// </summary>
|
2021-06-04 17:04:09 -04:00
|
|
|
public static DirectoryReference DataDir { get; } = GetDataDir();
|
2021-04-29 15:10:34 -04:00
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// The launch arguments
|
|
|
|
|
/// </summary>
|
2022-05-17 15:43:35 -04:00
|
|
|
public static IReadOnlyList<string> Args { get; private set; } = null!;
|
2021-04-29 15:10:34 -04:00
|
|
|
|
2021-06-04 15:03:28 -04:00
|
|
|
/// <summary>
|
|
|
|
|
/// The current application version
|
|
|
|
|
/// </summary>
|
|
|
|
|
public static string Version { get; } = GetVersion();
|
|
|
|
|
|
2021-04-29 15:10:34 -04:00
|
|
|
/// <summary>
|
|
|
|
|
/// Entry point
|
|
|
|
|
/// </summary>
|
2022-03-21 07:56:16 -04:00
|
|
|
/// <param name="args">Command-line arguments</param>
|
2021-04-29 15:10:34 -04:00
|
|
|
/// <returns>Exit code</returns>
|
2022-03-21 07:56:16 -04:00
|
|
|
public static async Task<int> Main(string[] args)
|
2021-04-29 15:10:34 -04:00
|
|
|
{
|
2022-03-21 07:56:16 -04:00
|
|
|
Program.Args = args;
|
2021-04-29 15:10:34 -04:00
|
|
|
|
2022-03-21 07:56:16 -04:00
|
|
|
IServiceCollection services = new ServiceCollection();
|
|
|
|
|
services.AddCommandsFromAssembly(Assembly.GetExecutingAssembly());
|
|
|
|
|
services.AddLogging(builder => builder.AddProvider(new Logging.HordeLoggerProvider()));
|
2021-04-29 15:10:34 -04:00
|
|
|
|
2021-05-11 13:12:19 -04:00
|
|
|
// Enable unencrypted HTTP/2 for gRPC channel without TLS
|
|
|
|
|
AppContext.SetSwitch("System.Net.Http.SocketsHttpHandler.Http2UnencryptedSupport", true);
|
2021-04-29 15:10:34 -04:00
|
|
|
|
|
|
|
|
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
|
|
|
|
|
{
|
|
|
|
|
// Prioritize agent execution time over any job its running.
|
|
|
|
|
// We've seen file copying starving the agent communication to the Horde server, causing a disconnect.
|
|
|
|
|
// Increasing the process priority is speculative fix to combat this.
|
2022-03-21 07:56:16 -04:00
|
|
|
using (Process process = Process.GetCurrentProcess())
|
2021-04-29 15:10:34 -04:00
|
|
|
{
|
2022-03-21 07:56:16 -04:00
|
|
|
process.PriorityClass = ProcessPriorityClass.High;
|
2021-04-29 15:10:34 -04:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Execute all the commands
|
2022-03-21 07:56:16 -04:00
|
|
|
IServiceProvider serviceProvider = services.BuildServiceProvider();
|
|
|
|
|
return await CommandHost.RunAsync(new CommandLineArguments(args), serviceProvider, typeof(Horde.Agent.Modes.Service.RunCommand));
|
2021-04-29 15:10:34 -04:00
|
|
|
}
|
2021-06-04 15:03:28 -04:00
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Gets the version of the current assembly
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
static string GetVersion()
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
2022-05-17 15:43:35 -04:00
|
|
|
return FileVersionInfo.GetVersionInfo(Assembly.GetExecutingAssembly().Location).ProductVersion!;
|
2021-06-04 15:03:28 -04:00
|
|
|
}
|
|
|
|
|
catch
|
|
|
|
|
{
|
|
|
|
|
return "unknown";
|
|
|
|
|
}
|
|
|
|
|
}
|
2021-06-04 17:04:09 -04:00
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Gets the application directory
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
static DirectoryReference GetAppDir()
|
|
|
|
|
{
|
|
|
|
|
return new DirectoryReference(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location)!);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Gets the default data directory
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
static DirectoryReference GetDataDir()
|
|
|
|
|
{
|
|
|
|
|
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
|
|
|
|
|
{
|
2022-03-21 07:56:16 -04:00
|
|
|
DirectoryReference? programDataDir = DirectoryReference.GetSpecialFolder(Environment.SpecialFolder.CommonApplicationData);
|
|
|
|
|
if (programDataDir != null)
|
2021-06-04 17:04:09 -04:00
|
|
|
{
|
2022-03-21 07:56:16 -04:00
|
|
|
return DirectoryReference.Combine(programDataDir, "HordeAgent");
|
2021-06-04 17:04:09 -04:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return GetAppDir();
|
|
|
|
|
}
|
2021-04-29 15:10:34 -04:00
|
|
|
}
|
|
|
|
|
}
|