api changes needed for for copying old settings to new.
- py: bpy.utils.resource_path('USER', 2, 56) - C: BLI_get_folder_version(id, major, minor, check);
This commit is contained in:
parent
d4d88de2b0
commit
f8c09b37d4
@ -23,7 +23,7 @@ This module contains utility functions specific to blender but
|
||||
not assosiated with blenders internal data.
|
||||
"""
|
||||
|
||||
from _bpy import register_class, unregister_class, blend_paths
|
||||
from _bpy import register_class, unregister_class, blend_paths, resource_path
|
||||
from _bpy import script_paths as _bpy_script_paths
|
||||
from _bpy import user_resource as _user_resource
|
||||
|
||||
|
@ -45,6 +45,7 @@ const char *BLI_getDefaultDocumentFolder(void);
|
||||
char *BLI_get_folder(int folder_id, const char *subfolder);
|
||||
char *BLI_get_folder_create(int folder_id, const char *subfolder);
|
||||
char *BLI_get_user_folder_notest(int folder_id, const char *subfolder);
|
||||
char *BLI_get_folder_version(const int id, const int ver, const int do_check);
|
||||
|
||||
/* folder_id */
|
||||
|
||||
@ -73,6 +74,11 @@ char *BLI_get_user_folder_notest(int folder_id, const char *subfolder);
|
||||
|
||||
#define BLENDER_USERFOLDER(id) (id >= BLENDER_USER_CONFIG && id <= BLENDER_USER_PLUGINS)
|
||||
|
||||
/* for BLI_get_folder_version only */
|
||||
#define BLENDER_RESOURCE_PATH_USER 0
|
||||
#define BLENDER_RESOURCE_PATH_LOCAL 1
|
||||
#define BLENDER_RESOURCE_PATH_SYSTEM 2
|
||||
|
||||
#define BLENDER_STARTUP_FILE "startup.blend"
|
||||
#define BLENDER_BOOKMARK_FILE "bookmarks.txt"
|
||||
#define BLENDER_HISTORY_FILE "recent-files.txt"
|
||||
|
@ -90,7 +90,7 @@
|
||||
extern char bprogname[];
|
||||
|
||||
static int add_win32_extension(char *name);
|
||||
static char *blender_version_decimal(void);
|
||||
static char *blender_version_decimal(const int ver);
|
||||
|
||||
/* implementation */
|
||||
|
||||
@ -823,10 +823,10 @@ const char *BLI_getDefaultDocumentFolder(void) {
|
||||
|
||||
// #define PATH_DEBUG2
|
||||
|
||||
static char *blender_version_decimal(void)
|
||||
static char *blender_version_decimal(const int ver)
|
||||
{
|
||||
static char version_str[5];
|
||||
sprintf(version_str, "%d.%02d", BLENDER_VERSION/100, BLENDER_VERSION%100);
|
||||
sprintf(version_str, "%d.%02d", ver/100, ver%100);
|
||||
return version_str;
|
||||
}
|
||||
|
||||
@ -836,9 +836,13 @@ static int test_path(char *targetpath, const char *path_base, const char *path_s
|
||||
|
||||
if(path_sep) BLI_join_dirfile(tmppath, sizeof(tmppath), path_base, path_sep);
|
||||
else BLI_strncpy(tmppath, path_base, sizeof(tmppath));
|
||||
|
||||
BLI_make_file_string("/", targetpath, tmppath, folder_name);
|
||||
|
||||
|
||||
/* rare cases folder_name is omitted (when looking for ~/.blender/2.xx dir only) */
|
||||
if(folder_name)
|
||||
BLI_make_file_string("/", targetpath, tmppath, folder_name);
|
||||
else
|
||||
BLI_strncpy(targetpath, tmppath, sizeof(tmppath));
|
||||
|
||||
if (BLI_is_dir(targetpath)) {
|
||||
#ifdef PATH_DEBUG2
|
||||
printf("\tpath found: %s\n", targetpath);
|
||||
@ -868,7 +872,7 @@ static int test_env_path(char *path, const char *envvar)
|
||||
}
|
||||
}
|
||||
|
||||
static int get_path_local(char *targetpath, const char *folder_name, const char *subfolder_name)
|
||||
static int get_path_local(char *targetpath, const char *folder_name, const char *subfolder_name, const int ver)
|
||||
{
|
||||
char bprogdir[FILE_MAX];
|
||||
char relfolder[FILE_MAX];
|
||||
@ -876,24 +880,29 @@ static int get_path_local(char *targetpath, const char *folder_name, const char
|
||||
#ifdef PATH_DEBUG2
|
||||
printf("get_path_local...\n");
|
||||
#endif
|
||||
|
||||
if (subfolder_name) {
|
||||
BLI_join_dirfile(relfolder, sizeof(relfolder), folder_name, subfolder_name);
|
||||
} else {
|
||||
BLI_strncpy(relfolder, folder_name, sizeof(relfolder));
|
||||
|
||||
if(folder_name) {
|
||||
if (subfolder_name) {
|
||||
BLI_join_dirfile(relfolder, sizeof(relfolder), folder_name, subfolder_name);
|
||||
} else {
|
||||
BLI_strncpy(relfolder, folder_name, sizeof(relfolder));
|
||||
}
|
||||
}
|
||||
else {
|
||||
relfolder[0]= '\0';
|
||||
}
|
||||
|
||||
/* use argv[0] (bprogname) to get the path to the executable */
|
||||
BLI_split_dirfile(bprogname, bprogdir, NULL);
|
||||
|
||||
/* try EXECUTABLE_DIR/2.5x/folder_name - new default directory for local blender installed files */
|
||||
if(test_path(targetpath, bprogdir, blender_version_decimal(), relfolder))
|
||||
if(test_path(targetpath, bprogdir, blender_version_decimal(ver), relfolder))
|
||||
return 1;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int get_path_user(char *targetpath, const char *folder_name, const char *subfolder_name, const char *envvar)
|
||||
static int get_path_user(char *targetpath, const char *folder_name, const char *subfolder_name, const char *envvar, const int ver)
|
||||
{
|
||||
char user_path[FILE_MAX];
|
||||
const char *user_base_path;
|
||||
@ -911,7 +920,7 @@ static int get_path_user(char *targetpath, const char *folder_name, const char *
|
||||
|
||||
user_base_path = (const char *)GHOST_getUserDir();
|
||||
if (user_base_path) {
|
||||
BLI_snprintf(user_path, FILE_MAX, BLENDER_USER_FORMAT, user_base_path, blender_version_decimal());
|
||||
BLI_snprintf(user_path, FILE_MAX, BLENDER_USER_FORMAT, user_base_path, blender_version_decimal(ver));
|
||||
}
|
||||
|
||||
if(!user_path[0])
|
||||
@ -930,7 +939,7 @@ static int get_path_user(char *targetpath, const char *folder_name, const char *
|
||||
}
|
||||
}
|
||||
|
||||
static int get_path_system(char *targetpath, const char *folder_name, const char *subfolder_name, const char *envvar)
|
||||
static int get_path_system(char *targetpath, const char *folder_name, const char *subfolder_name, const char *envvar, const int ver)
|
||||
{
|
||||
char system_path[FILE_MAX];
|
||||
const char *system_base_path;
|
||||
@ -945,10 +954,15 @@ static int get_path_system(char *targetpath, const char *folder_name, const char
|
||||
/* use argv[0] (bprogname) to get the path to the executable */
|
||||
BLI_split_dirfile(bprogname, bprogdir, NULL);
|
||||
|
||||
if (subfolder_name) {
|
||||
BLI_join_dirfile(relfolder, sizeof(relfolder), folder_name, subfolder_name);
|
||||
} else {
|
||||
BLI_strncpy(relfolder, folder_name, sizeof(relfolder));
|
||||
if(folder_name) {
|
||||
if (subfolder_name) {
|
||||
BLI_join_dirfile(relfolder, sizeof(relfolder), folder_name, subfolder_name);
|
||||
} else {
|
||||
BLI_strncpy(relfolder, folder_name, sizeof(relfolder));
|
||||
}
|
||||
}
|
||||
else {
|
||||
relfolder[0]= '\0';
|
||||
}
|
||||
|
||||
/* try CWD/release/folder_name */
|
||||
@ -978,7 +992,7 @@ static int get_path_system(char *targetpath, const char *folder_name, const char
|
||||
|
||||
system_base_path = (const char *)GHOST_getSystemDir();
|
||||
if (system_base_path) {
|
||||
BLI_snprintf(system_path, FILE_MAX, BLENDER_SYSTEM_FORMAT, system_base_path, blender_version_decimal());
|
||||
BLI_snprintf(system_path, FILE_MAX, BLENDER_SYSTEM_FORMAT, system_base_path, blender_version_decimal(ver));
|
||||
}
|
||||
|
||||
if(!system_path[0])
|
||||
@ -1001,70 +1015,71 @@ static int get_path_system(char *targetpath, const char *folder_name, const char
|
||||
/* returns the path if found, NULL string if not */
|
||||
char *BLI_get_folder(int folder_id, const char *subfolder)
|
||||
{
|
||||
const int ver= BLENDER_VERSION;
|
||||
static char path[FILE_MAX] = "";
|
||||
|
||||
switch (folder_id) {
|
||||
case BLENDER_DATAFILES: /* general case */
|
||||
if (get_path_local(path, "datafiles", subfolder)) break;
|
||||
if (get_path_user(path, "datafiles", subfolder, "BLENDER_USER_DATAFILES")) break;
|
||||
if (get_path_system(path, "datafiles", subfolder, "BLENDER_SYSTEM_DATAFILES")) break;
|
||||
if (get_path_local(path, "datafiles", subfolder, ver)) break;
|
||||
if (get_path_user(path, "datafiles", subfolder, "BLENDER_USER_DATAFILES", ver)) break;
|
||||
if (get_path_system(path, "datafiles", subfolder, "BLENDER_SYSTEM_DATAFILES", ver)) break;
|
||||
return NULL;
|
||||
|
||||
case BLENDER_USER_DATAFILES:
|
||||
if (get_path_local(path, "datafiles", subfolder)) break;
|
||||
if (get_path_user(path, "datafiles", subfolder, "BLENDER_USER_DATAFILES")) break;
|
||||
if (get_path_local(path, "datafiles", subfolder, ver)) break;
|
||||
if (get_path_user(path, "datafiles", subfolder, "BLENDER_USER_DATAFILES", ver)) break;
|
||||
return NULL;
|
||||
|
||||
case BLENDER_SYSTEM_DATAFILES:
|
||||
if (get_path_local(path, "datafiles", subfolder)) break;
|
||||
if (get_path_system(path, "datafiles", subfolder, "BLENDER_SYSTEM_DATAFILES")) break;
|
||||
if (get_path_local(path, "datafiles", subfolder, ver)) break;
|
||||
if (get_path_system(path, "datafiles", subfolder, "BLENDER_SYSTEM_DATAFILES", ver)) break;
|
||||
return NULL;
|
||||
|
||||
case BLENDER_USER_AUTOSAVE:
|
||||
if (get_path_local(path, "autosave", subfolder)) break;
|
||||
if (get_path_user(path, "autosave", subfolder, "BLENDER_USER_DATAFILES")) break;
|
||||
if (get_path_local(path, "autosave", subfolder, ver)) break;
|
||||
if (get_path_user(path, "autosave", subfolder, "BLENDER_USER_DATAFILES", ver)) break;
|
||||
return NULL;
|
||||
|
||||
case BLENDER_CONFIG: /* general case */
|
||||
if (get_path_local(path, "config", subfolder)) break;
|
||||
if (get_path_user(path, "config", subfolder, "BLENDER_USER_CONFIG")) break;
|
||||
if (get_path_system(path, "config", subfolder, "BLENDER_SYSTEM_CONFIG")) break;
|
||||
if (get_path_local(path, "config", subfolder, ver)) break;
|
||||
if (get_path_user(path, "config", subfolder, "BLENDER_USER_CONFIG", ver)) break;
|
||||
if (get_path_system(path, "config", subfolder, "BLENDER_SYSTEM_CONFIG", ver)) break;
|
||||
return NULL;
|
||||
|
||||
case BLENDER_USER_CONFIG:
|
||||
if (get_path_local(path, "config", subfolder)) break;
|
||||
if (get_path_user(path, "config", subfolder, "BLENDER_USER_CONFIG")) break;
|
||||
if (get_path_local(path, "config", subfolder, ver)) break;
|
||||
if (get_path_user(path, "config", subfolder, "BLENDER_USER_CONFIG", ver)) break;
|
||||
return NULL;
|
||||
|
||||
case BLENDER_SYSTEM_CONFIG:
|
||||
if (get_path_local(path, "config", subfolder)) break;
|
||||
if (get_path_system(path, "config", subfolder, "BLENDER_SYSTEM_CONFIG")) break;
|
||||
if (get_path_local(path, "config", subfolder, ver)) break;
|
||||
if (get_path_system(path, "config", subfolder, "BLENDER_SYSTEM_CONFIG", ver)) break;
|
||||
return NULL;
|
||||
|
||||
case BLENDER_SCRIPTS: /* general case */
|
||||
if (get_path_local(path, "scripts", subfolder)) break;
|
||||
if (get_path_user(path, "scripts", subfolder, "BLENDER_USER_SCRIPTS")) break;
|
||||
if (get_path_system(path, "scripts", subfolder, "BLENDER_SYSTEM_SCRIPTS")) break;
|
||||
if (get_path_local(path, "scripts", subfolder, ver)) break;
|
||||
if (get_path_user(path, "scripts", subfolder, "BLENDER_USER_SCRIPTS", ver)) break;
|
||||
if (get_path_system(path, "scripts", subfolder, "BLENDER_SYSTEM_SCRIPTS", ver)) break;
|
||||
return NULL;
|
||||
|
||||
case BLENDER_USER_SCRIPTS:
|
||||
if (get_path_local(path, "scripts", subfolder)) break;
|
||||
if (get_path_user(path, "scripts", subfolder, "BLENDER_USER_SCRIPTS")) break;
|
||||
if (get_path_local(path, "scripts", subfolder, ver)) break;
|
||||
if (get_path_user(path, "scripts", subfolder, "BLENDER_USER_SCRIPTS", ver)) break;
|
||||
return NULL;
|
||||
|
||||
case BLENDER_SYSTEM_SCRIPTS:
|
||||
if (get_path_local(path, "scripts", subfolder)) break;
|
||||
if (get_path_system(path, "scripts", subfolder, "BLENDER_SYSTEM_SCRIPTS")) break;
|
||||
if (get_path_local(path, "scripts", subfolder, ver)) break;
|
||||
if (get_path_system(path, "scripts", subfolder, "BLENDER_SYSTEM_SCRIPTS", ver)) break;
|
||||
return NULL;
|
||||
|
||||
case BLENDER_PYTHON: /* general case */
|
||||
if (get_path_local(path, "python", subfolder)) break;
|
||||
if (get_path_system(path, "python", subfolder, "BLENDER_SYSTEM_PYTHON")) break;
|
||||
if (get_path_local(path, "python", subfolder, ver)) break;
|
||||
if (get_path_system(path, "python", subfolder, "BLENDER_SYSTEM_PYTHON", ver)) break;
|
||||
return NULL;
|
||||
|
||||
case BLENDER_SYSTEM_PYTHON:
|
||||
if (get_path_local(path, "python", subfolder)) break;
|
||||
if (get_path_system(path, "python", subfolder, "BLENDER_SYSTEM_PYTHON")) break;
|
||||
if (get_path_local(path, "python", subfolder, ver)) break;
|
||||
if (get_path_system(path, "python", subfolder, "BLENDER_SYSTEM_PYTHON", ver)) break;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
@ -1073,20 +1088,21 @@ char *BLI_get_folder(int folder_id, const char *subfolder)
|
||||
|
||||
char *BLI_get_user_folder_notest(int folder_id, const char *subfolder)
|
||||
{
|
||||
const int ver= BLENDER_VERSION;
|
||||
static char path[FILE_MAX] = "";
|
||||
|
||||
switch (folder_id) {
|
||||
case BLENDER_USER_DATAFILES:
|
||||
get_path_user(path, "datafiles", subfolder, "BLENDER_USER_DATAFILES");
|
||||
get_path_user(path, "datafiles", subfolder, "BLENDER_USER_DATAFILES", ver);
|
||||
break;
|
||||
case BLENDER_USER_CONFIG:
|
||||
get_path_user(path, "config", subfolder, "BLENDER_USER_CONFIG");
|
||||
get_path_user(path, "config", subfolder, "BLENDER_USER_CONFIG", ver);
|
||||
break;
|
||||
case BLENDER_USER_AUTOSAVE:
|
||||
get_path_user(path, "autosave", subfolder, "BLENDER_USER_AUTOSAVE");
|
||||
get_path_user(path, "autosave", subfolder, "BLENDER_USER_AUTOSAVE", ver);
|
||||
break;
|
||||
case BLENDER_USER_SCRIPTS:
|
||||
get_path_user(path, "scripts", subfolder, "BLENDER_USER_SCRIPTS");
|
||||
get_path_user(path, "scripts", subfolder, "BLENDER_USER_SCRIPTS", ver);
|
||||
break;
|
||||
}
|
||||
if ('\0' == path[0]) {
|
||||
@ -1113,6 +1129,30 @@ char *BLI_get_folder_create(int folder_id, const char *subfolder)
|
||||
return path;
|
||||
}
|
||||
|
||||
char *BLI_get_folder_version(const int id, const int ver, const int do_check)
|
||||
{
|
||||
static char path[FILE_MAX] = "";
|
||||
int ok;
|
||||
switch(id) {
|
||||
case BLENDER_RESOURCE_PATH_USER:
|
||||
ok= get_path_user(path, NULL, NULL, NULL, ver);
|
||||
break;
|
||||
case BLENDER_RESOURCE_PATH_LOCAL:
|
||||
ok= get_path_local(path, NULL, NULL, ver);
|
||||
break;
|
||||
case BLENDER_RESOURCE_PATH_SYSTEM:
|
||||
ok= get_path_system(path, NULL, NULL, NULL, ver);
|
||||
break;
|
||||
default:
|
||||
BLI_assert(!"incorrect ID");
|
||||
}
|
||||
|
||||
if((ok == FALSE) && do_check) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return path;
|
||||
}
|
||||
|
||||
/* End new stuff */
|
||||
/* ************************************************************* */
|
||||
|
@ -48,6 +48,7 @@
|
||||
|
||||
|
||||
#include "BKE_global.h" /* XXX, G.main only */
|
||||
#include "BKE_blender.h"
|
||||
|
||||
#include "RNA_access.h"
|
||||
|
||||
@ -69,8 +70,8 @@ static char bpy_script_paths_doc[] =
|
||||
" Return 2 paths to blender scripts directories.\n"
|
||||
"\n"
|
||||
" :return: (system, user) strings will be empty when not found.\n"
|
||||
" :rtype: tuple of strigs\n";
|
||||
|
||||
" :rtype: tuple of strings\n"
|
||||
;
|
||||
static PyObject *bpy_script_paths(PyObject *UNUSED(self))
|
||||
{
|
||||
PyObject *ret= PyTuple_New(2);
|
||||
@ -92,7 +93,8 @@ static char bpy_blend_paths_doc[] =
|
||||
" :arg absolute: When true the paths returned are made absolute.\n"
|
||||
" :type absolute: boolean\n"
|
||||
" :return: path list.\n"
|
||||
" :rtype: list of strigs\n";
|
||||
" :rtype: list of strings\n"
|
||||
;
|
||||
static PyObject *bpy_blend_paths(PyObject *UNUSED(self), PyObject *args, PyObject *kw)
|
||||
{
|
||||
struct BPathIterator *bpi;
|
||||
@ -167,9 +169,50 @@ static PyObject *bpy_user_resource(PyObject *UNUSED(self), PyObject *args, PyObj
|
||||
return PyUnicode_DecodeFSDefault(path ? path : "");
|
||||
}
|
||||
|
||||
static char bpy_resource_path_doc[] =
|
||||
".. function:: resource_path(type, major=2, minor=57)\n"
|
||||
"\n"
|
||||
" Return the base path for storing system files.\n"
|
||||
"\n"
|
||||
" :arg type: string in ['USER', 'LOCAL', 'SYSTEM'].\n"
|
||||
" :type type: string\n"
|
||||
" :arg major: major version, defaults to current.\n"
|
||||
" :type major: int\n"
|
||||
" :arg minor: minor version, defaults to current.\n"
|
||||
" :type minor: string\n"
|
||||
" :return: the resource path (not necessarily existing).\n"
|
||||
" :rtype: string\n"
|
||||
;
|
||||
static PyObject *bpy_resource_path(PyObject *UNUSED(self), PyObject *args, PyObject *kw)
|
||||
{
|
||||
char *type;
|
||||
int major= BLENDER_VERSION/100, minor= BLENDER_VERSION%100;
|
||||
static const char *kwlist[]= {"type", "major", "minor", NULL};
|
||||
int folder_id;
|
||||
char *path;
|
||||
|
||||
if (!PyArg_ParseTupleAndKeywords(args, kw, "s|ii:resource_path", (char **)kwlist, &type, &major, &minor))
|
||||
return NULL;
|
||||
|
||||
/* stupid string compare */
|
||||
if (!strcmp(type, "USER")) folder_id= BLENDER_RESOURCE_PATH_USER;
|
||||
else if(!strcmp(type, "LOCAL")) folder_id= BLENDER_RESOURCE_PATH_LOCAL;
|
||||
else if(!strcmp(type, "SYSTEM")) folder_id= BLENDER_RESOURCE_PATH_SYSTEM;
|
||||
else {
|
||||
PyErr_SetString(PyExc_ValueError, "invalid resource argument");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
path= BLI_get_folder_version(folder_id, (major * 100) + minor, FALSE);
|
||||
|
||||
return PyUnicode_DecodeFSDefault(path);
|
||||
}
|
||||
|
||||
static PyMethodDef meth_bpy_script_paths= {"script_paths", (PyCFunction)bpy_script_paths, METH_NOARGS, bpy_script_paths_doc};
|
||||
static PyMethodDef meth_bpy_blend_paths= {"blend_paths", (PyCFunction)bpy_blend_paths, METH_VARARGS|METH_KEYWORDS, bpy_blend_paths_doc};
|
||||
static PyMethodDef meth_bpy_user_resource= {"user_resource", (PyCFunction)bpy_user_resource, METH_VARARGS|METH_KEYWORDS, NULL};
|
||||
static PyMethodDef meth_bpy_resource_path= {"resource_path", (PyCFunction)bpy_resource_path, METH_VARARGS|METH_KEYWORDS, bpy_resource_path_doc};
|
||||
|
||||
|
||||
static PyObject *bpy_import_test(const char *modname)
|
||||
{
|
||||
@ -244,6 +287,7 @@ void BPy_init_modules( void )
|
||||
PyModule_AddObject(mod, meth_bpy_script_paths.ml_name, (PyObject *)PyCFunction_New(&meth_bpy_script_paths, NULL));
|
||||
PyModule_AddObject(mod, meth_bpy_blend_paths.ml_name, (PyObject *)PyCFunction_New(&meth_bpy_blend_paths, NULL));
|
||||
PyModule_AddObject(mod, meth_bpy_user_resource.ml_name, (PyObject *)PyCFunction_New(&meth_bpy_user_resource, NULL));
|
||||
PyModule_AddObject(mod, meth_bpy_resource_path.ml_name, (PyObject *)PyCFunction_New(&meth_bpy_resource_path, NULL));
|
||||
|
||||
/* register funcs (bpy_rna.c) */
|
||||
PyModule_AddObject(mod, meth_bpy_register_class.ml_name, (PyObject *)PyCFunction_New(&meth_bpy_register_class, NULL));
|
||||
|
@ -670,11 +670,13 @@ int BPY_context_member_get(bContext *C, const char *member, bContextDataResult *
|
||||
}
|
||||
|
||||
if(done==0) {
|
||||
if (item) printf("Context '%s' not a valid type\n", member);
|
||||
else printf("Context '%s' not found\n", member);
|
||||
if (item) printf("PyContext '%s' not a valid type\n", member);
|
||||
else printf("PyContext '%s' not found\n", member);
|
||||
}
|
||||
else {
|
||||
printf("Context '%s' found\n", member);
|
||||
if(G.f & G_DEBUG) {
|
||||
printf("PyContext '%s' found\n", member);
|
||||
}
|
||||
}
|
||||
|
||||
return done;
|
||||
|
Loading…
Reference in New Issue
Block a user