From 06514aec6314749d05188cf31a9d40f014cf5976 Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Mon, 28 Nov 2022 10:39:28 +0100 Subject: [PATCH] fs/StandardDirectory: add GetAppCacheDir() --- src/fs/StandardDirectory.cxx | 18 ++++++++++++++++++ src/fs/StandardDirectory.hxx | 7 +++++++ 2 files changed, 25 insertions(+) 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. */