-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathProgram.cs
66 lines (54 loc) · 2.04 KB
/
Program.cs
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
62
63
64
65
using local_gpss.utils;
if (Helpers.IsRunningAsAdminOrRoot())
{
// To prevent any security risk, you must confirm you know what you're doing and that
// flagbrew and myself (Allen) are not responsible if something goes wrong.
Console.WriteLine("You're running this as an admin or root, this is considered unsafe");
Console.WriteLine("If you know what you're doing and you're willing to accept the risks (and agree that FlagBrew and the developer (Allen) are not responsible for any issues that occur)");
Console.WriteLine("Then press Y to continue, otherwise please run this as a regular user");
var key = Console.ReadKey();
if (key.Key != ConsoleKey.Y)
{
Environment.Exit(2);
}
}
var builder = WebApplication.CreateBuilder(args);
// Add services to the container.
// Learn more about configuring OpenAPI at https://aka.ms/aspnet/openapi
builder.Services.AddOpenApi();
builder.Services.AddControllers();
var app = builder.Build();
app.UseRouting();
app.MapControllers();
// Configure the HTTP request pipeline.
if (app.Environment.IsDevelopment())
{
app.UseDeveloperExceptionPage();
app.MapOpenApi();
};
// This ensures that stuff like the ribbons database is initialized
var config = Helpers.Init() ?? Helpers.FirstTime();
// check if the config IP is in the assignable IPs.
if (!Helpers.GetLocalIPs().Contains(config.Ip))
{
// Call the helper to choose the new IP.
config = Helpers.NewIpNeeded(config);
}
// Check if the port can be used
if (!Helpers.CanBindToPort(config.Port))
{
config = Helpers.NewPortNeeded(config);
}
try
{
Console.WriteLine($"The API Url you should enter into PKSM is http://{config.Ip}:{config.Port}/");
app.Run($"http://{config.Ip}:{config.Port}/");
}
catch (Exception e)
{
Console.WriteLine("Uh Oh, something went wrong with starting Local GPSS, the error details are as followed:");
Console.WriteLine(e);
Console.WriteLine("Please provide these error details if you are asking for support.");
Console.WriteLine("Press any key to exit..");
Console.ReadKey();
}