Serg-Norseman / GEDKeeper

GEDKeeper - program for work with personal genealogical database
https://gedkeeper.net/
GNU General Public License v3.0
149 stars 44 forks source link

`GetTempDir()` is not quite multi-platform #451

Closed danfe closed 1 year ago

danfe commented 1 year ago

On Windows, it's probably safe to assume that TEMP environment variable is always there and set, but on Unix-like systems it is not, and when it is, it's typically named TMP. Consider the following patch:

@@ -1758,7 +1758,11 @@

         public static string GetTempDir()
         {
-            string tempPath = Environment.GetEnvironmentVariable("TEMP");
+            string tempPath;
+            if (SysUtils.IsUnix())
+                tempPath = Environment.GetEnvironmentVariable("TMP") ?? "/tmp";
+            else
+                tempPath = Environment.GetEnvironmentVariable("TEMP");
             return tempPath + Path.DirectorySeparatorChar;
         }
hazzik commented 1 year ago

More correct and cross-platform way would be to use Path.GetTempPath()