Kaynağa Gözat

Fixed runtime constants loading

Krzysztof Krysiński 1 gün önce
ebeveyn
işleme
00f4b76099

+ 8 - 5
src/PixiEditor.Extensions.Runtime/ExtensionLoader.cs

@@ -22,7 +22,6 @@ public class ExtensionLoader
     private HashSet<string> loadedExtensions = new HashSet<string>();
 
 
-
     public ExtensionLoader(string[] packagesPaths, string unpackedExtensionsPath)
     {
         PackagesPath = packagesPaths;
@@ -34,6 +33,11 @@ public class ExtensionLoader
     {
         foreach (var packagesPath in PackagesPath)
         {
+            if (!Directory.Exists(packagesPath))
+            {
+                continue; // Skip if the directory does not exist
+            }
+
             foreach (var updateFile in Directory.GetFiles(packagesPath, "*.update"))
             {
                 try
@@ -53,13 +57,13 @@ public class ExtensionLoader
                 catch (UnauthorizedAccessException)
                 {
                     // File is in use, ignore
-                } 
+                }
             }
-            
+
             foreach (var file in Directory.GetFiles(packagesPath, "*.pixiext"))
             {
                 LoadExtension(file);
-            } 
+            }
         }
     }
 
@@ -435,5 +439,4 @@ public class ExtensionLoader
 
         return null;
     }
-
 }

+ 1 - 1
src/PixiEditor/Initialization/ClassicDesktopEntry.cs

@@ -192,7 +192,7 @@ internal class ClassicDesktopEntry
 #elif MACOS
         return new PixiEditor.MacOs.MacOperatingSystem();
 #else
-        throw new PlatformNotSupportedException("This platform is not supported");
+        throw new PlatformNotSupportedException("This OS is not supported");
 #endif
     }
 

+ 3 - 0
src/PixiEditor/Models/IO/Paths.cs

@@ -44,6 +44,9 @@ public static class Paths
         Path.GetTempPath(),
         "PixiEditor", "Autosave");
 
+    public static string InstallDirectoryPath { get; } =
+        Path.GetDirectoryName(Assembly.GetEntryAssembly().Location) ?? string.Empty;
+
     public static string ParseSpecialPathOrDefault(string path)
     {
         path = path.Replace("%appdata%", Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData));

+ 13 - 7
src/PixiEditor/RuntimeConstants.cs

@@ -1,17 +1,23 @@
 using System.Diagnostics;
+using System.Reflection;
+using PixiEditor.Models.IO;
 
 namespace PixiEditor;
 
 public static class RuntimeConstants
 {
-    private static Dictionary<string, string> appSettings = File.Exists("appsettings.json")
-        ? System.Text.Json.JsonSerializer.Deserialize<Dictionary<string, string>>(ReadAppSettings())
-        : new Dictionary<string, string>();
+    private static Dictionary<string, string> appSettings =
+        System.Text.Json.JsonSerializer.Deserialize<Dictionary<string, string>>(ReadAppSettings());
 
     private static string ReadAppSettings()
     {
-        string installDirPath = Process.GetCurrentProcess().MainModule?.FileName;
-        string appsettingsPath = Path.Combine(Path.GetDirectoryName(installDirPath) ?? string.Empty, "appsettings.json");
+        string installDirPath = Paths.InstallDirectoryPath;
+        string appsettingsPath = Path.Combine(installDirPath, "appsettings.json");
+        if (!File.Exists(appsettingsPath))
+        {
+            return "{}";
+        }
+        
         using StreamReader reader = new StreamReader(appsettingsPath);
         return reader.ReadToEnd();
     }
@@ -20,9 +26,9 @@ public static class RuntimeConstants
     public static string? AnalyticsUrl =>
         appSettings.TryGetValue("AnalyticsUrl", out string? url) ? url : null;
 
-    public static string? PixiEditorApiUrl =
+    public static string? PixiEditorApiUrl =>
         appSettings.TryGetValue("PixiEditorApiUrl", out string? apiUrl) ? apiUrl : null;
 
-    public static string? PixiEditorApiKey =
+    public static string? PixiEditorApiKey =>
         appSettings.TryGetValue("PixiEditorApiKey", out string? apiKey) ? apiKey : null;
 }