feat: Implement face encoder functionality with GPU support and recursive option

This commit is contained in:
MaddoScientisto 2026-05-09 12:09:05 +02:00
commit 988a3d94e1
10 changed files with 790 additions and 219 deletions

View file

@ -21,6 +21,9 @@ static class Program
[DllImport("kernel32.dll", SetLastError = true)]
private static extern bool AllocConsole();
[DllImport("kernel32.dll", SetLastError = true)]
private static extern bool FreeConsole();
[DllImport("kernel32.dll", SetLastError = true)]
static extern IntPtr GetStdHandle(int nStdHandle);
@ -36,6 +39,12 @@ static class Program
[DllImport("kernel32.dll", SetLastError = true)]
static extern bool AttachConsole(int dwProcessId);
[DllImport("kernel32.dll", SetLastError = true)]
private static extern bool GenerateConsoleCtrlEvent(uint dwCtrlEvent, uint dwProcessGroupId);
[DllImport("kernel32.dll", SetLastError = true)]
private static extern bool SetConsoleCtrlHandler(ConsoleCtrlDelegate? handlerRoutine, bool add);
[DllImport("kernel32.dll", SetLastError = true)]
static extern IntPtr CreateFile(
string lpFileName,
@ -48,6 +57,9 @@ static class Program
private const uint GENERIC_WRITE = 0x40000000;
private const uint OPEN_EXISTING = 3;
private const uint CTRL_C_EVENT = 0;
private delegate bool ConsoleCtrlDelegate(uint ctrlType);
private static void RedirectConsoleOutput()
{
@ -58,6 +70,38 @@ static class Program
Console.SetOut(standardOutput);
Console.SetError(standardOutput);
}
internal static bool TrySendConsoleInterrupt(int processId)
{
var hadConsole = GetConsoleWindow() != IntPtr.Zero;
try
{
if (hadConsole)
{
FreeConsole();
}
if (!AttachConsole(processId))
{
return false;
}
SetConsoleCtrlHandler(null, true);
return GenerateConsoleCtrlEvent(CTRL_C_EVENT, 0);
}
finally
{
FreeConsole();
SetConsoleCtrlHandler(null, false);
if (hadConsole)
{
AllocConsole();
RedirectConsoleOutput();
}
}
}
#endif
public static IServiceProvider ServiceProvider { get; private set; } = default!;