瀏覽代碼

Look for settings in same dir as exe instead of working dir

The app would look for the settings file in the current working directory, and the "Start with PC" option's working directory is System32. This changes it so it will always look in the same place as the exe it launched from.

Fixes #2
Daniel Chalmers 2 年之前
父節點
當前提交
b079734c5a
共有 1 個文件被更改,包括 8 次插入1 次删除
  1. 8 1
      DesktopClock/Properties/Settings.cs

+ 8 - 1
DesktopClock/Properties/Settings.cs

@@ -11,7 +11,7 @@ public sealed class Settings : INotifyPropertyChanged
 {
     private DateTime _fileLastUsed = DateTime.UtcNow;
 
-    public static readonly string Path = System.Diagnostics.Process.GetCurrentProcess().ProcessName + ".settings";
+    public static readonly string Path = GetSettingsPath();
     private static readonly Lazy<Settings> _default = new(() => TryLoad() ?? new Settings());
 
     private static readonly JsonSerializerSettings _jsonSerializerSettings = new()
@@ -116,4 +116,11 @@ public sealed class Settings : INotifyPropertyChanged
             return null;
         }
     }
+
+    private static string GetSettingsPath()
+    {
+        var exeInfo = new FileInfo(System.Reflection.Assembly.GetEntryAssembly().Location);
+        var exeNameWithoutExtension = System.IO.Path.GetFileNameWithoutExtension(exeInfo.FullName);
+        return System.IO.Path.Combine(exeInfo.DirectoryName, exeNameWithoutExtension + ".settings");
+    }
 }