Changeset View
Changeset View
Standalone View
Standalone View
source/blender/blenkernel/intern/appdir.c
| Show First 20 Lines • Show All 238 Lines • ▼ Show 20 Lines | |||||
| } | } | ||||
| /** | /** | ||||
| * Returns the path of a folder from environment variables | * Returns the path of a folder from environment variables | ||||
| * | * | ||||
| * \param targetpath: String to return path. | * \param targetpath: String to return path. | ||||
| * \param subfolder_name: optional name of subfolder within folder. | * \param subfolder_name: optional name of subfolder within folder. | ||||
| * \param envvar: name of environment variable to check folder_name. | * \param envvar: name of environment variable to check folder_name. | ||||
| * \return true if it was able to construct such a path. | * \return true if it was able to construct such a path and the path exists. | ||||
| */ | */ | ||||
| static bool get_path_environment( | static bool get_path_environment( | ||||
| char *targetpath, | char *targetpath, | ||||
| size_t targetpath_len, | size_t targetpath_len, | ||||
| const char *subfolder_name, | const char *subfolder_name, | ||||
| const char *envvar) | const char *envvar) | ||||
| { | { | ||||
| char user_path[FILE_MAX]; | char user_path[FILE_MAX]; | ||||
| Show All 11 Lines | else { | ||||
| BLI_strncpy(targetpath, user_path, FILE_MAX); | BLI_strncpy(targetpath, user_path, FILE_MAX); | ||||
| return true; | return true; | ||||
| } | } | ||||
| } | } | ||||
| return false; | return false; | ||||
| } | } | ||||
| /** | /** | ||||
| * Returns the path of a folder from environment variables | |||||
| * | |||||
| * \param targetpath: String to return path. | |||||
| * \param subfolder_name: optional name of subfolder within folder. | |||||
| * \param envvar: name of environment variable to check folder_name. | |||||
| * \return true if it was able to construct such a path. | |||||
| */ | |||||
| static bool get_path_environment_subfolder_notest( | |||||
campbellbarton: Could call this `get_path_environment_notest` ? `get_path_environment` also takes a `subfolder`. | |||||
| char *targetpath, | |||||
| size_t targetpath_len, | |||||
| const char *subfolder_name, | |||||
| const char *envvar) | |||||
| { | |||||
| char user_path[FILE_MAX]; | |||||
| if (test_env_path(user_path, envvar)) { | |||||
| if (subfolder_name) { | |||||
| BLI_join_dirfile(targetpath, targetpath_len, user_path, subfolder_name); | |||||
| return true; | |||||
| } | |||||
| else { | |||||
| BLI_strncpy(targetpath, user_path, FILE_MAX); | |||||
| return true; | |||||
| } | |||||
| } | |||||
| return false; | |||||
| } | |||||
| /** | |||||
| * Returns the path of a folder within the user-files area. | * Returns the path of a folder within the user-files area. | ||||
| * \param targetpath: String to return path | * \param targetpath: String to return path | ||||
| * \param folder_name: default name of folder within user area | * \param folder_name: default name of folder within user area | ||||
| * \param subfolder_name: optional name of subfolder within folder | * \param subfolder_name: optional name of subfolder within folder | ||||
| * \param ver: Blender version, used to construct a subdirectory name | * \param ver: Blender version, used to construct a subdirectory name | ||||
| * \return true if it was able to construct such a path. | * \return true if it was able to construct such a path. | ||||
| */ | */ | ||||
| static bool get_path_user( | static bool get_path_user( | ||||
| ▲ Show 20 Lines • Show All 159 Lines • ▼ Show 20 Lines | |||||
| */ | */ | ||||
| const char *BKE_appdir_folder_id_user_notest(const int folder_id, const char *subfolder) | const char *BKE_appdir_folder_id_user_notest(const int folder_id, const char *subfolder) | ||||
| { | { | ||||
| const int ver = BLENDER_VERSION; | const int ver = BLENDER_VERSION; | ||||
| static char path[FILE_MAX] = ""; | static char path[FILE_MAX] = ""; | ||||
| switch (folder_id) { | switch (folder_id) { | ||||
| case BLENDER_USER_DATAFILES: | case BLENDER_USER_DATAFILES: | ||||
| if (get_path_environment(path, sizeof(path), subfolder, "BLENDER_USER_DATAFILES")) break; | if (get_path_environment_subfolder_notest(path, sizeof(path), subfolder, "BLENDER_USER_DATAFILES")) break; | ||||
| get_path_user(path, sizeof(path), "datafiles", subfolder, ver); | get_path_user(path, sizeof(path), "datafiles", subfolder, ver); | ||||
| break; | break; | ||||
| case BLENDER_USER_CONFIG: | case BLENDER_USER_CONFIG: | ||||
| if (get_path_environment(path, sizeof(path), subfolder, "BLENDER_USER_CONFIG")) break; | if (get_path_environment_subfolder_notest(path, sizeof(path), subfolder, "BLENDER_USER_CONFIG")) break; | ||||
| get_path_user(path, sizeof(path), "config", subfolder, ver); | get_path_user(path, sizeof(path), "config", subfolder, ver); | ||||
| break; | break; | ||||
| case BLENDER_USER_AUTOSAVE: | case BLENDER_USER_AUTOSAVE: | ||||
| if (get_path_environment(path, sizeof(path), subfolder, "BLENDER_USER_AUTOSAVE")) break; | if (get_path_environment_subfolder_notest(path, sizeof(path), subfolder, "BLENDER_USER_AUTOSAVE")) break; | ||||
| get_path_user(path, sizeof(path), "autosave", subfolder, ver); | get_path_user(path, sizeof(path), "autosave", subfolder, ver); | ||||
| break; | break; | ||||
| case BLENDER_USER_SCRIPTS: | case BLENDER_USER_SCRIPTS: | ||||
| if (get_path_environment(path, sizeof(path), subfolder, "BLENDER_USER_SCRIPTS")) break; | if (get_path_environment_subfolder_notest(path, sizeof(path), subfolder, "BLENDER_USER_SCRIPTS")) break; | ||||
| get_path_user(path, sizeof(path), "scripts", subfolder, ver); | get_path_user(path, sizeof(path), "scripts", subfolder, ver); | ||||
| break; | break; | ||||
| default: | default: | ||||
| BLI_assert(0); | BLI_assert(0); | ||||
| break; | break; | ||||
| } | } | ||||
| if ('\0' == path[0]) { | if ('\0' == path[0]) { | ||||
| ▲ Show 20 Lines • Show All 434 Lines • Show Last 20 Lines | |||||
Could call this get_path_environment_notest ? get_path_environment also takes a subfolder.