This commit is contained in:
JustArchi
2020-12-18 22:06:15 +01:00
parent c5c55dc44e
commit 34c5f5cf8b
10 changed files with 346 additions and 284 deletions

View File

@@ -30,6 +30,7 @@ using System.IO;
using System.Linq;
using System.Reflection;
using System.Threading.Tasks;
using ArchiSteamFarm.Helpers;
using ArchiSteamFarm.Json;
using ArchiSteamFarm.Localization;
using Newtonsoft.Json.Linq;
@@ -86,6 +87,30 @@ namespace ArchiSteamFarm.Plugins {
return changeNumberToStartFrom == uint.MaxValue ? 0 : changeNumberToStartFrom;
}
internal static async Task<ICrossProcessSemaphore> GetCrossProcessSemaphore(string objectName) {
if (string.IsNullOrEmpty(objectName)) {
throw new ArgumentNullException(nameof(objectName));
}
string resourceName = OS.GetOsResourceName(objectName);
if ((ActivePlugins == null) || (ActivePlugins.Count == 0)) {
return new CrossProcessFileBasedSemaphore(resourceName);
}
IList<ICrossProcessSemaphore?> responses;
try {
responses = await Utilities.InParallel(ActivePlugins.OfType<ICrossProcessSemaphoreProvider>().Select(plugin => plugin.GetCrossProcessSemaphore(resourceName))).ConfigureAwait(false);
} catch (Exception e) {
ASF.ArchiLogger.LogGenericException(e);
return new CrossProcessFileBasedSemaphore(resourceName);
}
return responses.FirstOrDefault(response => response != null) ?? new CrossProcessFileBasedSemaphore(resourceName);
}
internal static bool InitPlugins() {
if (ActivePlugins != null) {
return false;