Add project files.

This commit is contained in:
2026-03-08 20:45:01 +01:00
commit 053a4052dd
45 changed files with 2578 additions and 0 deletions

View File

@@ -0,0 +1,43 @@
using System.Diagnostics;
using System.Diagnostics.CodeAnalysis;
namespace LeagueAPI.Utils;
internal class PortTokenWithLockfile : IPortTokenBehavior
{
public bool TryGet(Process process, out string remotingAuthToken, out int appPort, [NotNullWhen(false)] out Exception? exception)
{
try
{
DirectoryInfo directory = new(Path.GetDirectoryName(process.MainModule?.FileName) ?? throw new FileNotFoundException("Lockfile not found.", "lockfile"));
FileInfo lockfile = new(Path.Join(directory.FullName, "lockfile"));
while (!lockfile.Exists)
{
if (directory.Root == directory)
{
break;
}
directory = directory.Parent ?? directory.Root;
lockfile = new(Path.Join(directory.FullName, "lockfile"));
}
using FileStream stream = lockfile.Open(FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
using StreamReader streamReader = new(stream);
string[] array = streamReader.ReadToEnd().Split(":");
if (array is not [string clientName, string pid, string port, string secret, string protocol] || !int.TryParse(port, out appPort))
{
throw new Exception("Failed to parse lockfile.");
}
remotingAuthToken = secret;
exception = null;
return true;
}
catch (Exception ex)
{
remotingAuthToken = string.Empty;
appPort = 0;
exception = ex;
return false;
}
}
}