Files
ben marsh d4f085fa25 Horde: Rename namespaces to match project folders.
[CL 34573501 by ben marsh in ue5-main branch]
2024-06-21 15:57:01 -04:00

38 lines
968 B
C#

// Copyright Epic Games, Inc. All Rights Reserved.
using System.Diagnostics;
using System.Threading.Tasks;
using EpicGames.Core;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Options;
namespace HordeServer.Commands
{
/// <summary>
/// Opens a web browser to the server homepage
/// </summary>
[Command("open", "Open web browser to the server homepage")]
public class OpenCommand : Command
{
readonly IOptions<ServerSettings> _settings;
/// <summary>
/// Constructor
/// </summary>
public OpenCommand(IOptions<ServerSettings> settings)
{
_settings = settings;
}
/// <inheritdoc/>
public override Task<int> ExecuteAsync(ILogger logger)
{
ProcessStartInfo startInfo = new ProcessStartInfo();
startInfo.FileName = $"http://localhost:{_settings.Value.HttpPort}";
startInfo.UseShellExecute = true;
using Process? process = Process.Start(startInfo);
return Task.FromResult((process != null) ? 0 : 1);
}
}
}