瀏覽代碼

Simplify code to get data dir

Bond_009 6 年之前
父節點
當前提交
a94aeb5c87
共有 1 個文件被更改,包括 4 次插入18 次删除
  1. 4 18
      Jellyfin.Server/Program.cs

+ 4 - 18
Jellyfin.Server/Program.cs

@@ -181,26 +181,13 @@ namespace Jellyfin.Server
 
                 if (string.IsNullOrEmpty(dataDir))
                 {
-                    if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
-                    {
-                        dataDir = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData);
-                    }
-                    else
-                    {
-                        // $XDG_DATA_HOME defines the base directory relative to which user specific data files should be stored.
-                        dataDir = Environment.GetEnvironmentVariable("XDG_DATA_HOME");
-
-                        // If $XDG_DATA_HOME is either not set or empty, a default equal to $HOME/.local/share should be used.
-                        if (string.IsNullOrEmpty(dataDir))
-                        {
-                            dataDir = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.UserProfile), ".local", "share");
-                        }
-                    }
-
-                    dataDir = Path.Combine(dataDir, "jellyfin");
+                    // LocalApplicationData follows the XDG spec on unix machines
+                    dataDir = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), "jellyfin");
                 }
             }
 
+            Directory.CreateDirectory(dataDir);
+
             // configDir
             // IF      --configdir
             // ELSE IF $JELLYFIN_CONFIG_DIR
@@ -210,7 +197,6 @@ namespace Jellyfin.Server
             // ELSE IF $XDG_CONFIG_HOME use $XDG_CONFIG_HOME/jellyfin
             // ELSE    $HOME/.config/jellyfin
             var configDir = options.ConfigDir;
-
             if (string.IsNullOrEmpty(configDir))
             {
                 configDir = Environment.GetEnvironmentVariable("JELLYFIN_CONFIG_DIR");