Esempio n. 1
0
// PyDoc_STRVAR(bpy_user_resource_doc[] = // now in bpy/utils.py
static PyObject *bpy_user_resource(PyObject *UNUSED(self), PyObject *args, PyObject *kw)
{
	const char *type;
	const char *subdir = NULL;
	int folder_id;
	static const char *kwlist[] = {"type", "subdir", NULL};

	const char *path;

	if (!PyArg_ParseTupleAndKeywords(args, kw, "s|s:user_resource", (char **)kwlist, &type, &subdir))
		return NULL;
	
	/* stupid string compare */
	if      (STREQ(type, "DATAFILES")) folder_id = BLENDER_USER_DATAFILES;
	else if (STREQ(type, "CONFIG"))    folder_id = BLENDER_USER_CONFIG;
	else if (STREQ(type, "SCRIPTS"))   folder_id = BLENDER_USER_SCRIPTS;
	else if (STREQ(type, "AUTOSAVE"))  folder_id = BLENDER_USER_AUTOSAVE;
	else {
		PyErr_SetString(PyExc_ValueError, "invalid resource argument");
		return NULL;
	}
	
	/* same logic as BKE_appdir_folder_id_create(), but best leave it up to the script author to create */
	path = BKE_appdir_folder_id(folder_id, subdir);

	if (!path)
		path = BKE_appdir_folder_id_user_notest(folder_id, subdir);

	return PyC_UnicodeFromByte(path ? path : "");
}
Esempio n. 2
0
/**
 * Returns the path to a folder in the user area, creating it if it doesn't exist.
 */
const char *BKE_appdir_folder_id_create(const int folder_id, const char *subfolder)
{
	const char *path;

	/* only for user folders */
	if (!ELEM(folder_id, BLENDER_USER_DATAFILES, BLENDER_USER_CONFIG, BLENDER_USER_SCRIPTS, BLENDER_USER_AUTOSAVE))
		return NULL;
	
	path = BKE_appdir_folder_id(folder_id, subfolder);
	
	if (!path) {
		path = BKE_appdir_folder_id_user_notest(folder_id, subfolder);
		if (path) BLI_dir_create_recursive(path);
	}
	
	return path;
}