This repository has been archived by the owner on Sep 13, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathProgram.cs
71 lines (61 loc) · 2.44 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
66
67
68
69
70
71
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using System.IO;
using Microsoft.AspNetCore.SignalR;
using Microsoft.Extensions.FileProviders;
using System.Reflection;
var builder = WebApplication.CreateBuilder(args);
// Add services to the container.
builder.Services.AddRazorPages();
builder.Services.AddSignalR();
builder.Services.AddSingleton<FileWatcherService>(provider =>
{
var userProfilePath = Environment.GetFolderPath(Environment.SpecialFolder.UserProfile);
var defaultFilePath = Path.Combine(userProfilePath, "AppData", "LocalLow", "Skirmish Mode Games, Inc", "BeyondATC", "Player.log");
var logFileLocationPath = Path.Combine(userProfilePath, "logfile_location.txt");
var filePath = File.Exists(logFileLocationPath) ? File.ReadAllText(logFileLocationPath) : defaultFilePath;
var lastLineFilePath = Path.Combine(Path.GetTempPath(), "lastline.txt");
var hubContext = provider.GetRequiredService<IHubContext<MyHub>>();
return new FileWatcherService(hubContext, filePath, lastLineFilePath, true);
});
var fileProvider = new ManifestEmbeddedFileProvider(Assembly.GetAssembly(type: typeof(Program))!, "wwwroot");
var app = builder.Build();
app.UseStaticFiles(new StaticFileOptions
{
FileProvider = fileProvider,
RequestPath = string.Empty,
});
// Configure the HTTP request pipeline.
if (!app.Environment.IsDevelopment())
{
app.UseExceptionHandler("/Error");
app.UseHsts();
}
app.UseStaticFiles();
app.UseRouting();
app.MapRazorPages();
app.MapHub<MyHub>("/hub");
app.MapGet("/lastline", async context =>
{
var lastLineFilePath = Path.Combine(Path.GetTempPath(), "lastline.txt");
if (File.Exists(lastLineFilePath))
{
var lastLine = await File.ReadAllTextAsync(lastLineFilePath);
await context.Response.WriteAsync(lastLine);
}
else
{
context.Response.StatusCode = 404;
}
});
// Start the file watcher service
var fileWatcherService = app.Services.GetRequiredService<FileWatcherService>();
Console.WriteLine("------------------------------------------------------------------");
Console.WriteLine("Welcome to fearlessfrog's AtcLogWatcher! v0.3.0");
Console.WriteLine("Listening on: http://localhost:41716");
Console.WriteLine("See filters.txt for the list of filters to exclude.");
Console.WriteLine("Press Ctrl+C to exit.");
Console.WriteLine("------------------------------------------------------------------");
app.Run();