diff --git a/src/fs/StandardDirectory.cxx b/src/fs/StandardDirectory.cxx index 2a31d170b..ad0ae2118 100644 --- a/src/fs/StandardDirectory.cxx +++ b/src/fs/StandardDirectory.cxx @@ -290,6 +290,24 @@ GetUserCacheDir() noexcept #endif } +AllocatedPath +GetAppCacheDir() noexcept +{ +#ifdef USE_XDG + if (const auto user_dir = GetUserCacheDir(); !user_dir.IsNull()) { + auto dir = user_dir / app_filename; + CreateDirectoryNoThrow(dir); + return dir; + } + + return nullptr; +#elif defined(ANDROID) + return context->GetCacheDir(Java::GetEnv()); +#else + return nullptr; +#endif +} + AllocatedPath GetUserRuntimeDir() noexcept { diff --git a/src/fs/StandardDirectory.hxx b/src/fs/StandardDirectory.hxx index 99cf0dc70..29746bc3a 100644 --- a/src/fs/StandardDirectory.hxx +++ b/src/fs/StandardDirectory.hxx @@ -43,6 +43,13 @@ GetUserMusicDir() noexcept; AllocatedPath GetUserCacheDir() noexcept; +/** + * Obtains cache directory for this application. + */ +[[gnu::const]] +AllocatedPath +GetAppCacheDir() noexcept; + /** * Obtains the runtime directory for the current user. */