diff --git a/Userland/Libraries/LibCore/StandardPaths.cpp b/Userland/Libraries/LibCore/StandardPaths.cpp index 49e20408c3..73d51d7302 100644 --- a/Userland/Libraries/LibCore/StandardPaths.cpp +++ b/Userland/Libraries/LibCore/StandardPaths.cpp @@ -65,6 +65,24 @@ DeprecatedString StandardPaths::config_directory() return LexicalPath::canonicalized_path(builder.to_deprecated_string()); } +DeprecatedString StandardPaths::data_directory() +{ + if (auto* data_directory = getenv("XDG_DATA_HOME")) + return LexicalPath::canonicalized_path(data_directory); + + StringBuilder builder; + builder.append(home_directory()); +#if defined(AK_OS_SERENITY) + builder.append("/.data"sv); +#elif defined(AK_OS_MACOS) + builder.append("/Library/Application Support"sv); +#else + builder.append("/.local/share"sv); +#endif + + return LexicalPath::canonicalized_path(builder.to_deprecated_string()); +} + DeprecatedString StandardPaths::tempfile_directory() { return "/tmp"; diff --git a/Userland/Libraries/LibCore/StandardPaths.h b/Userland/Libraries/LibCore/StandardPaths.h index 234eab42dc..78014ea279 100644 --- a/Userland/Libraries/LibCore/StandardPaths.h +++ b/Userland/Libraries/LibCore/StandardPaths.h @@ -18,6 +18,7 @@ public: static DeprecatedString downloads_directory(); static DeprecatedString tempfile_directory(); static DeprecatedString config_directory(); + static DeprecatedString data_directory(); }; }