53 lines
1.7 KiB
C#
53 lines
1.7 KiB
C#
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 LocalRuntimeStorageService : IRuntimeStorageService
|
|
{
|
|
private readonly IOptions<LocalStorageOptions> Options;
|
|
|
|
public LocalRuntimeStorageService(IOptions<LocalStorageOptions> options)
|
|
{
|
|
Options = options;
|
|
}
|
|
|
|
public Task<IRuntimeStorage?> FindAsync(string id)
|
|
{
|
|
var path = Path.Combine(Options.Value.RuntimePath, id);
|
|
|
|
if (!Directory.Exists(path))
|
|
return Task.FromResult<IRuntimeStorage?>(null);
|
|
|
|
return Task.FromResult<IRuntimeStorage?>(new LocalRuntimeStorage(path));
|
|
}
|
|
|
|
public Task<IRuntimeStorage> CreateAsync(string id, RuntimeConfiguration configuration)
|
|
{
|
|
var path = Path.Combine(Options.Value.RuntimePath, id);
|
|
|
|
Directory.CreateDirectory(path);
|
|
|
|
return Task.FromResult<IRuntimeStorage>(new LocalRuntimeStorage(path));
|
|
}
|
|
|
|
public Task UpdateAsync(IRuntimeStorage runtimeStorage, RuntimeConfiguration configuration)
|
|
=> Task.CompletedTask;
|
|
|
|
public Task DeleteAsync(IRuntimeStorage runtimeStorage)
|
|
{
|
|
if (runtimeStorage is not LocalRuntimeStorage localRuntimeStorage)
|
|
{
|
|
throw new ArgumentException(
|
|
$"You cannot delete runtime storages which haven't been created by {nameof(LocalRuntimeStorageService)}"
|
|
);
|
|
}
|
|
|
|
if(Directory.Exists(localRuntimeStorage.BindPath))
|
|
Directory.Delete(localRuntimeStorage.BindPath, true);
|
|
|
|
return Task.CompletedTask;
|
|
}
|
|
} |