using Microsoft.Extensions.Options; using MoonlightServers.Daemon.Configuration; using MoonlightServers.Daemon.Models; using MoonlightServers.Daemon.ServerSystem.Abstractions; namespace MoonlightServers.Daemon.ServerSystem.Implementations.Local; public class LocalInstallStorageService : IInstallStorageService { private readonly IOptions Options; public LocalInstallStorageService(IOptions options) { Options = options; } public Task FindAsync(string id) { var path = Path.Combine(Options.Value.InstallPath, id); if (!Directory.Exists(path)) return Task.FromResult(null); return Task.FromResult(new LocalInstallStorage(path)); } public Task CreateAsync(string id, RuntimeConfiguration runtimeConfiguration, InstallConfiguration installConfiguration) { var path = Path.Combine(Options.Value.InstallPath, id); Directory.CreateDirectory(path); return Task.FromResult(new LocalInstallStorage(path)); } public Task DeleteAsync(IInstallStorage installStorage) { if (installStorage is not LocalInstallStorage localInstallStorage) { throw new ArgumentException( $"You cannot delete install storages which haven't been created by {nameof(LocalInstallStorageService)}" ); } if(Directory.Exists(localInstallStorage.BindPath)) Directory.Delete(localInstallStorage.BindPath, true); return Task.CompletedTask; } }