Code Cleanup: style and redundant casts
[blender.git] / source / blender / editors / space_file / filelist.c
index 699cb9b4feb7cd98e91f194dfebe27b7b1bd4360..748a0bd884c743535ab58ce68a7420455312657e 100644 (file)
@@ -48,6 +48,7 @@
 #include "BLI_linklist.h"
 #include "BLI_threads.h"
 #include "BLI_utildefines.h"
+#include "BLI_fileops_types.h"
 
 #ifdef WIN32
 #  include "BLI_winstuff.h"
@@ -143,24 +144,35 @@ typedef struct FolderList {
 #define SPECIAL_IMG_FONTFILE 8
 #define SPECIAL_IMG_UNKNOWNFILE 9
 #define SPECIAL_IMG_LOADING 10
-#define SPECIAL_IMG_MAX SPECIAL_IMG_LOADING + 1
+#define SPECIAL_IMG_BACKUP 11
+#define SPECIAL_IMG_MAX SPECIAL_IMG_BACKUP + 1
 
 static ImBuf *gSpecialFileImages[SPECIAL_IMG_MAX];
 
 
 /* ******************* SORT ******************* */
 
+static bool compare_is_directory(const struct direntry *entry)
+{
+       /* for library browse .blend files may be treated as directories, but
+        * for sorting purposes they should be considered regular files */
+       if (S_ISDIR(entry->type))
+               return !(entry->flags & (BLENDERFILE | BLENDERFILE_BACKUP));
+       
+       return false;
+}
+
 static int compare_name(const void *a1, const void *a2)
 {
        const struct direntry *entry1 = a1, *entry2 = a2;
 
        /* type is equal to stat.st_mode */
 
-       if (S_ISDIR(entry1->type)) {
-               if (S_ISDIR(entry2->type) == 0) return (-1);
+       if (compare_is_directory(entry1)) {
+               if (compare_is_directory(entry2) == 0) return (-1);
        }
        else {
-               if (S_ISDIR(entry2->type)) return (1);
+               if (compare_is_directory(entry2)) return (1);
        }
        if (S_ISREG(entry1->type)) {
                if (S_ISREG(entry2->type) == 0) return (-1);
@@ -186,11 +198,11 @@ static int compare_date(const void *a1, const void *a2)
        
        /* type is equal to stat.st_mode */
 
-       if (S_ISDIR(entry1->type)) {
-               if (S_ISDIR(entry2->type) == 0) return (-1);
+       if (compare_is_directory(entry1)) {
+               if (compare_is_directory(entry2) == 0) return (-1);
        }
        else {
-               if (S_ISDIR(entry2->type)) return (1);
+               if (compare_is_directory(entry2)) return (1);
        }
        if (S_ISREG(entry1->type)) {
                if (S_ISREG(entry2->type) == 0) return (-1);
@@ -219,11 +231,11 @@ static int compare_size(const void *a1, const void *a2)
 
        /* type is equal to stat.st_mode */
 
-       if (S_ISDIR(entry1->type)) {
-               if (S_ISDIR(entry2->type) == 0) return (-1);
+       if (compare_is_directory(entry1)) {
+               if (compare_is_directory(entry2) == 0) return (-1);
        }
        else {
-               if (S_ISDIR(entry2->type)) return (1);
+               if (compare_is_directory(entry2)) return (1);
        }
        if (S_ISREG(entry1->type)) {
                if (S_ISREG(entry2->type) == 0) return (-1);
@@ -260,11 +272,11 @@ static int compare_extension(const void *a1, const void *a2)
 
        /* type is equal to stat.st_mode */
 
-       if (S_ISDIR(entry1->type)) {
-               if (S_ISDIR(entry2->type) == 0) return (-1);
+       if (compare_is_directory(entry1)) {
+               if (compare_is_directory(entry2) == 0) return (-1);
        }
        else {
-               if (S_ISDIR(entry2->type)) return (1);
+               if (compare_is_directory(entry2)) return (1);
        }
        if (S_ISREG(entry1->type)) {
                if (S_ISREG(entry2->type) == 0) return (-1);
@@ -292,18 +304,18 @@ static int is_hidden_file(const char *filename, short hide_dot)
                if (filename[0] == '.' && filename[1] != '.' && filename[1] != 0) {
                        is_hidden = 1; /* ignore .file */
                }
-               else if (((filename[0] == '.') && (filename[1] == 0) )) {
+               else if (((filename[0] == '.') && (filename[1] == 0))) {
                        is_hidden = 1; /* ignore . */
                }
                else {
                        int len = strlen(filename);
-                       if ( (len > 0) && (filename[len - 1] == '~') ) {
+                       if ((len > 0) && (filename[len - 1] == '~')) {
                                is_hidden = 1;  /* ignore file~ */
                        }
-               } 
+               }
        }
        else {
-               if (((filename[0] == '.') && (filename[1] == 0) )) {
+               if (((filename[0] == '.') && (filename[1] == 0))) {
                        is_hidden = 1; /* ignore . */
                }
        }
@@ -358,9 +370,9 @@ void filelist_filter(FileList *filelist)
        /* How many files are left after filter ? */
        for (i = 0; i < filelist->numfiles; ++i) {
                struct direntry *file = &filelist->filelist[i];
-               if (filelist->filterf(file, filelist->dir, filelist->filter, filelist->hide_dot) ) {
+               if (filelist->filterf(file, filelist->dir, filelist->filter, filelist->hide_dot)) {
                        num_filtered++;
-               } 
+               }
        }
        
        if (filelist->fidx) {
@@ -372,7 +384,7 @@ void filelist_filter(FileList *filelist)
 
        for (i = 0, j = 0; i < filelist->numfiles; ++i) {
                struct direntry *file = &filelist->filelist[i];
-               if (filelist->filterf(file, filelist->dir, filelist->filter, filelist->hide_dot) ) {
+               if (filelist->filterf(file, filelist->dir, filelist->filter, filelist->hide_dot)) {
                        filelist->fidx[j++] = i;
                }
        }
@@ -420,7 +432,7 @@ void filelist_free_icons(void)
        }
 }
 
-//-----------------FOLDERLIST (previous/next) --------------//
+/* -----------------FOLDERLIST (previous/next) -------------- */
 ListBase *folderlist_new(void)
 {
        ListBase *p = MEM_callocN(sizeof(ListBase), "folderlist");
@@ -461,15 +473,23 @@ void folderlist_pushdir(ListBase *folderlist, const char *dir)
 
        /* create next folder element */
        folder = (FolderList *)MEM_mallocN(sizeof(FolderList), "FolderList");
-       folder->foldername = (char *)MEM_mallocN(sizeof(char) * (strlen(dir) + 1), "foldername");
-       folder->foldername[0] = '\0';
-
-       BLI_strncpy(folder->foldername, dir, FILE_MAXDIR);
+       folder->foldername = BLI_strdup(dir);
 
        /* add it to the end of the list */
        BLI_addtail(folderlist, folder);
 }
 
+const char *folderlist_peeklastdir(ListBase *folderlist)
+{
+       struct FolderList *folder;
+
+       if (!folderlist->last)
+               return NULL;
+
+       folder = folderlist->last;
+       return folder->foldername;
+}
+
 int folderlist_clear_next(struct SpaceFile *sfile)
 {
        struct FolderList *folder;
@@ -520,7 +540,7 @@ static void filelist_read_main(struct FileList *filelist);
 static void filelist_read_library(struct FileList *filelist);
 static void filelist_read_dir(struct FileList *filelist);
 
-//------------------FILELIST------------------------//
+/* ------------------FILELIST------------------------ */
 FileList *filelist_new(short type)
 {
        FileList *p = MEM_callocN(sizeof(FileList), "filelist");
@@ -536,6 +556,7 @@ FileList *filelist_new(short type)
                default:
                        p->readf = filelist_read_dir;
                        p->filterf = is_filtered_file;
+                       break;
 
        }
        return p;
@@ -544,8 +565,6 @@ FileList *filelist_new(short type)
 
 void filelist_free(struct FileList *filelist)
 {
-       int i;
-
        if (!filelist) {
                printf("Attempting to delete empty filelist.\n");
                return;
@@ -556,24 +575,9 @@ void filelist_free(struct FileList *filelist)
                filelist->fidx = NULL;
        }
 
-       for (i = 0; i < filelist->numfiles; ++i) {
-               if (filelist->filelist[i].image) {                      
-                       IMB_freeImBuf(filelist->filelist[i].image);
-               }
-               filelist->filelist[i].image = NULL;
-               if (filelist->filelist[i].relname)
-                       MEM_freeN(filelist->filelist[i].relname);
-               if (filelist->filelist[i].path)
-                       MEM_freeN(filelist->filelist[i].path);
-               filelist->filelist[i].relname = NULL;
-               if (filelist->filelist[i].string)
-                       MEM_freeN(filelist->filelist[i].string);
-               filelist->filelist[i].string = NULL;
-       }
-       
+       BLI_free_filelist(filelist->filelist, filelist->numfiles);
        filelist->numfiles = 0;
-       free(filelist->filelist);
-       filelist->filelist = NULL;      
+       filelist->filelist = NULL;
        filelist->filter = 0;
        filelist->filter_glob[0] = '\0';
        filelist->numfiltered = 0;
@@ -625,7 +629,7 @@ ImBuf *filelist_getimage(struct FileList *filelist, int index)
 
        BLI_assert(G.background == FALSE);
 
-       if ( (index < 0) || (index >= filelist->numfiltered) ) {
+       if ((index < 0) || (index >= filelist->numfiltered)) {
                return NULL;
        }
        fidx = filelist->fidx[index];
@@ -642,7 +646,7 @@ ImBuf *filelist_geticon(struct FileList *filelist, int index)
 
        BLI_assert(G.background == FALSE);
 
-       if ( (index < 0) || (index >= filelist->numfiltered) ) {
+       if ((index < 0) || (index >= filelist->numfiltered)) {
                return NULL;
        }
        fidx = filelist->fidx[index];
@@ -665,7 +669,7 @@ ImBuf *filelist_geticon(struct FileList *filelist, int index)
        if (file->flags & BLENDERFILE) {
                ibuf = gSpecialFileImages[SPECIAL_IMG_BLENDFILE];
        }
-       else if ( (file->flags & MOVIEFILE) || (file->flags & MOVIEFILE_ICON) ) {
+       else if ((file->flags & MOVIEFILE) || (file->flags & MOVIEFILE_ICON)) {
                ibuf = gSpecialFileImages[SPECIAL_IMG_MOVIEFILE];
        }
        else if (file->flags & SOUNDFILE) {
@@ -683,6 +687,9 @@ ImBuf *filelist_geticon(struct FileList *filelist, int index)
        else if (file->flags & IMAGEFILE) {
                ibuf = gSpecialFileImages[SPECIAL_IMG_LOADING];
        }
+       else if (file->flags & BLENDERFILE_BACKUP) {
+               ibuf = gSpecialFileImages[SPECIAL_IMG_BACKUP];
+       }
 
        return ibuf;
 }
@@ -691,7 +698,7 @@ struct direntry *filelist_file(struct FileList *filelist, int index)
 {
        int fidx = 0;
        
-       if ( (index < 0) || (index >= filelist->numfiltered) ) {
+       if ((index < 0) || (index >= filelist->numfiltered)) {
                return NULL;
        }
        fidx = filelist->fidx[index];
@@ -740,6 +747,7 @@ void filelist_setfilter_types(struct FileList *filelist, const char *filter_glob
        BLI_strncpy(filelist->filter_glob, filter_glob, sizeof(filelist->filter_glob));
 }
 
+/* would recognize .blend as well */
 static int file_is_blend_backup(const char *str)
 {
        short a, b;
@@ -748,7 +756,9 @@ static int file_is_blend_backup(const char *str)
        a = strlen(str);
        b = 7;
        
-       if (a == 0 || b >= a) ;
+       if (a == 0 || b >= a) {
+               /* pass */
+       }
        else {
                char *loc;
                
@@ -765,58 +775,78 @@ static int file_is_blend_backup(const char *str)
        return (retval);
 }
 
-
-static int file_extension_type(const char *relname)
+static int path_extension_type(const char *path)
 {
-       if (BLO_has_bfile_extension(relname)) {
+       if (BLO_has_bfile_extension(path)) {
                return BLENDERFILE;
        }
-       else if (file_is_blend_backup(relname)) {
+       else if (file_is_blend_backup(path)) {
                return BLENDERFILE_BACKUP;
        }
-       else if (BLI_testextensie(relname, ".py")) {
+       else if (BLI_testextensie(path, ".app")) {
+               return APPLICATIONBUNDLE;
+       }
+       else if (BLI_testextensie(path, ".py")) {
                return PYSCRIPTFILE;
        }
-       else if (BLI_testextensie(relname, ".txt")  ||
-                BLI_testextensie(relname, ".glsl") ||
-                BLI_testextensie(relname, ".data"))
+       else if (BLI_testextensie(path, ".txt")  ||
+                BLI_testextensie(path, ".glsl") ||
+                BLI_testextensie(path, ".osl")  ||
+                BLI_testextensie(path, ".data"))
        {
                return TEXTFILE;
        }
-       else if (BLI_testextensie(relname, ".ttf") ||
-                BLI_testextensie(relname, ".ttc") ||
-                BLI_testextensie(relname, ".pfb") ||
-                BLI_testextensie(relname, ".otf") ||
-                BLI_testextensie(relname, ".otc"))
+       else if (BLI_testextensie(path, ".ttf") ||
+                BLI_testextensie(path, ".ttc") ||
+                BLI_testextensie(path, ".pfb") ||
+                BLI_testextensie(path, ".otf") ||
+                BLI_testextensie(path, ".otc"))
        {
-               return FTFONTFILE;                      
+               return FTFONTFILE;
        }
-       else if (BLI_testextensie(relname, ".btx")) {
+       else if (BLI_testextensie(path, ".btx")) {
                return BTXFILE;
        }
-       else if (BLI_testextensie(relname, ".dae")) {
+       else if (BLI_testextensie(path, ".dae")) {
                return COLLADAFILE;
        }
-       else if (BLI_testextensie_array(relname, imb_ext_image) ||
-                (G.have_quicktime && BLI_testextensie_array(relname, imb_ext_image_qt)))
+       else if (BLI_testextensie_array(path, imb_ext_image) ||
+                (G.have_quicktime && BLI_testextensie_array(path, imb_ext_image_qt)))
        {
-               return IMAGEFILE;                       
+               return IMAGEFILE;
        }
-       else if (BLI_testextensie_array(relname, imb_ext_movie)) {
-               return MOVIEFILE;                       
+       else if (BLI_testextensie(path, ".ogg")) {
+               if (IMB_isanim(path)) {
+                       return MOVIEFILE;
+               }
+               else {
+                       return SOUNDFILE;
+               }
+       }
+       else if (BLI_testextensie_array(path, imb_ext_movie)) {
+               return MOVIEFILE;
        }
-       else if (BLI_testextensie_array(relname, imb_ext_audio)) {
+       else if (BLI_testextensie_array(path, imb_ext_audio)) {
                return SOUNDFILE;
-       } 
+       }
        return 0;
 }
 
-int ED_file_extension_icon(const char *relname)
+static int file_extension_type(const char *dir, const char *relname)
+{
+       char path[FILE_MAX];
+       BLI_join_dirfile(path, sizeof(path), dir, relname);
+       return path_extension_type(path);
+}
+
+int ED_file_extension_icon(const char *path)
 {
-       int type = file_extension_type(relname);
+       int type = path_extension_type(path);
        
-       if (type == BLENDERFILE || type == BLENDERFILE_BACKUP)
+       if (type == BLENDERFILE)
                return ICON_FILE_BLEND;
+       else if (type == BLENDERFILE_BACKUP)
+               return ICON_FILE_BACKUP;
        else if (type == IMAGEFILE)
                return ICON_FILE_IMAGE;
        else if (type == MOVIEFILE)
@@ -831,6 +861,8 @@ int ED_file_extension_icon(const char *relname)
                return ICON_FILE_BLANK;
        else if (type == COLLADAFILE)
                return ICON_FILE_BLANK;
+       else if (type == TEXTFILE)
+               return ICON_FILE_TEXT;
        
        return ICON_FILE_BLANK;
 }
@@ -844,14 +876,15 @@ static void filelist_setfiletypes(struct FileList *filelist)
        
        for (num = 0; num < filelist->numfiles; num++, file++) {
                file->type = file->s.st_mode;  /* restore the mess below */
-               
-               /* Don't check extensions for directories */ 
+#ifndef __APPLE__
+               /* Don't check extensions for directories, allow in OSX cause bundles have extensions*/
                if (file->type & S_IFDIR) {
                        continue;
                }
-               file->flags = file_extension_type(file->relname);
+#endif
+               file->flags = file_extension_type(filelist->dir, file->relname);
                
-               if (filelist->filter_glob &&
+               if (filelist->filter_glob[0] &&
                    BLI_testextensie_glob(file->relname, filelist->filter_glob))
                {
                        file->flags = OPERATORFILE;
@@ -862,18 +895,14 @@ static void filelist_setfiletypes(struct FileList *filelist)
 
 static void filelist_read_dir(struct FileList *filelist)
 {
-       char wdir[FILE_MAX] = "";
        if (!filelist) return;
 
        filelist->fidx = NULL;
        filelist->filelist = NULL;
 
-       BLI_current_working_dir(wdir, sizeof(wdir));  /* backup cwd to restore after */
-
        BLI_cleanup_dir(G.main->name, filelist->dir);
        filelist->numfiles = BLI_dir_contents(filelist->dir, &(filelist->filelist));
 
-       if (!chdir(wdir)) {} /* fix warning about not checking return value */
        filelist_setfiletypes(filelist);
        filelist_filter(filelist);
 }
@@ -932,7 +961,7 @@ void filelist_parent(struct FileList *filelist)
 void filelist_select_file(struct FileList *filelist, int index, FileSelType select, unsigned int flag, FileCheckType check)
 {
        struct direntry *file = filelist_file(filelist, index);
-       if (file != NULL) {     
+       if (file != NULL) {
                int check_ok = 0; 
                switch (check) {
                        case CHECK_DIRS:
@@ -965,9 +994,9 @@ void filelist_select_file(struct FileList *filelist, int index, FileSelType sele
 void filelist_select(struct FileList *filelist, FileSelection *sel, FileSelType select, unsigned int flag, FileCheckType check)
 {
        /* select all valid files between first and last indicated */
-       if ( (sel->first >= 0) && (sel->first < filelist->numfiltered) && (sel->last >= 0) && (sel->last < filelist->numfiltered) ) {
+       if ((sel->first >= 0) && (sel->first < filelist->numfiltered) && (sel->last >= 0) && (sel->last < filelist->numfiltered)) {
                int current_file;
-               for (current_file = sel->first; current_file <= sel->last; current_file++) {    
+               for (current_file = sel->first; current_file <= sel->last; current_file++) {
                        filelist_select_file(filelist, current_file, select, flag, check);
                }
        }
@@ -1004,6 +1033,7 @@ void filelist_sort(struct FileList *filelist, short sort)
                        break;
                case FILE_SORT_EXTENSION:
                        qsort(filelist->filelist, filelist->numfiles, sizeof(struct direntry), compare_extension);
+                       break;
        }
 
        filelist_filter(filelist);
@@ -1021,7 +1051,7 @@ static int groupname_to_code(const char *group)
        char *lslash;
        
        BLI_strncpy(buf, group, sizeof(buf));
-       lslash = BLI_last_slash(buf);
+       lslash = (char *)BLI_last_slash(buf);
        if (lslash)
                lslash[0] = '\0';
 
@@ -1034,7 +1064,7 @@ void filelist_from_library(struct FileList *filelist)
        struct ImBuf *ima;
        int ok, i, nprevs, nnames, idcode;
        char filename[FILE_MAX];
-       char dir[FILE_MAX], group[GROUP_MAX];   
+       char dir[FILE_MAX], group[GROUP_MAX];
        
        /* name test */
        ok = filelist_islibrary(filelist, dir, group);
@@ -1150,7 +1180,11 @@ void filelist_from_main(struct FileList *filelist)
        if (filelist->dir[0] == 0) {
                
                /* make directories */
+#ifdef WITH_FREESTYLE
                filelist->numfiles = 25;
+#else
+               filelist->numfiles = 24;
+#endif
                filelist->filelist = (struct direntry *)malloc(filelist->numfiles * sizeof(struct direntry));
                
                for (a = 0; a < filelist->numfiles; a++) {
@@ -1181,7 +1215,9 @@ void filelist_from_main(struct FileList *filelist)
                filelist->filelist[21].relname = BLI_strdup("Action");
                filelist->filelist[22].relname = BLI_strdup("NodeTree");
                filelist->filelist[23].relname = BLI_strdup("Speaker");
-               filelist->filelist[24].relname= BLI_strdup("FreestyleLineStyle");
+#ifdef WITH_FREESTYLE
+               filelist->filelist[24].relname = BLI_strdup("FreestyleLineStyle");
+#endif
                filelist_sort(filelist, FILE_SORT_ALPHA);
        }
        else {
@@ -1224,21 +1260,22 @@ void filelist_from_main(struct FileList *filelist)
                        if (ok) {
                                if (!filelist->hide_dot || id->name[2] != '.') {
                                        memset(files, 0, sizeof(struct direntry));
-                                       if (id->lib == NULL)
+                                       if (id->lib == NULL) {
                                                files->relname = BLI_strdup(id->name + 2);
+                                       }
                                        else {
-                                               files->relname = MEM_mallocN(FILE_MAX + 32, "filename for lib");
-                                               sprintf(files->relname, "%s | %s", id->lib->name, id->name + 2);
+                                               files->relname = MEM_mallocN(FILE_MAX + (MAX_ID_NAME - 2),     "filename for lib");
+                                               BLI_snprintf(files->relname, FILE_MAX + (MAX_ID_NAME - 2) + 3, "%s | %s", id->lib->name, id->name + 2);
                                        }
                                        files->type |= S_IFREG;
-#if 0               // XXXXX TODO show the selection status of the objects
+#if 0               /* XXXXX TODO show the selection status of the objects */
                                        if (!filelist->has_func) { /* F4 DATA BROWSE */
                                                if (idcode == ID_OB) {
                                                        if ( ((Object *)id)->flag & SELECT) files->selflag |= SELECTED_FILE;
                                                }
                                                else if (idcode == ID_SCE) {
                                                        if ( ((Scene *)id)->r.scemode & R_BG_RENDER) files->selflag |= SELECTED_FILE;
-                                               }                                       
+                                               }
                                        }
 #endif
                                        files->nr = totbl + 1;
@@ -1247,10 +1284,10 @@ void filelist_from_main(struct FileList *filelist)
                                        if (idcode == ID_MA || idcode == ID_TE || idcode == ID_LA || idcode == ID_WO || idcode == ID_IM) {
                                                files->flags |= IMAGEFILE;
                                        }
-                                       if (id->lib && fake) BLI_snprintf(files->extra, sizeof(files->extra), "LF %d", id->us);
-                                       else if (id->lib) BLI_snprintf(files->extra, sizeof(files->extra), "L    %d", id->us);
-                                       else if (fake) BLI_snprintf(files->extra, sizeof(files->extra), "F    %d", id->us);
-                                       else BLI_snprintf(files->extra, sizeof(files->extra), "      %d", id->us);
+                                       if      (id->lib && fake) BLI_snprintf(files->extra, sizeof(files->extra), "LF %d",    id->us);
+                                       else if (id->lib)         BLI_snprintf(files->extra, sizeof(files->extra), "L    %d",  id->us);
+                                       else if (fake)            BLI_snprintf(files->extra, sizeof(files->extra), "F    %d",  id->us);
+                                       else                      BLI_snprintf(files->extra, sizeof(files->extra), "      %d", id->us);
                                        
                                        if (id->lib) {
                                                if (totlib == 0) firstlib = files;
@@ -1295,11 +1332,11 @@ static void thumbnails_startjob(void *tjv, short *stop, short *do_update, float
        tj->stop = stop;
        tj->do_update = do_update;
 
-       while ( (*stop == 0) && (limg) ) {
+       while ((*stop == 0) && (limg)) {
                if (limg->flags & IMAGEFILE) {
                        limg->img = IMB_thumb_manage(limg->path, THB_NORMAL, THB_SOURCE_IMAGE);
                }
-               else if (limg->flags & BLENDERFILE) {
+               else if (limg->flags & (BLENDERFILE | BLENDERFILE_BACKUP)) {
                        limg->img = IMB_thumb_manage(limg->path, THB_NORMAL, THB_SOURCE_BLEND);
                }
                else if (limg->flags & MOVIEFILE) {
@@ -1345,7 +1382,7 @@ static void thumbnails_free(void *tjv)
 }
 
 
-void thumbnails_start(struct FileList *filelist, const struct bContext *C)
+void thumbnails_start(FileList *filelist, const bContext *C)
 {
        wmJob *wm_job;
        ThumbnailJob *tj;
@@ -1356,8 +1393,8 @@ void thumbnails_start(struct FileList *filelist, const struct bContext *C)
        tj->filelist = filelist;
        for (idx = 0; idx < filelist->numfiles; idx++) {
                if (!filelist->filelist[idx].image) {
-                       if ( (filelist->filelist[idx].flags & (IMAGEFILE | MOVIEFILE | BLENDERFILE)) ) {
-                               FileImage *limg = MEM_callocN(sizeof(struct FileImage), "loadimage");
+                       if ((filelist->filelist[idx].flags & (IMAGEFILE | MOVIEFILE | BLENDERFILE | BLENDERFILE_BACKUP))) {
+                               FileImage *limg = MEM_callocN(sizeof(FileImage), "loadimage");
                                BLI_strncpy(limg->path, filelist->filelist[idx].path, FILE_MAX);
                                limg->index = idx;
                                limg->flags = filelist->filelist[idx].flags;
@@ -1379,12 +1416,12 @@ void thumbnails_start(struct FileList *filelist, const struct bContext *C)
        WM_jobs_start(CTX_wm_manager(C), wm_job);
 }
 
-void thumbnails_stop(struct FileList *filelist, const struct bContext *C)
+void thumbnails_stop(wmWindowManager *wm, FileList *filelist)
 {
-       WM_jobs_kill(CTX_wm_manager(C), filelist, NULL);
+       WM_jobs_kill(wm, filelist, NULL);
 }
 
-int thumbnails_running(struct FileList *filelist, const struct bContext *C)
+int thumbnails_running(wmWindowManager *wm, FileList *filelist)
 {
-       return WM_jobs_test(CTX_wm_manager(C), filelist, WM_JOB_TYPE_FILESEL_THUMBNAIL);
+       return WM_jobs_test(wm, filelist, WM_JOB_TYPE_FILESEL_THUMBNAIL);
 }