-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram.cs
More file actions
61 lines (50 loc) · 1.75 KB
/
Copy pathProgram.cs
File metadata and controls
61 lines (50 loc) · 1.75 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using Spectre.Console;
using ViveConsole.Services;
using ViveConsole.Services.Backend;
using ViveConsole.Utils;
namespace ViveConsole;
internal class Program
{
static async Task Main(string[] args)
{
// 0. 全局操作系统检查
if (!OperatingSystem.IsWindows())
{
Console.WriteLine("此工具仅支持 Windows 平台。");
return;
}
// 1. 处理 --help
if (args.Contains("--help"))
{
ConsoleHelper.ShowHelp();
return;
}
// 2. 检查管理员权限
if (!ConsoleHelper.IsAdministrator())
{
AnsiConsole.MarkupLine("[red]Error: This application requires Administrator privileges.[/]");
return;
}
// 3. 检查 vivetool 是否在 Path 中
if (!ConsoleHelper.IsVivetoolInPath())
{
AnsiConsole.MarkupLine("[red]Error: 'vivetool.exe' was not found in your PATH.[/]");
AnsiConsole.MarkupLine("Please download it from: [blue]https://github.com/thebookisclosed/ViVe/releases[/]");
return;
}
// 4. 配置 Host 和依赖注入
var builder = Host.CreateApplicationBuilder(args);
_ = builder.Services
.AddSingleton<ICommandParser, CommandParser>()
.AddSingleton<IStateManager, StateManager>()
.AddSingleton<IVivetoolAdapter, VivetoolAdapter>()
.AddSingleton<IUserInterface, UserInterface>()
.AddSingleton<App>();
using var host = builder.Build();
// 5. 运行 App
var app = host.Services.GetRequiredService<App>();
await app.RunAsync();
}
}