using System.ServiceProcess; using System.Text.Json; using XFEToolBox.Client.Core.Search.Service; using XFEToolBox.Indexing.Service.Host; using XFEToolBox.Indexing.Service.Installation; namespace XFEToolBox.Indexing.Service; public static class Program { public static async Task Main(string[] args) { if (args.Length == 1 && args[0] is "--install" or "--uninstall") return IndexingServiceInstaller.Run(args[0]); if (args.Length == 1 && args[0] == "--probe") { var status = await new IndexingServiceClient().GetStatusAsync().ConfigureAwait(false); Console.WriteLine(JsonSerializer.Serialize(status)); return status is null ? 1 : 0; } if (args.Length == 1 && args[0] == "--console") { using var cancellation = new CancellationTokenSource(); Console.CancelKeyPress += (_, eventArgs) => { eventArgs.Cancel = true; _ = cancellation.CancelAsync(); }; await using var host = new IndexingServiceHost(IndexingWindowsService.DataDirectory); try { await host.RunAsync(cancellation.Token).ConfigureAwait(false); } catch (OperationCanceledException) when (cancellation.IsCancellationRequested) { } return 0; } if (args.Length != 0) { Console.Error.WriteLine("Supported options: --install, --uninstall, --probe, --console."); return 2; } if (Environment.UserInteractive) { Console.Error.WriteLine("Run this executable through Windows Service Control Manager, or use --install."); return 2; } ServiceBase.Run(new IndexingWindowsService()); return 0; } }