diff --git a/ArchiSteamFarm/Plugins/Core.cs b/ArchiSteamFarm/Plugins/Core.cs index 74f07eebc..cd89f94eb 100644 --- a/ArchiSteamFarm/Plugins/Core.cs +++ b/ArchiSteamFarm/Plugins/Core.cs @@ -86,35 +86,26 @@ namespace ArchiSteamFarm.Plugins { } internal static bool InitPlugins() { - string pluginsPath = Path.Combine(SharedInfo.HomeDirectory, SharedInfo.PluginsDirectory); - - if (!Directory.Exists(pluginsPath)) { - ASF.ArchiLogger.LogGenericTrace(Strings.NothingFound); - - return true; - } - HashSet assemblies = new HashSet(); - try { - foreach (string assemblyPath in Directory.EnumerateFiles(pluginsPath, "*.dll", SearchOption.AllDirectories)) { - Assembly assembly; + string pluginsPath = Path.Combine(SharedInfo.HomeDirectory, SharedInfo.PluginsDirectory); - try { - assembly = Assembly.LoadFrom(assemblyPath); - } catch (Exception e) { - ASF.ArchiLogger.LogGenericError(string.Format(Strings.ErrorIsInvalid, assemblyPath)); - ASF.ArchiLogger.LogGenericWarningException(e); + if (Directory.Exists(pluginsPath)) { + HashSet loadedAssemblies = LoadAssembliesFrom(pluginsPath); - continue; - } - - assemblies.Add(assembly); + if ((loadedAssemblies != null) && (loadedAssemblies.Count > 0)) { + assemblies.UnionWith(loadedAssemblies); } - } catch (Exception e) { - ASF.ArchiLogger.LogGenericException(e); + } - return false; + string customPluginsPath = Path.Combine(Directory.GetCurrentDirectory(), SharedInfo.PluginsDirectory); + + if (Directory.Exists(customPluginsPath)) { + HashSet loadedAssemblies = LoadAssembliesFrom(customPluginsPath); + + if ((loadedAssemblies != null) && (loadedAssemblies.Count > 0)) { + assemblies.UnionWith(loadedAssemblies); + } } if (assemblies.Count == 0) { @@ -392,5 +383,42 @@ namespace ArchiSteamFarm.Plugins { ASF.ArchiLogger.LogGenericException(e); } } + + private static HashSet LoadAssembliesFrom(string path) { + if (string.IsNullOrEmpty(path)) { + ASF.ArchiLogger.LogNullError(nameof(path)); + + return null; + } + + if (!Directory.Exists(path)) { + return null; + } + + HashSet assemblies = new HashSet(); + + try { + foreach (string assemblyPath in Directory.EnumerateFiles(path, "*.dll", SearchOption.AllDirectories)) { + Assembly assembly; + + try { + assembly = Assembly.LoadFrom(assemblyPath); + } catch (Exception e) { + ASF.ArchiLogger.LogGenericError(string.Format(Strings.ErrorIsInvalid, assemblyPath)); + ASF.ArchiLogger.LogGenericWarningException(e); + + continue; + } + + assemblies.Add(assembly); + } + } catch (Exception e) { + ASF.ArchiLogger.LogGenericException(e); + + return null; + } + + return assemblies; + } } }