4 using System.Threading.Tasks;
14 public Version Version {
get; }
17 public string DreamDaemonPath {
get; }
20 public string DreamMakerPath {
get; }
48 SemaphoreSlim trustedFileSemaphore,
50 string dreamDaemonPath,
51 string dreamMakerPath,
52 string trustedFilePath)
54 this.ioManager = ioManager ??
throw new ArgumentNullException(nameof(ioManager));
55 this.trustedFileSemaphore = trustedFileSemaphore ??
throw new ArgumentNullException(nameof(trustedFileSemaphore));
56 Version = version ??
throw new ArgumentNullException(nameof(version));
57 DreamDaemonPath = dreamDaemonPath ??
throw new ArgumentNullException(nameof(dreamDaemonPath));
58 DreamMakerPath = dreamMakerPath ??
throw new ArgumentNullException(nameof(dreamMakerPath));
59 this.trustedFilePath = trustedFilePath ??
throw new ArgumentNullException(nameof(trustedFilePath));
72 public async Task
TrustDmbPath(
string fullDmbPath, CancellationToken cancellationToken)
74 if (fullDmbPath == null)
75 throw new ArgumentNullException(nameof(fullDmbPath));
79 string trustedFileText;
81 if (await ioManager.FileExists(trustedFilePath, cancellationToken).ConfigureAwait(
false))
83 var trustedFileBytes = await ioManager.ReadAllBytes(trustedFilePath, cancellationToken).ConfigureAwait(
false);
84 trustedFileText = Encoding.UTF8.GetString(trustedFileBytes);
85 trustedFileText = $
"{trustedFileText.Trim()}{Environment.NewLine}";
89 trustedFileText = String.Empty;
92 if (trustedFileText.Contains(fullDmbPath, StringComparison.Ordinal))
95 trustedFileText = $
"{trustedFileText}{fullDmbPath}{Environment.NewLine}";
97 var newTrustedFileBytes = Encoding.UTF8.GetBytes(trustedFileText);
98 await ioManager.WriteAllBytes(trustedFilePath, newTrustedFileBytes, cancellationToken).ConfigureAwait(
false);
readonly IIOManager ioManager
The IIOManager for the ByondExecutableLock.
async Task TrustDmbPath(string fullDmbPath, CancellationToken cancellationToken)
Add a given fullDmbPath to the trusted DMBs list in BYOND's config.
ByondExecutableLock(IIOManager ioManager, SemaphoreSlim trustedFileSemaphore, Version version, string dreamDaemonPath, string dreamMakerPath, string trustedFilePath)
Construct a ByondExecutableLock
void DoNotDeleteThisSession()
Call if, during a detach, this version should not be deleted
readonly SemaphoreSlim trustedFileSemaphore
SemaphoreSlim used to guard access to the trustedFilePath.
Represents usage of the two primary BYOND server executables
readonly string trustedFilePath
The path to the BYOND trusted .dmbs configuration file.
Interface for using filesystems
static async Task< SemaphoreSlimContext > Lock(SemaphoreSlim semaphore, CancellationToken cancellationToken)
Asyncronously locks a semaphore
Async lock context helper