]> git.deb.at Git - rhonda/impostor.git/commitdiff
Workaround for broken config / plugins path
authorAeonLucid <aeonlucid@outlook.com>
Thu, 5 Nov 2020 01:50:56 +0000 (02:50 +0100)
committerAeonLucid <aeonlucid@outlook.com>
Thu, 5 Nov 2020 01:50:56 +0000 (02:50 +0100)
src/Impostor.Server/Plugins/PluginLoader.cs
src/Impostor.Server/Program.cs
src/Impostor.Server/Utils/DirUtils.cs [new file with mode: 0644]

index ef6dae6729364f8c3fb80b9752b4915520dc3e15..1ea207203d3498f3b560d9c67ffae40c1a01d270 100644 (file)
@@ -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<string>(config.Paths);
             var libraryPaths = new List<string>(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
+}
index a58dfa084a826fad634e93d72bcd24cd14189460..361a671401e9c9ec75e4245414353b1f2bc028c3 100644 (file)
@@ -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<PluginConfig>() ?? 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 (file)
index 0000000..0d1c7d9
--- /dev/null
@@ -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;
+        }
+    }
+}