diff options
author | Jeroen Bakker <jbakker> | 2021-10-12 09:42:08 +0300 |
---|---|---|
committer | Jeroen Bakker <jeroen@blender.org> | 2021-10-12 09:42:25 +0300 |
commit | 70fd6a313e70ead89f94090d1de3d90032f778d5 (patch) | |
tree | 1d1887377ecabfa9660f245acbc47515721c19a7 /source/blender/blenkernel | |
parent | 8f66f4031855d1414f1d7475ca7dbc551fc8b0bc (diff) |
GHOST: Add option to request (user) cache folder.
Introduces `BKE_appdir_folder_caches` to get the folder that
can be used to store caches. On different OS's different folders
are used.
- Linux: `~/.cache/blender/`.
- MacOS: `Library/Caches/Blender/`.
- Windows: `(%USERPROFILE%\AppData\Local)\Blender Foundation\Blender\Cache\`.
Reviewed By: Severin
Differential Revision: https://developer.blender.org/D12822
Diffstat (limited to 'source/blender/blenkernel')
-rw-r--r-- | source/blender/blenkernel/BKE_appdir.h | 1 | ||||
-rw-r--r-- | source/blender/blenkernel/intern/appdir.c | 32 |
2 files changed, 33 insertions, 0 deletions
diff --git a/source/blender/blenkernel/BKE_appdir.h b/source/blender/blenkernel/BKE_appdir.h index 0f00d391973..07132201e87 100644 --- a/source/blender/blenkernel/BKE_appdir.h +++ b/source/blender/blenkernel/BKE_appdir.h @@ -35,6 +35,7 @@ void BKE_appdir_exit(void); const char *BKE_appdir_folder_default(void); const char *BKE_appdir_folder_home(void); bool BKE_appdir_folder_documents(char *dir); +bool BKE_appdir_folder_caches(char *r_path, size_t path_len); bool BKE_appdir_folder_id_ex(const int folder_id, const char *subfolder, char *path, diff --git a/source/blender/blenkernel/intern/appdir.c b/source/blender/blenkernel/intern/appdir.c index eae331fc7d1..0bc8d17fdaf 100644 --- a/source/blender/blenkernel/intern/appdir.c +++ b/source/blender/blenkernel/intern/appdir.c @@ -218,6 +218,38 @@ bool BKE_appdir_folder_documents(char *dir) } /** + * Get the user's cache directory, i.e. $HOME/.cache/blender/ on Linux, + * %USERPROFILE%\AppData\Local\blender\ on Windows. + * + * \returns True if the path is valid. It doesn't create or checks format + * if the `blender` folder exists. It does check if the parent of the + * path exists. + */ +bool BKE_appdir_folder_caches(char *r_path, const size_t path_len) +{ + r_path[0] = '\0'; + + const char *caches_root_path = GHOST_getUserSpecialDir(GHOST_kUserSpecialDirCaches); + if (caches_root_path == NULL || !BLI_is_dir(caches_root_path)) { + caches_root_path = BKE_tempdir_base(); + } + if (caches_root_path == NULL || !BLI_is_dir(caches_root_path)) { + return false; + } + +#ifdef WIN32 + BLI_path_join( + r_path, path_len, caches_root_path, "Blender Foundation", "Blender", "Cache", SEP_STR, NULL); +#elif __APPLE__ + BLI_path_join(r_path, path_len, caches_root_path, "Blender", SEP_STR, NULL); +#else /* __linux__ */ + BLI_path_join(r_path, path_len, caches_root_path, "blender", SEP_STR, NULL); +#endif + + return true; +} + +/** * Gets a good default directory for fonts. */ bool BKE_appdir_font_folder_default( |