Bladeren bron

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 jaren geleden
bovenliggende
commit
b079734c5a
1 gewijzigde bestanden met toevoegingen van 8 en 1 verwijderingen
  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");
+    }
 }