Page MenuHome

file_paths_01.txt

Authored By
Matt Ebb (broken)
Nov 13 2013, 2:28 PM
Size
14 KB
Subscribers
None

file_paths_01.txt

Index: source/blender/blenkernel/intern/blender.c
===================================================================
--- source/blender/blenkernel/intern/blender.c (revision 28755)
+++ source/blender/blenkernel/intern/blender.c (working copy)
@@ -55,6 +55,7 @@
#include "BLI_blenlib.h"
#include "BLI_dynstr.h"
+#include "BLI_path_util.h"
#include "IMB_imbuf.h"
@@ -367,7 +368,7 @@
BlendFileData *bfd;
int retval= 1;
- if(strstr(dir, ".B25.blend")==0) /* dont print user-pref loading */
+ if(strstr(dir, BLENDER_STARTUP_FILE)==0) /* dont print user-pref loading */
printf("read blend: %s\n", dir);
bfd= BLO_read_from_file(dir, reports);
Index: source/blender/windowmanager/intern/wm_files.c
===================================================================
--- source/blender/windowmanager/intern/wm_files.c (revision 28755)
+++ source/blender/windowmanager/intern/wm_files.c (working copy)
@@ -322,17 +322,14 @@
{
ListBase wmbase;
char tstr[FILE_MAXDIR+FILE_MAXFILE], scestr[FILE_MAXDIR];
- char *home= BLI_gethome();
int from_memory= op?RNA_boolean_get(op->ptr, "factory"):0;
int success;
-
- BLI_clean(home);
free_ttfont(); /* still weird... what does it here? */
G.relbase_valid = 0;
if (!from_memory) {
- BLI_make_file_string(G.sce, tstr, home, ".B25.blend");
+ BLI_make_file_string(G.sce, tstr, BLI_get_folder(BLENDER_USER_CONFIG, NULL), BLENDER_STARTUP_FILE);
}
strcpy(scestr, G.sce); /* temporary store */
@@ -388,7 +385,7 @@
char *line;
int num;
- BLI_make_file_string("/", name, BLI_gethome(), ".Blog");
+ BLI_make_file_string("/", name, BLI_get_folder(BLENDER_CONFIG, NULL), BLENDER_HISTORY_FILE);
lines= BLI_read_file_as_lines(name);
G.recent_files.first = G.recent_files.last = NULL;
@@ -424,7 +421,7 @@
FILE *fp;
int i;
- BLI_make_file_string("/", name, BLI_gethome(), ".Blog");
+ BLI_make_file_string("/", name, BLI_get_folder_create(BLENDER_USER_CONFIG, NULL), BLENDER_HISTORY_FILE);
recent = G.recent_files.first;
/* refresh .Blog of recent opened files, when current file was changed */
@@ -566,7 +563,8 @@
if(win->screen->full == SCREENTEMP)
wm_window_close(C, wm, win);
- BLI_make_file_string("/", tstr, BLI_gethome(), ".B25.blend");
+ BLI_make_file_string("/", tstr, BLI_get_folder_create(BLENDER_USER_CONFIG, NULL), BLENDER_STARTUP_FILE);
+ printf("trying to save homefile at %s \n", tstr);
/* force save as regular blend file */
fileflags = G.fileflags & ~(G_FILE_COMPRESS | G_FILE_AUTOPLAY | G_FILE_LOCK | G_FILE_SIGN);
Index: source/blender/blenloader/intern/writefile.c
===================================================================
--- source/blender/blenloader/intern/writefile.c (revision 28755)
+++ source/blender/blenloader/intern/writefile.c (working copy)
@@ -2490,7 +2490,7 @@
makeFilesAbsolute(G.sce, NULL);
}
- BLI_make_file_string(G.sce, userfilename, BLI_gethome(), ".B25.blend");
+ BLI_make_file_string(G.sce, userfilename, BLI_get_folder_create(BLENDER_USER_CONFIG, NULL), BLENDER_STARTUP_FILE);
write_user_block= BLI_streq(dir, userfilename);
if(write_flags & G_FILE_RELATIVE_REMAP)
Index: source/blender/blenlib/BLI_path_util.h
===================================================================
--- source/blender/blenlib/BLI_path_util.h (revision 28755)
+++ source/blender/blenlib/BLI_path_util.h (working copy)
@@ -45,6 +45,38 @@
#define BLI_GETHOME_USER 1<<3 /* home folder ~/.blender */
#define BLI_GETHOME_ALL (BLI_GETHOME_SYSTEM|BLI_GETHOME_LOCAL|BLI_GETHOME_USER)
+char *BLI_get_folder(int folder_id, char *subfolder);
+char *BLI_get_folder_create(int folder_id, char *subfolder);
+
+/* folder_id */
+
+/* general, will find baserd on user/local/system priority */
+#define BLENDER_CONFIG 1
+#define BLENDER_DATAFILES 2
+#define BLENDER_SCRIPTS 3
+#define BLENDER_PLUGINS 4
+
+/* user-specific */
+#define BLENDER_USER_CONFIG 11
+#define BLENDER_USER_DATAFILES 12
+#define BLENDER_USER_SCRIPTS 13
+#define BLENDER_USER_PLUGINS 14
+
+/* system */
+#define BLENDER_SYSTEM_CONFIG 21 /* optional */
+#define BLENDER_SYSTEM_DATAFILES 22
+#define BLENDER_SYSTEM_SCRIPTS 23
+#define BLENDER_SYSTEM_PLUGINS 24
+
+#define BLENDER_TEMP 50
+
+#define BLENDER_USERFOLDER(id) (id >= BLENDER_USER_CONFIG && id <= BLENDER_USER_PLUGINS)
+
+#define BLENDER_STARTUP_FILE "startup.blend"
+#define BLENDER_BOOKMARK_FILE "bookmarks.txt"
+#define BLENDER_HISTORY_FILE "recent-files.txt"
+
+
void BLI_setenv(const char *env, const char *val);
void BLI_setenv_if_new(const char *env, const char* val);
Index: source/blender/blenlib/intern/path_util.c
===================================================================
--- source/blender/blenlib/intern/path_util.c (revision 28755)
+++ source/blender/blenlib/intern/path_util.c (working copy)
@@ -44,6 +44,7 @@
#include "BLI_storage_types.h"
#include "BKE_utildefines.h"
+#include "BKE_blender.h" // BLENDER_VERSION
@@ -795,7 +796,7 @@
/* this function returns the path to a blender folder, if it exists
* utility functions for BLI_gethome_folder */
-/* #define PATH_DEBUG */ /* for testing paths that are checked */
+// #define PATH_DEBUG /* for testing paths that are checked */
static int test_data_path(char *targetpath, char *path_base, char *path_sep, char *folder_name)
{
@@ -905,6 +906,237 @@
return NULL;
}
+
+/* NEW stuff, to be cleaned up when fully migrated */
+/* ************************************************************* */
+/* ************************************************************* */
+
+#define PATH_DEBUG2
+
+static char *blender_version_decimal(void)
+{
+ static char version_str[5];
+ sprintf(version_str, "%d.%02d", BLENDER_VERSION/100, BLENDER_VERSION%100);
+ return version_str;
+}
+
+static int test_path(char *targetpath, char *path_base, char *path_sep, char *folder_name)
+{
+ char tmppath[FILE_MAXDIR];
+
+ if(path_sep) BLI_join_dirfile(tmppath, path_base, path_sep);
+ else BLI_strncpy(tmppath, path_base, sizeof(tmppath));
+
+ BLI_make_file_string("/", targetpath, tmppath, folder_name);
+
+ if (BLI_exists(targetpath)) {
+#ifdef PATH_DEBUG2
+ printf("\tpath found: %s\n", targetpath);
+#endif
+ return 1;
+ }
+ else {
+#ifdef PATH_DEBUG2
+ printf("\tpath missing: %s\n", targetpath);
+#endif
+ //targetpath[0] = '\0';
+ return 0;
+ }
+}
+
+static int get_path_local(char *targetpath, char *folder_name)
+{
+ extern char bprogname[]; /* argv[0] from creator.c */
+ char bprogdir[FILE_MAXDIR];
+ char cwd[FILE_MAXDIR];
+ char *s;
+ int i;
+
+#ifdef PATH_DEBUG2
+ printf("get_path_local...\n");
+#endif
+
+ /* try release/folder_name (binary relative) */
+ /* use argv[0] (bprogname) to get the path to the executable */
+ s = BLI_last_slash(bprogname);
+ i = s - bprogname + 1;
+ BLI_strncpy(bprogdir, bprogname, i);
+
+ /* try release/folder_name (CWD relative) */
+ if(test_path(targetpath, BLI_getwdN(cwd), "release", folder_name))
+ return 1;
+
+ if(test_path(targetpath, bprogdir, "release", folder_name))
+ return 1;
+
+ /* try ./.blender/folder_name */
+ if(test_path(targetpath, bprogdir, ".blender", folder_name))
+ return 1;
+
+ return 0;
+}
+
+static int get_path_user(char *targetpath, char *folder_name)
+{
+ char user_path[FILE_MAXDIR];
+
+#if defined(__APPLE__)
+ /* XXX example below - replace with OS API */
+ BLI_strncpy(user_path, BLI_gethome(), FILE_MAXDIR);
+ strcat(user_path, "/Library/Application Support/Blender");
+
+#elif defined(WIN32)
+ /* XXX example below - replace with OS API */
+ BLI_strncpy(user_path, BLI_gethome(), FILE_MAXDIR);
+ strcat(user_path, "\Application Data\Blender");
+
+#else /* UNIX */
+ /* XXX example below - replace with OS API */
+ BLI_strncpy(user_path, BLI_gethome(), FILE_MAXDIR);
+ strcat(user_path, "/.blender");
+#endif
+
+ if(!user_path[0])
+ return 0;
+
+ BLI_add_slash(user_path);
+ strcat(user_path, blender_version_decimal());
+ BLI_add_slash(user_path);
+
+
+#ifdef PATH_DEBUG2
+ printf("get_path_user: %s\n", user_path);
+#endif
+
+ /* try $HOME/folder_name */
+ return test_path(targetpath, user_path, NULL, folder_name);
+}
+
+static int get_path_system(char *targetpath, char *folder_name)
+{
+ char *system_path;
+
+#if defined(__APPLE__)
+ /* XXX example below - replace with OS API */
+ system_path = BLI_getbundle();
+
+#elif defined(WIN32)
+ /* XXX example below - replace with OS API */
+ system_path = BLI_getInstallationDir();
+
+#else /* UNIX */
+ /* XXX example below - replace with OS API */
+ char usr_share[FILE_MAXDIR]="/usr/share/blender/";
+ system_path = &usr_share;
+#endif
+
+ if(!system_path[0])
+ return 0;
+
+ BLI_add_slash(system_path);
+ strcat(system_path, blender_version_decimal());
+ BLI_add_slash(system_path);
+
+
+#ifdef PATH_DEBUG2
+ printf("get_path_system: %s\n", system_path);
+#endif
+
+ /* try $BLENDERPATH/folder_name */
+ return test_path(targetpath, system_path, NULL, folder_name);
+}
+
+static int test_env_path(char *path, char *envvar)
+{
+ char *env = getenv(envvar);
+ if (!env) return 0;
+
+ if (BLI_exists(env)) {
+ BLI_strncpy(path, env, FILE_MAXDIR);
+ return 1;
+ } else {
+ path[0] = '\0';
+ return 0;
+ }
+}
+
+/* get a folder out of the 'folder_id' presets for paths */
+/* returns the path if found, NULL string if not */
+char *BLI_get_folder(int folder_id, char *subfolder)
+{
+ static char path[FILE_MAXDIR] = "";
+
+ switch (folder_id) {
+ case BLENDER_DATAFILES: /* general case */
+ if (test_env_path(path, "BLENDER_USER_DATAFILES")) break;
+ if (get_path_user(path, "datafiles")) break;
+
+ if (get_path_local(path, "datafiles")) break;
+
+ if (test_env_path(path, "BLENDER_SYSTEM_DATAFILES")) break;
+ if (get_path_system(path, "datafiles")) break;
+
+ return NULL;
+ case BLENDER_USER_DATAFILES:
+ if (test_env_path(path, "BLENDER_USER_DATAFILES")) break;
+ if (get_path_user(path, "datafiles")) break;
+
+ return NULL;
+ case BLENDER_SYSTEM_DATAFILES:
+ if (test_env_path(path, "BLENDER_SYSTEM_DATAFILES")) break;
+ if (get_path_system(path, "datafiles")) break;
+
+ return NULL;
+ case BLENDER_CONFIG: /* general case */
+ if (test_env_path(path, "BLENDER_USER_CONFIG")) break;
+ if (get_path_user(path, "config")) break;
+
+ if (get_path_local(path, "config")) break;
+
+ if (test_env_path(path, "BLENDER_SYSTEM_CONFIG")) break;
+ if (get_path_system(path, "config")) break;
+
+ return NULL;
+ case BLENDER_USER_CONFIG:
+ if (test_env_path(path, "BLENDER_USER_CONFIG")) break;
+ if (get_path_user(path, "config")) break;
+
+ return NULL;
+ case BLENDER_SYSTEM_CONFIG:
+ if (test_env_path(path, "BLENDER_SYSTEM_CONFIG")) break;
+ if (get_path_system(path, "config")) break;
+
+ return NULL;
+ }
+
+ return path;
+}
+
+char *BLI_get_folder_create(int folder_id, char *subfolder)
+{
+ static char fulldir[FILE_MAXDIR] = "";
+ char *path;
+ int exists;
+
+ /* only for user folders */
+ if (!ELEM(folder_id, BLENDER_USER_DATAFILES, BLENDER_USER_CONFIG))
+ return NULL;
+
+ path = BLI_get_folder(folder_id, subfolder);
+
+ if (path[0])
+ BLI_recurdir_fileops(path);
+
+ return path;
+}
+
+
+/* End new stuff */
+/* ************************************************************* */
+/* ************************************************************* */
+
+
+
#ifdef PATH_DEBUG
#undef PATH_DEBUG
#endif
Index: source/blender/editors/space_file/file_ops.c
===================================================================
--- source/blender/editors/space_file/file_ops.c (revision 28755)
+++ source/blender/editors/space_file/file_ops.c (working copy)
@@ -391,7 +391,7 @@
char name[FILE_MAX];
fsmenu_insert_entry(fsmenu, FS_CATEGORY_BOOKMARKS, params->dir, 0, 1);
- BLI_make_file_string("/", name, BLI_gethome(), ".Bfs");
+ BLI_make_file_string("/", name, BLI_get_folder_create(BLENDER_USER_CONFIG, NULL), BLENDER_BOOKMARK_FILE);
fsmenu_write_file(fsmenu, name);
}
@@ -423,7 +423,7 @@
char name[FILE_MAX];
fsmenu_remove_entry(fsmenu, FS_CATEGORY_BOOKMARKS, index);
- BLI_make_file_string("/", name, BLI_gethome(), ".Bfs");
+ BLI_make_file_string("/", name, BLI_get_folder_create(BLENDER_USER_CONFIG, NULL), BLENDER_BOOKMARK_FILE);
fsmenu_write_file(fsmenu, name);
ED_area_tag_redraw(sa);
}
@@ -612,7 +612,7 @@
folderlist_free(sfile->folders_next);
fsmenu_insert_entry(fsmenu_get(), FS_CATEGORY_RECENT, sfile->params->dir,0, 1);
- BLI_make_file_string(G.sce, name, BLI_gethome(), ".Bfs");
+ BLI_make_file_string(G.sce, name, BLI_get_folder_create(BLENDER_USER_CONFIG, NULL), BLENDER_BOOKMARK_FILE);
fsmenu_write_file(fsmenu_get(), name);
WM_event_fileselect_event(C, op, EVT_FILESELECT_EXEC);
Index: source/blender/editors/space_file/space_file.c
===================================================================
--- source/blender/editors/space_file/space_file.c (revision 28755)
+++ source/blender/editors/space_file/space_file.c (working copy)
@@ -581,7 +581,7 @@
void ED_file_init(void)
{
char name[FILE_MAX];
- BLI_make_file_string("/", name, BLI_gethome(), ".Bfs");
+ BLI_make_file_string("/", name, BLI_get_folder(BLENDER_CONFIG, NULL), BLENDER_BOOKMARK_FILE);
fsmenu_read_file(fsmenu_get(), name);
filelist_init_icons();
IMB_thumb_makedirs();
Index: source/blender/editors/interface/interface_icons.c
===================================================================
--- source/blender/editors/interface/interface_icons.c (revision 28755)
+++ source/blender/editors/interface/interface_icons.c (working copy)
@@ -460,15 +460,8 @@
char filenamestr[FILE_MAXFILE+16]; // 16 == strlen(".blender/icons/")+1
if ((btheme!=NULL) && (strlen(btheme->tui.iconfile) > 0)) {
-
-#ifdef WIN32
- sprintf(filenamestr, "icons/%s", btheme->tui.iconfile);
-#else
- sprintf(filenamestr, ".blender/icons/%s", btheme->tui.iconfile);
-#endif
+ BLI_make_file_string("/", iconfilestr, BLI_get_folder(BLENDER_DATAFILES, NULL), btheme->tui.iconfile);
- BLI_make_file_string("/", iconfilestr, BLI_gethome(), filenamestr);
-
if (BLI_exists(iconfilestr)) {
bbuf = IMB_loadiffname(iconfilestr, IB_rect);
if(bbuf->x < ICON_IMAGE_W || bbuf->y < ICON_IMAGE_H) {
@@ -558,11 +551,7 @@
list->first = list->last = NULL;
-#ifdef WIN32
- BLI_make_file_string("/", icondirstr, BLI_gethome(), "icons");
-#else
- BLI_make_file_string("/", icondirstr, BLI_gethome(), ".blender/icons");
-#endif
+ BLI_make_file_string("/", icondirstr, BLI_get_folder(BLENDER_DATAFILES, NULL), "");
if(BLI_exists(icondirstr)==0)
return;

File Metadata

Mime Type
text/x-diff
Storage Engine
local-disk
Storage Format
Raw Data
Storage Handle
3e/ee/cdaded74cfc0e15d07273f530e88

Event Timeline