46 lines
1.5 KiB
C#
46 lines
1.5 KiB
C#
using MoonlightServers.Daemon.Models;
|
|
using MoonlightServers.Daemon.ServerSystem.Abstractions;
|
|
|
|
namespace MoonlightServers.Daemon.ServerSystem.Implementations.Local;
|
|
|
|
public class LocalRuntimeStorageService : IRuntimeStorageService
|
|
{
|
|
private const string HostPathTemplate = "./mldaemon/runtime/{0}";
|
|
|
|
public Task<IRuntimeStorage?> FindAsync(string id)
|
|
{
|
|
var path = string.Format(HostPathTemplate, 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 = string.Format(HostPathTemplate, 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.HostPath))
|
|
Directory.Delete(localRuntimeStorage.HostPath, true);
|
|
|
|
return Task.CompletedTask;
|
|
}
|
|
} |