43 lines
1.4 KiB
C#
43 lines
1.4 KiB
C#
using MoonlightServers.Daemon.Models;
|
|
using MoonlightServers.Daemon.ServerSystem.Abstractions;
|
|
|
|
namespace MoonlightServers.Daemon.ServerSystem.Implementations.Local;
|
|
|
|
public class LocalInstallStorageService : IInstallStorageService
|
|
{
|
|
private const string HostPathTemplate = "./mldaemon/install/{0}";
|
|
|
|
public Task<IInstallStorage?> FindAsync(string id)
|
|
{
|
|
var path = string.Format(HostPathTemplate, id);
|
|
|
|
if (!Directory.Exists(path))
|
|
return Task.FromResult<IInstallStorage?>(null);
|
|
|
|
return Task.FromResult<IInstallStorage?>(new LocalInstallStorage(path));
|
|
}
|
|
|
|
public Task<IInstallStorage> CreateAsync(string id, RuntimeConfiguration runtimeConfiguration, InstallConfiguration installConfiguration)
|
|
{
|
|
var path = string.Format(HostPathTemplate, id);
|
|
|
|
Directory.CreateDirectory(path);
|
|
|
|
return Task.FromResult<IInstallStorage>(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.HostPath))
|
|
Directory.Delete(localInstallStorage.HostPath, true);
|
|
|
|
return Task.CompletedTask;
|
|
}
|
|
} |