From: AeonLucid Date: Thu, 5 Nov 2020 01:50:56 +0000 (+0100) Subject: Workaround for broken config / plugins path X-Git-Tag: v1.2.2~40 X-Git-Url: https://git.deb.at/?a=commitdiff_plain;h=0cd558b98c077b4f07062377613a5b04e295eed1;p=rhonda%2Fimpostor.git Workaround for broken config / plugins path --- diff --git a/src/Impostor.Server/Plugins/PluginLoader.cs b/src/Impostor.Server/Plugins/PluginLoader.cs index ef6dae6..1ea2072 100644 --- a/src/Impostor.Server/Plugins/PluginLoader.cs +++ b/src/Impostor.Server/Plugins/PluginLoader.cs @@ -5,6 +5,7 @@ using System.Linq; using System.Reflection; using System.Runtime.Loader; using Impostor.Api.Plugins; +using Impostor.Server.Utils; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.FileSystemGlobbing; using Microsoft.Extensions.Hosting; @@ -25,7 +26,7 @@ namespace Impostor.Server.Plugins var pluginPaths = new List(config.Paths); var libraryPaths = new List(config.LibraryPaths); - var rootFolder = AppContext.BaseDirectory; + var rootFolder = DirUtils.GetExecutableDirectory(); pluginPaths.Add(Path.Combine(rootFolder, "plugins")); libraryPaths.Add(Path.Combine(rootFolder, "libraries")); @@ -143,4 +144,4 @@ namespace Impostor.Server.Plugins } } } -} \ No newline at end of file +} diff --git a/src/Impostor.Server/Program.cs b/src/Impostor.Server/Program.cs index a58dfa0..361a671 100644 --- a/src/Impostor.Server/Program.cs +++ b/src/Impostor.Server/Program.cs @@ -14,6 +14,7 @@ using Impostor.Server.Net.Messages; using Impostor.Server.Net.Redirector; using Impostor.Server.Plugins; using Impostor.Server.Recorder; +using Impostor.Server.Utils; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Hosting; @@ -75,6 +76,7 @@ namespace Impostor.Server .Get() ?? new PluginConfig(); return Host.CreateDefaultBuilder(args) + .UseContentRoot(DirUtils.GetExecutableDirectory()) #if DEBUG .UseEnvironment(Environment.GetEnvironmentVariable("IMPOSTOR_ENV") ?? "Development") #else diff --git a/src/Impostor.Server/Utils/DirUtils.cs b/src/Impostor.Server/Utils/DirUtils.cs new file mode 100644 index 0000000..0d1c7d9 --- /dev/null +++ b/src/Impostor.Server/Utils/DirUtils.cs @@ -0,0 +1,29 @@ +using System; +using System.Diagnostics; +using System.IO; + +namespace Impostor.Server.Utils +{ + internal static class DirUtils + { + // Workaround for: + // - https://github.com/dotnet/runtime/issues/40828 + // - https://github.com/dotnet/runtime/issues/38405#issuecomment-652643506 + public static string GetExecutableDirectory() + { + var programDirectory = Path.GetDirectoryName(typeof(Program).Assembly.Location)!; + var currentDirectory = Directory.GetCurrentDirectory(); + var baseDirectory = AppDomain.CurrentDomain.BaseDirectory; + var executablePath = Process.GetCurrentProcess().MainModule!.FileName; + var executableDirectory = Path.GetDirectoryName(executablePath)!; + var executable = Path.GetFileNameWithoutExtension(executablePath); + + if ("dotnet".Equals(executable, StringComparison.InvariantCultureIgnoreCase)) + { + return programDirectory; + } + + return executableDirectory; + } + } +}