LANCommander/LANCommander.Server/Startup/Filesystem.cs

31 lines
992 B
C#
Raw Normal View History

2025-03-11 21:21:16 -05:00
using LANCommander.Server.Services.Models;
using Microsoft.Extensions.Options;
2025-03-11 21:21:16 -05:00
namespace LANCommander.Server.Startup;
public static class Filesystem
{
public static WebApplication PrepareDirectories(this WebApplication app)
{
var settings = app.Services.GetRequiredService<IOptions<Settings.Settings>>();
2025-03-11 21:21:16 -05:00
var logger = app.Services.GetRequiredService<ILogger<Program>>();
logger.LogDebug("Ensuring required directories exist");
IEnumerable<string> directories = [
settings.Value.Server.Update.StoragePath,
settings.Value.Server.Launcher.StoragePath,
settings.Value.Server.Backups.StoragePath,
2025-03-11 21:21:16 -05:00
"Snippets",
];
foreach (var directory in directories)
{
logger.LogDebug("Ensuring directory {Directory} exists", directory);
if (!Directory.Exists(directory))
Directory.CreateDirectory(directory);
}
return app;
}
}