/// <inheritdoc /> public Task StartAsync(CancellationToken cancellationToken) => byondInstaller.CleanCache(cancellationToken);
#pragma warning restore CA1506 /// <inheritdoc /> public Task StartAsync(CancellationToken cancellationToken) { CheckSystemCompatibility(); return(byondInstaller.CleanCache(cancellationToken)); }
/// <inheritdoc /> public async Task StartAsync(CancellationToken cancellationToken) { var cacheCleanTask = byondInstaller.CleanCache(cancellationToken); async Task <byte[]> GetActiveVersion() { if (!await ioManager.FileExists(ActiveVersionFileName, cancellationToken).ConfigureAwait(false)) { return(null); } return(await ioManager.ReadAllBytes(ActiveVersionFileName, cancellationToken).ConfigureAwait(false)); } var activeVersionBytesTask = GetActiveVersion(); await ioManager.CreateDirectory(".", cancellationToken).ConfigureAwait(false); var directories = await ioManager.GetDirectories(".", cancellationToken).ConfigureAwait(false); async Task ReadVersion(string path) { var versionFile = ioManager.ConcatPath(path, VersionFileName); if (!await ioManager.FileExists(versionFile, cancellationToken).ConfigureAwait(false)) { logger.LogInformation("Cleaning unparsable version path: {0}", ioManager.ResolvePath(path)); await ioManager.DeleteDirectory(path, cancellationToken).ConfigureAwait(false); //cleanup return; } var bytes = await ioManager.ReadAllBytes(versionFile, cancellationToken).ConfigureAwait(false); var text = Encoding.UTF8.GetString(bytes); if (Version.TryParse(text, out var version)) { var key = VersionKey(version); lock (installedVersions) if (!installedVersions.ContainsKey(key)) { installedVersions.Add(key, Task.CompletedTask); return; } } await ioManager.DeleteDirectory(path, cancellationToken).ConfigureAwait(false); }; await Task.WhenAll(directories.Select(x => ReadVersion(x))).ConfigureAwait(false); var activeVersionBytes = await activeVersionBytesTask.ConfigureAwait(false); if (activeVersionBytes != null) { var activeVersionString = Encoding.UTF8.GetString(activeVersionBytes); if (Version.TryParse(activeVersionString, out var activeVersion)) { ActiveVersion = activeVersion; } else { await ioManager.DeleteFile(ActiveVersionFileName, cancellationToken).ConfigureAwait(false); } await cacheCleanTask.ConfigureAwait(false); } }