+ private static string ReadXdgUserDir (string config_dir, string home_dir,
+ string key, string fallback)
+ {
+ string env_path = internalGetEnvironmentVariable (key);
+ if (env_path != null && env_path != String.Empty) {
+ return env_path;
+ }
+
+ string user_dirs_path = Path.Combine (config_dir, "user-dirs.dirs");
+
+ if (!File.Exists (user_dirs_path)) {
+ return Path.Combine (home_dir, fallback);
+ }
+
+ try {
+ using(StreamReader reader = new StreamReader (user_dirs_path)) {
+ string line;
+ while ((line = reader.ReadLine ()) != null) {
+ line = line.Trim ();
+ int delim_index = line.IndexOf ('=');
+ if(delim_index > 8 && line.Substring (0, delim_index) == key) {
+ string path = line.Substring (delim_index + 1).Trim ('"');
+ bool relative = false;
+
+ if (path.StartsWith ("$HOME/")) {
+ relative = true;
+ path = path.Substring (6);
+ } else if (!path.StartsWith ("/")) {
+ relative = true;
+ }
+
+ return relative ? Path.Combine (home_dir, path) : path;
+ }
+ }
+ }
+ } catch (FileNotFoundException) {
+ }
+
+ return Path.Combine (home_dir, fallback);
+ }
+
+