/// <summary>Read the database for the specified terminal.</summary> /// <param name="term">The identifier for the terminal.</param> /// <returns>The database, or null if it could not be found.</returns> private static Database ReadDatabase(string term) { // This follows the same search order as prescribed by ncurses. Database db; // First try a location specified in the TERMINFO environment variable. string terminfo = Environment.GetEnvironmentVariable("TERMINFO"); if (!string.IsNullOrWhiteSpace(terminfo) && (db = ReadDatabase(term, terminfo)) != null) { return(db); } // Then try in the user's home directory. string home = PersistedFiles.GetHomeDirectory(); if (!string.IsNullOrWhiteSpace(home) && (db = ReadDatabase(term, home + "/.terminfo")) != null) { return(db); } // Then try a set of well-known locations. foreach (string terminfoLocation in _terminfoLocations) { if ((db = ReadDatabase(term, terminfoLocation)) != null) { return(db); } } // Couldn't find one return(null); }
private static string GetFolderPathCoreWithoutValidation(SpecialFolder folder) { // First handle any paths that involve only static paths, avoiding the overheads of getting user-local paths. // https://www.freedesktop.org/software/systemd/man/file-hierarchy.html switch (folder) { case SpecialFolder.CommonApplicationData: return("/usr/share"); case SpecialFolder.CommonTemplates: return("/usr/share/templates"); } if (IsMac) { switch (folder) { case SpecialFolder.ProgramFiles: return("/Applications"); case SpecialFolder.System: return("/System"); } } // All other paths are based on the XDG Base Directory Specification: // https://specifications.freedesktop.org/basedir-spec/latest/ string home = null; try { home = PersistedFiles.GetHomeDirectory(); } catch (Exception exc) { Debug.Fail($"Unable to get home directory: {exc}"); } if (string.IsNullOrEmpty(home)) { home = Path.GetTempPath(); } // TODO: Consider caching (or precomputing and caching) all subsequent results. // This would significantly improve performance for repeated access, at the expense // of not being responsive to changes in the underlying environment variables, // configuration files, etc. switch (folder) { case SpecialFolder.UserProfile: case SpecialFolder.MyDocuments: // same value as Personal return(home); case SpecialFolder.ApplicationData: return(GetXdgConfig(home)); case SpecialFolder.LocalApplicationData: // "$XDG_DATA_HOME defines the base directory relative to which user specific data files should be stored." // "If $XDG_DATA_HOME is either not set or empty, a default equal to $HOME/.local/share should be used." string data = GetEnvironmentVariable("XDG_DATA_HOME"); if (string.IsNullOrEmpty(data) || data[0] != '/') { data = Path.Combine(home, ".local", "share"); } return(data); case SpecialFolder.Desktop: case SpecialFolder.DesktopDirectory: return(ReadXdgDirectory(home, "XDG_DESKTOP_DIR", "Desktop")); case SpecialFolder.Templates: return(ReadXdgDirectory(home, "XDG_TEMPLATES_DIR", "Templates")); case SpecialFolder.MyVideos: return(ReadXdgDirectory(home, "XDG_VIDEOS_DIR", "Videos")); case SpecialFolder.MyMusic: return(IsMac ? Path.Combine(home, "Music") : ReadXdgDirectory(home, "XDG_MUSIC_DIR", "Music")); case SpecialFolder.MyPictures: return(IsMac ? Path.Combine(home, "Pictures") : ReadXdgDirectory(home, "XDG_PICTURES_DIR", "Pictures")); case SpecialFolder.Fonts: return(IsMac ? Path.Combine(home, "Library", "Fonts") : Path.Combine(home, ".fonts")); case SpecialFolder.Favorites: if (IsMac) { return(Path.Combine(home, "Library", "Favorites")); } break; case SpecialFolder.InternetCache: if (IsMac) { return(Path.Combine(home, "Library", "Caches")); } break; } // No known path for the SpecialFolder return(string.Empty); }
private static string?GetSpecialFolder(SpecialFolder folder) { string?home = null; try { home = PersistedFiles.GetHomeDirectory(); } catch (Exception exc) { Debug.Fail($"Unable to get home directory: {exc}"); } // Fall back to '/' when we can't determine the home directory. // This location isn't writable by non-root users which provides some safeguard // that the application doesn't write data which is meant to be private. if (string.IsNullOrEmpty(home)) { home = "/"; } switch (folder) { case SpecialFolder.Personal: case SpecialFolder.LocalApplicationData: return(home); case SpecialFolder.ApplicationData: return(Path.Combine(home, ".config")); case SpecialFolder.Desktop: case SpecialFolder.DesktopDirectory: return(Path.Combine(home, "Desktop")); case SpecialFolder.MyMusic: return(Path.Combine(home, "Music")); case SpecialFolder.MyPictures: return(Path.Combine(home, "Pictures")); case SpecialFolder.Templates: return(Path.Combine(home, "Templates")); case SpecialFolder.MyVideos: return(Path.Combine(home, "Videos")); case SpecialFolder.CommonTemplates: return("/usr/share/templates"); case SpecialFolder.Fonts: return(Path.Combine(home, ".fonts")); case SpecialFolder.UserProfile: return(GetEnvironmentVariable("HOME")); case SpecialFolder.CommonApplicationData: return("/usr/share"); default: return(string.Empty); } }