Fix T43684: File Browser is unusable on Windows Machines (do not BLI_is_dir() in draw loop!)

Did not had any issue on linux, but looks like on some windows can slow things as Hell.
Or maybe just the presence of some network FS?

Anyway, not a good idea, so now fsmenu entries' valid status is stored and only evaluated
on startup (reading of bookmarks & co) and when opening file browser (refresh, like
for system bookmarks).
This commit is contained in:
Bastien Montagne 2015-02-16 15:48:37 +01:00
parent fd4f0ed39e
commit 0dfdca6d13
Notes: blender-bot 2023-02-14 09:29:36 +01:00
Referenced by issue #63748, Long startups after network drives are disconnected
Referenced by issue #43684, File Browser is unusable on Windows Machines
6 changed files with 41 additions and 10 deletions

View File

@ -600,6 +600,7 @@ static int bookmark_cleanup_exec(bContext *C, wmOperator *UNUSED(op))
BLI_make_file_string("/", name, BKE_appdir_folder_id_create(BLENDER_USER_CONFIG, NULL), BLENDER_BOOKMARK_FILE);
fsmenu_write_file(fsmenu, name);
fsmenu_refresh_bookmarks_status(fsmenu);
ED_area_tag_refresh(sa);
ED_area_tag_redraw(sa);
}

View File

@ -216,6 +216,16 @@ void ED_fsmenu_entry_set_name(struct FSMenuEntry *fsentry, const char *name)
}
}
void fsmenu_entry_refresh_valid(struct FSMenuEntry *fsentry)
{
if (fsentry->path && fsentry->path[0]) {
fsentry->valid = BLI_is_dir(fsentry->path);
}
else {
fsentry->valid = false;
}
}
short fsmenu_can_save(struct FSMenu *fsmenu, FSMenuCategory category, int idx)
{
FSMenuEntry *fsm_iter;
@ -272,6 +282,7 @@ void fsmenu_insert_entry(struct FSMenu *fsmenu, FSMenuCategory category, const c
else {
fsm_iter->name[0] = '\0';
}
fsmenu_entry_refresh_valid(fsm_iter);
if (fsm_prev) {
if (flag & FS_INSERT_FIRST) {
@ -640,6 +651,19 @@ void fsmenu_refresh_system_category(struct FSMenu *fsmenu)
fsmenu_read_system(fsmenu, true);
}
void fsmenu_refresh_bookmarks_status(struct FSMenu *fsmenu)
{
int categories[] = {FS_CATEGORY_SYSTEM, FS_CATEGORY_SYSTEM_BOOKMARKS, FS_CATEGORY_BOOKMARKS, FS_CATEGORY_RECENT};
int i;
for (i = sizeof(categories) / sizeof(*categories); i--; ) {
FSMenuEntry *fsm_iter = ED_fsmenu_get_category(fsmenu, categories[i]);
for ( ; fsm_iter; fsm_iter = fsm_iter->next) {
fsmenu_entry_refresh_valid(fsm_iter);
}
}
}
void fsmenu_free(void)
{
if (g_fsmenu) {

View File

@ -49,6 +49,9 @@ struct FSMenuEntry;
*/
void fsmenu_insert_entry(struct FSMenu *fsmenu, enum FSMenuCategory category, const char *path, const char *name, const enum FSMenuInsert flag);
/** Refresh 'valid' status of given menu entry */
void fsmenu_entry_refresh_valid(struct FSMenuEntry *fsentry);
/** Return whether the entry was created by the user and can be saved and deleted */
short fsmenu_can_save(struct FSMenu *fsmenu, enum FSMenuCategory category, int index);
@ -70,6 +73,9 @@ void fsmenu_free(void);
/** Refresh system directory menu */
void fsmenu_refresh_system_category(struct FSMenu *fsmenu);
/** Refresh 'valid' status of all menu entries */
void fsmenu_refresh_bookmarks_status(struct FSMenu *fsmenu);
/** Get active index based on given directory. */
int fsmenu_get_active_indices(struct FSMenu *fsmenu, enum FSMenuCategory category, const char *dir);

View File

@ -157,6 +157,12 @@ static void file_init(wmWindowManager *UNUSED(wm), ScrArea *sa)
/* refresh system directory list */
fsmenu_refresh_system_category(ED_fsmenu_get());
/* Update bookmarks 'valid' state.
* Done here, because it seems BLI_is_dir() can have huge impact on performances
* in some cases, on win systems... See T43684.
*/
fsmenu_refresh_bookmarks_status(ED_fsmenu_get());
if (sfile->layout) sfile->layout->dirty = true;
}

View File

@ -647,7 +647,8 @@ typedef struct FSMenuEntry {
char *path;
char name[256]; /* FILE_MAXFILE */
short save;
short pad[3];
short valid;
short pad[2];
} FSMenuEntry;
/* FileSelectParams.display */

View File

@ -1423,13 +1423,6 @@ static int rna_FileBrowser_FSMenuEntry_name_get_editable(PointerRNA *ptr)
return fsm->save;
}
static int rna_FileBrowser_FSMenuEntry_is_valid_get(PointerRNA *ptr)
{
char *path = ED_fsmenu_entry_get_path(ptr->data);
return path ? BLI_is_dir(path) : false; /* For now, no path = invalid. */
}
static void rna_FileBrowser_FSMenu_next(CollectionPropertyIterator *iter)
{
ListBaseIterator *internal = &iter->internal.listbase;
@ -3638,8 +3631,8 @@ static void rna_def_filemenu_entry(BlenderRNA *brna)
RNA_def_property_clear_flag(prop, PROP_EDITABLE);
prop = RNA_def_property(srna, "is_valid", PROP_BOOLEAN, PROP_NONE);
RNA_def_property_boolean_funcs(prop, "rna_FileBrowser_FSMenuEntry_is_valid_get", NULL);
RNA_def_property_ui_text(prop, "Save", "Whether this path is saved in bookmarks, or generated from OS");
RNA_def_property_boolean_sdna(prop, NULL, "valid", 1);
RNA_def_property_ui_text(prop, "Valid", "Whether this path is currently reachable");
RNA_def_property_clear_flag(prop, PROP_EDITABLE);
}