Commit: ffb0fc35a92693b9d7d4e3ce54790982aedf5851
Author: Bastien Montagne
Date:   Mon Dec 8 13:59:32 2014 +0100
Branches: asset-experiments
https://developer.blender.org/rBffb0fc35a92693b9d7d4e3ce54790982aedf5851

Get rid of BLO_is_a_library.

===================================================================

M       source/blender/blenloader/BLO_readfile.h
M       source/blender/blenloader/intern/readfile.c
M       source/blender/editors/space_file/file_ops.c
M       source/blender/editors/space_file/filelist.c

===================================================================

diff --git a/source/blender/blenloader/BLO_readfile.h 
b/source/blender/blenloader/BLO_readfile.h
index 11f4379..cb0e90b 100644
--- a/source/blender/blenloader/BLO_readfile.h
+++ b/source/blender/blenloader/BLO_readfile.h
@@ -207,12 +207,6 @@ bool BLO_has_bfile_extension(const char *str);
  */
 bool BLO_library_path_explode(const char *path, char *r_dir, char *r_group, 
char *r_name);
 
-/**
- * return ok when a blenderfile, in dir is the filename,
- * in group the type of libdata
- */
-bool BLO_is_a_library(const char *path, char *dir, char *group);
-
 
 /**
  * Initialize the BlendHandle for appending or linking library data.
diff --git a/source/blender/blenloader/intern/readfile.c 
b/source/blender/blenloader/intern/readfile.c
index e7a6a6a..9072fed 100644
--- a/source/blender/blenloader/intern/readfile.c
+++ b/source/blender/blenloader/intern/readfile.c
@@ -1152,7 +1152,7 @@ bool BLO_library_path_explode(const char *path, char 
*r_dir, char *r_group, char
         * then we now next path item is group, and everything else is data 
name. */
        char *slash, *prev_slash = NULL;
 
-       strcpy(r_dir, path);
+       r_dir[0] = '\0';
        if (r_group) {
                r_group[0] = '\0';
        }
@@ -1160,6 +1160,13 @@ bool BLO_library_path_explode(const char *path, char 
*r_dir, char *r_group, char
                r_name[0] = '\0';
        }
 
+       /* if path leads to an existing directory or file, we can be sure we're 
not in a library */
+       if (BLI_is_dir(path) || BLI_is_file(path)) {
+               return false;
+       }
+
+       strcpy(r_dir, path);
+
        while ((slash = (char *)BLI_last_slash(r_dir))) {
                *slash = '\0';
                if (BLO_has_bfile_extension(r_dir)) {
@@ -1167,7 +1174,7 @@ bool BLO_library_path_explode(const char *path, char 
*r_dir, char *r_group, char
                }
 
                if (prev_slash) {
-                       *prev_slash = '/';
+                       *prev_slash = SEP;
                }
                prev_slash = slash;
        }
@@ -1193,49 +1200,6 @@ bool BLO_library_path_explode(const char *path, char 
*r_dir, char *r_group, char
        return true;
 }
 
-bool BLO_is_a_library(const char *path, char *dir, char *group)
-{
-       /* return ok when a blenderfile, in dir is the filename,
-        * in group the type of libdata
-        */
-       int len;
-       char *fd;
-       
-       /* if path leads to a directory we can be sure we're not in a library */
-       if (BLI_is_dir(path)) return 0;
-
-       strcpy(dir, path);
-       len = strlen(dir);
-       if (len < 7) return 0;
-       if ((dir[len - 1] != '/') && (dir[len - 1] != '\\')) return 0;
-       
-       group[0] = '\0';
-       dir[len - 1] = '\0';
-
-       /* Find the last slash */
-       fd = (char *)BLI_last_slash(dir);
-
-       if (fd == NULL) return 0;
-       *fd = 0;
-       if (BLO_has_bfile_extension(fd+1)) {
-               /* the last part of the dir is a .blend file, no group follows 
*/
-               *fd = '/'; /* put back the removed slash separating the dir and 
the .blend file name */
-       }
-       else {
-               const char * const gp = fd + 1; // in case we have a .blend 
file, gp points to the group
-               
-               /* Find the last slash */
-               fd = (char *)BLI_last_slash(dir);
-               if (!fd || !BLO_has_bfile_extension(fd+1)) return 0;
-               
-               /* now we know that we are in a blend file and it is safe to 
-                * assume that gp actually points to a group */
-               if (strcmp("Screen", gp) != 0)
-                       BLI_strncpy(group, gp, BLO_GROUP_MAX);
-       }
-       return 1;
-}
-
 /* ************** OLD POINTERS ******************* */
 
 static void *newdataadr(FileData *fd, void *adr)               /* only direct 
databocks */
diff --git a/source/blender/editors/space_file/file_ops.c 
b/source/blender/editors/space_file/file_ops.c
index 577a0c0..02cd76b 100644
--- a/source/blender/editors/space_file/file_ops.c
+++ b/source/blender/editors/space_file/file_ops.c
@@ -869,7 +869,7 @@ int file_parent_exec(bContext *C, wmOperator 
*UNUSED(unused))
                        /* if not browsing in .blend file, we still want to 
check whether the path is a directory */
                        if (sfile->params->type == FILE_LOADLIB) {
                                char tdir[FILE_MAX], tgroup[FILE_MAX];
-                               if (BLO_is_a_library(sfile->params->dir, tdir, 
tgroup)) {
+                               if 
(BLO_library_path_explode(sfile->params->dir, tdir, NULL, NULL)) {
                                        file_change_dir(C, 0);
                                }
                                else {
@@ -1350,7 +1350,7 @@ void file_filename_enter_handle(bContext *C, void 
*UNUSED(arg_unused), void *arg
                        else if (sfile->params->type == FILE_LOADLIB) {
                                char tdir[FILE_MAX], tgroup[FILE_MAX];
                                BLI_add_slash(filepath);
-                               if (BLO_is_a_library(filepath, tdir, tgroup)) {
+                               if (BLO_library_path_explode(filepath, tdir, 
NULL, NULL)) {
                                        BLI_cleanup_dir(G.main->name, filepath);
                                        BLI_strncpy(sfile->params->dir, 
filepath, sizeof(sfile->params->dir));
                                        sfile->params->file[0] = '\0';
diff --git a/source/blender/editors/space_file/filelist.c 
b/source/blender/editors/space_file/filelist.c
index e736dd6..5397a46 100644
--- a/source/blender/editors/space_file/filelist.c
+++ b/source/blender/editors/space_file/filelist.c
@@ -1375,7 +1375,7 @@ void filelist_sort(struct FileList *filelist, short sort)
 
 bool filelist_islibrary(struct FileList *filelist, char *dir, char *group)
 {
-       return BLO_is_a_library(filelist->dir, dir, group);
+       return BLO_library_path_explode(filelist->dir, dir, group, NULL);
 }
 
 static int groupname_to_code(const char *group)

_______________________________________________
Bf-blender-cvs mailing list
[email protected]
http://lists.blender.org/mailman/listinfo/bf-blender-cvs

Reply via email to