LANCommander/LANCommander.Server/Startup/Filesystem.cs

38 lines
1.2 KiB
C#
Raw Permalink Normal View History

2025-12-11 02:06:04 -06:00
using LANCommander.SDK;
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-12-11 02:06:04 -06:00
settings.Value.Server.Scripts.Snippets.StoragePath,
settings.Value.Server.Scripts.Modules.StoragePath,
2025-03-11 21:21:16 -05:00
];
foreach (var directory in directories)
{
2026-07-24 18:00:32 -05:00
if (string.IsNullOrWhiteSpace(directory))
continue;
var resolved = AppPaths.ResolveStorageLocationPath(directory);
logger.LogDebug("Ensuring directory {Directory} exists", resolved);
if (!Directory.Exists(resolved))
Directory.CreateDirectory(resolved);
2025-03-11 21:21:16 -05:00
}
return app;
}
}