Settings for the server are now combined with the settings from the SDK. This introduces a large breaking change and a migration should be created. This refactor utilizes .NET Configuration and the Options pattern. This will allow for the overriding of any setting using envionment variables. It also means that Settings.yml can be used to override any .NET configuration. A SettingsProvider implementation was created, and any updating of settings was changed from SettingsService.SaveSettings() to SettingsProvider.Update(s => { ... })
31 lines
No EOL
992 B
C#
31 lines
No EOL
992 B
C#
using LANCommander.Server.Services.Models;
|
|
using Microsoft.Extensions.Options;
|
|
|
|
namespace LANCommander.Server.Startup;
|
|
|
|
public static class Filesystem
|
|
{
|
|
public static WebApplication PrepareDirectories(this WebApplication app)
|
|
{
|
|
var settings = app.Services.GetRequiredService<IOptions<Settings.Settings>>();
|
|
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,
|
|
"Snippets",
|
|
];
|
|
|
|
foreach (var directory in directories)
|
|
{
|
|
logger.LogDebug("Ensuring directory {Directory} exists", directory);
|
|
if (!Directory.Exists(directory))
|
|
Directory.CreateDirectory(directory);
|
|
}
|
|
|
|
return app;
|
|
}
|
|
} |