|
@@ -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;
|
|
|
}
|