Blender V5.3
filelist.cc
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2007 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
8
9/* global includes */
10
11#include <algorithm>
12#include <cstdlib>
13#include <cstring>
14#include <ctime>
15#include <memory>
16#include <optional>
17#include <sys/stat.h>
18
19#include "AS_asset_library.hh"
21#include "AS_remote_library.hh"
22
23#include "DNA_space_enums.h"
24#include "MEM_guardedalloc.h"
25
26#include "BLF_api.hh"
27
28#include "BLI_fileops.hh"
29#include "BLI_ghash.hh"
30#include "BLI_listbase.hh"
31#include "BLI_math_vector_c.hh"
32#include "BLI_path_utils.hh"
33#include "BLI_string.hh"
34#include "BLI_task_c.hh"
35#include "BLI_threads.hh"
36
37#include "BKE_asset.hh"
38#include "BKE_blendfile.hh"
39#include "BKE_context.hh"
40#include "BKE_global.hh"
41#include "BKE_icons.hh"
42#include "BKE_main.hh"
43#include "BKE_preferences.h"
44#include "BKE_preview_image.hh"
45
46#include "DNA_asset_types.h"
47#include "DNA_space_types.h"
48#include "DNA_userdef_types.h"
49
50#include "ED_asset_indexer.hh"
51#include "ED_fileselect.hh"
52
53#include "IMB_imbuf.hh"
54#include "IMB_imbuf_types.hh"
55#include "IMB_thumbs.hh"
56
57#include "MOV_util.hh"
58
59#include "WM_api.hh"
60#include "WM_types.hh"
61
62#include "UI_interface_icons.hh"
63#include "UI_resources.hh"
64
65#include "atomic_ops.h"
66
67#include "../file_indexer.hh"
68#include "../file_intern.hh"
69#include "../filelist.hh"
70#include "filelist_intern.hh"
71#include "filelist_readjob.hh"
72
73namespace blender {
74
76
78 const FileList *filelist, const StringRef downloaded_file_abspath)
79{
80 for (FileListInternEntry &entry : filelist->filelist_intern.entries) {
81 std::shared_ptr<asset_system::AssetRepresentation> asset = entry.asset.lock();
82 if (!asset) {
83 continue;
84 }
85
86 if (entry.typeflag & FILE_TYPE_ASSET_ONLINE) {
87 /* #AssetRepresentation.full_library_path() will only return a non-empty string if the
88 * asset's path points into some .blend on disk. */
89 std::string filepath = asset->full_library_path();
90 if (filepath.empty()) {
91 continue;
92 }
93 BLI_assert(BLI_is_file(filepath.c_str()));
94
96 asset->online_asset_mark_downloaded();
97
98 if (FileDirEntry **cached_entry = filelist->filelist_cache->uids.lookup_ptr(entry.uid)) {
99 (**cached_entry).typeflag &= ~FILE_TYPE_ASSET_ONLINE;
100 }
101 }
102 else if (asset->remote_file_status() == asset_system::RemoteAssetFileStatus::NO_MATCH) {
103 /* For already-downloaded assets that didn't match the remote listing, clear the mismatch
104 * status when their specific file has been re-downloaded. */
105 std::string filepath = asset->full_library_path();
106 if (filepath != downloaded_file_abspath) {
107 continue;
108 }
109 asset->online_asset_mark_downloaded();
110 }
111 }
112}
113
115 const FileList *filelist,
116 const blender::StringRef remote_url,
117 const blender::StringRef absolute_downloaded_file)
118{
119 if (!filelist->asset_library) {
120 return;
121 }
122 if (remote_url.is_empty()) {
123 return;
124 }
125
127 remote_asset_library_refresh_online_assets_status(filelist, absolute_downloaded_file);
128 }
129}
130
131void filelist_setindexer(FileList *filelist, const FileIndexerType *indexer)
132{
133 BLI_assert(filelist);
134 BLI_assert(indexer);
135
136 filelist->indexer = indexer;
137}
138
139void filelist_set_asset_include_online(FileList *filelist, const bool show_online_assets)
140{
141 if (!filelist->asset_library_ref ||
143 {
144 /* Online flag has no effect if not displaying online libraries. This function will be called
145 * again when switching libraries, so updating the flag here shouldn't be needed. Still do it
146 * for predictability. */
147 SET_FLAG_FROM_TEST(filelist->flags, show_online_assets, FL_ASSETS_INCLUDE_ONLINE);
148 return;
149 }
150
151 if (show_online_assets && ((filelist->flags & FL_ASSETS_INCLUDE_ONLINE) == 0)) {
152 /* Full refresh when enabling online assets, so online asset loading is triggered. */
153 filelist_tag_force_reset(filelist);
154 filelist->flags |= FL_ASSETS_INCLUDE_ONLINE;
155 }
156 else if (!show_online_assets && ((filelist->flags & FL_ASSETS_INCLUDE_ONLINE) != 0)) {
157 /* Simply filter out online assets when they were already loaded. */
159 filelist->flags &= ~FL_ASSETS_INCLUDE_ONLINE;
160 }
161}
162
164 FileList *filelist,
166 const bUUID *catalog_id)
167{
168 if (!filelist->filter_data.asset_catalog_filter) {
169 /* There's no filter data yet. */
172 }
173
174 const bool needs_update = file_set_asset_catalog_filter_settings(
175 filelist->filter_data.asset_catalog_filter, catalog_visibility, *catalog_id);
176
177 if (needs_update) {
179 }
180}
181
187 const AssetLibraryReference *library_b)
188{
189 if (library_a->type != library_b->type) {
190 return false;
191 }
192 if (library_a->type == ASSET_LIBRARY_CUSTOM) {
193 /* Don't only check the index, also check that it's valid. */
195 &U, library_a->custom_library_index);
196 return (library_ptr_a != nullptr) &&
197 (library_a->custom_library_index == library_b->custom_library_index);
198 }
199
200 return true;
201}
202
204 const AssetLibraryReference *asset_library_ref,
205 FunctionRef<void()> on_change)
206{
207 /* Unset if needed. */
208 if (!asset_library_ref) {
209 if (filelist->asset_library_ref) {
210 MEM_SAFE_DELETE(filelist->asset_library_ref);
211 filelist->flags |= FL_FORCE_RESET;
212 }
213 return;
214 }
215
216 bool changed = false;
217 if (!filelist->asset_library_ref) {
218 filelist->asset_library_ref = MEM_new<AssetLibraryReference>("filelist asset library");
219 *filelist->asset_library_ref = *asset_library_ref;
220
221 filelist->flags |= FL_FORCE_RESET;
222 changed = true;
223 }
224 else if (!filelist_compare_asset_libraries(filelist->asset_library_ref, asset_library_ref)) {
225 *filelist->asset_library_ref = *asset_library_ref;
226 filelist->flags |= FL_FORCE_RESET;
227 changed = true;
228 }
229
230 if (changed && on_change) {
231 on_change();
232 }
233}
234
235/* ********** Icon/image helpers ********** */
236
238{
239 BLI_assert(G.background == false);
240
241 for (int i = 0; i < int(SpecialFileImages::_Max); i++) {
243 gSpecialFileImages[i] = nullptr;
244 }
245}
246
248 const FileDirEntry *file,
249 char r_filepath[FILE_MAX_LIBEXTRA])
250{
251 if (file->asset) {
252 const std::string asset_path = file->asset->full_path();
253 BLI_strncpy(r_filepath, asset_path.c_str(), FILE_MAX_LIBEXTRA);
254 return;
255 }
256
257 const char *root = filelist_dir(filelist);
258 BLI_path_join(r_filepath, FILE_MAX_LIBEXTRA, root, file->relpath);
259}
260
262{
263 /* Actual preview loading is only started after the filelist is loaded, so the file isn't flagged
264 * with #FILE_ENTRY_PREVIEW_LOADING yet. */
265 const bool filelist_ready = filelist_is_ready(filelist);
266 if (!filelist_ready) {
267 return true;
268 }
269 const PreviewImage *asset_preview = file->asset ? file->asset->get_preview() : nullptr;
270 if (asset_preview && (asset_preview->flag[ICON_SIZE_PREVIEW] & PRV_RENDERING)) {
271 return true;
272 }
273
274 return file->flags & FILE_ENTRY_PREVIEW_LOADING;
275}
276
278{
279 BLI_assert(G.background == false);
280
281 return filelist_file(filelist, index);
282}
283
290
292{
293 ImBuf *ibuf = gSpecialFileImages[int(image)];
294 if (ibuf) {
295 return ibuf;
296 }
297 return gSpecialFileImages[int(image)] = ui::svg_icon_bitmap(icon, 256.0f, false);
298}
299
301{
302 ImBuf *ibuf = nullptr;
303
304 if (file->typeflag & FILE_TYPE_DIR) {
305 if (FILENAME_IS_PARENT(file->relpath)) {
307 }
308 else {
310 }
311 }
312 else {
314 }
315
316 return ibuf;
317}
318
324
325static int filelist_geticon_file_type_ex(const FileList *filelist,
326 const FileDirEntry *file,
327 const bool is_main,
328 const bool ignore_libdir)
329{
330 const eFileSel_File_Types typeflag = eFileSel_File_Types(file->typeflag);
331
332 if ((typeflag & FILE_TYPE_DIR) &&
333 !(ignore_libdir && (typeflag & (FILE_TYPE_BLENDERLIB | FILE_TYPE_BLENDER))))
334 {
335 if (FILENAME_IS_PARENT(file->relpath)) {
336 return is_main ? ICON_FILE_PARENT : ICON_NONE;
337 }
338 if (typeflag & FILE_TYPE_BUNDLE) {
339 return ICON_UGLYPACKAGE;
340 }
341 if (typeflag & FILE_TYPE_BLENDER) {
342 return ICON_FILE_BLEND;
343 }
344 if (is_main) {
345 /* Do not return icon for folders if icons are not 'main' draw type
346 * (e.g. when used over previews). */
347 return (file->attributes & FILE_ATTR_ANY_LINK) ? ICON_FOLDER_REDIRECT : ICON_FILE_FOLDER;
348 }
349
350 /* If this path is in System list or path cache then use that icon. */
351 FSMenu *fsmenu = ED_fsmenu_get();
352 FSMenuCategory categories[] = {
356 };
357
358 for (int i = 0; i < ARRAY_SIZE(categories); i++) {
359 FSMenuEntry *tfsm = ED_fsmenu_get_category(fsmenu, categories[i]);
360 char fullpath[FILE_MAX_LIBEXTRA];
361 char *target = fullpath;
362 if (file->redirection_path) {
363 target = file->redirection_path;
364 }
365 else if (filelist) {
366 filelist_file_get_full_path(filelist, file, fullpath);
367 BLI_path_slash_ensure(fullpath, sizeof(fullpath));
368 }
369 for (; tfsm; tfsm = tfsm->next) {
370 if (STREQ(tfsm->path, target)) {
371 /* Never want a little folder inside a large one. */
372 return (tfsm->icon == ICON_FILE_FOLDER) ? ICON_NONE : tfsm->icon;
373 }
374 }
375 }
376
377 if (file->attributes & FILE_ATTR_OFFLINE) {
378 return ICON_STATUS_ERROR;
379 }
380 if (file->attributes & FILE_ATTR_TEMPORARY) {
381 return ICON_FILE_CACHE;
382 }
383 if (file->attributes & FILE_ATTR_SYSTEM) {
384 return ICON_SYSTEM;
385 }
386 }
387
388 if (typeflag & FILE_TYPE_BLENDER) {
389 return (is_main || file->preview_icon_id) ? ICON_FILE_BLEND : ICON_BLENDER;
390 }
391 if (typeflag & FILE_TYPE_BLENDER_BACKUP) {
392 return ICON_FILE_BACKUP;
393 }
394 if (typeflag & FILE_TYPE_IMAGE) {
395 return ICON_FILE_IMAGE;
396 }
397 if (typeflag & FILE_TYPE_MOVIE) {
398 return ICON_FILE_MOVIE;
399 }
400 if (typeflag & FILE_TYPE_PYSCRIPT) {
401 return ICON_FILE_SCRIPT;
402 }
403 if (typeflag & FILE_TYPE_SOUND) {
404 return ICON_FILE_SOUND;
405 }
406 if (typeflag & FILE_TYPE_FTFONT) {
407 return ICON_FILE_FONT;
408 }
409 if (typeflag & FILE_TYPE_BTX) {
410 return ICON_FILE_BLANK;
411 }
412 if (typeflag & FILE_TYPE_ALEMBIC) {
413 return ICON_FILE_3D;
414 }
415 if (typeflag & FILE_TYPE_USD) {
416 return ICON_FILE_3D;
417 }
418 if (typeflag & FILE_TYPE_VOLUME) {
419 return ICON_FILE_VOLUME;
420 }
421 if (typeflag & FILE_TYPE_OBJECT_IO) {
422 return ICON_FILE_3D;
423 }
424 if (typeflag & FILE_TYPE_TEXT) {
425 return ICON_FILE_TEXT;
426 }
427 if (typeflag & FILE_TYPE_ARCHIVE) {
428 return ICON_FILE_ARCHIVE;
429 }
430 if (typeflag & FILE_TYPE_BLENDERLIB) {
431 const int ret = ui::icon_from_idcode(file->blentype);
432 if (ret != ICON_NONE) {
433 return ret;
434 }
435 }
436 return is_main ? ICON_FILE_BLANK : ICON_NONE;
437}
438
439int filelist_geticon_file_type(FileList *filelist, const int index, const bool is_main)
440{
442
443 return filelist_geticon_file_type_ex(filelist, file, is_main, false);
444}
445
447{
448 return file->preview_icon_id ? file->preview_icon_id :
449 filelist_geticon_file_type_ex(nullptr, file, false, false);
450}
451
453{
454 return intern_entry->local_data.id != nullptr;
455}
456
457/* ********** Main ********** */
458
460{
461 if (entry->name && ((entry->flags & FILE_ENTRY_NAME_FREE) != 0)) {
462 MEM_delete(const_cast<char *>(entry->name));
463 }
464 if (entry->relpath) {
465 MEM_delete(entry->relpath);
466 }
467 if (entry->redirection_path) {
468 MEM_delete(entry->redirection_path);
469 }
470 if (entry->preview_icon_id &&
471 /* Online assets previews are managed by the general UI preview system, not the file browser
472 * one. Don't mess with them. */
473 ((entry->typeflag & FILE_TYPE_ASSET_ONLINE) == 0))
474 {
476 entry->preview_icon_id = 0;
477 }
478}
479
481{
483 MEM_delete(entry);
484}
485
487{
488#if 0
489 FileDirEntry *entry, *entry_next;
490
491 for (entry = array->entries.first; entry; entry = entry_next) {
492 entry_next = entry->next;
493 filelist_entry_free(entry);
494 }
495 array->entries.clear_no_delete();
496#else
497 BLI_assert(array->entries.is_empty());
498#endif
499 array->entries_num = FILEDIR_NBR_ENTRIES_UNSET;
500 array->entries_filtered_num = FILEDIR_NBR_ENTRIES_UNSET;
501}
502
504{
505 if (auto asset_ptr = entry->asset.lock()) {
506 BLI_assert(filelist->asset_library);
507 filelist->asset_library->remove_asset(*asset_ptr);
508 }
509
510 if (entry->relpath) {
511 MEM_delete(entry->relpath);
512 }
513 if (entry->redirection_path) {
514 MEM_delete(entry->redirection_path);
515 }
516 if (entry->name && entry->free_name) {
517 MEM_delete(const_cast<char *>(entry->name));
518 }
519 MEM_delete(entry);
520}
521
522static void filelist_intern_free(FileList *filelist)
523{
524 FileListIntern *filelist_intern = &filelist->filelist_intern;
525 for (FileListInternEntry &entry : filelist_intern->entries.items_mutable()) {
526 filelist_intern_entry_free(filelist, &entry);
527 }
528 filelist_intern->entries.clear_no_delete();
529
530 MEM_SAFE_DELETE(filelist_intern->filtered);
531}
532
537{
538 FileListIntern *filelist_intern = &filelist->filelist_intern;
539 int removed_counter = 0;
540 for (FileListInternEntry &entry : filelist_intern->entries.items_mutable()) {
542 continue;
543 }
544
545 BLI_remlink(&filelist_intern->entries, &entry);
546 filelist_intern_entry_free(filelist, &entry);
547 removed_counter++;
548 }
549
550 if (removed_counter > 0) {
551 MEM_SAFE_DELETE(filelist_intern->filtered);
552 }
553 return removed_counter;
554}
555
556static void filelist_cache_preview_runf(TaskPool *__restrict pool, void *taskdata)
557{
559 if (cache->previews_cancel_token.is_cancelled()) {
560 return;
561 }
562
563 FileListEntryPreviewTaskData *preview_taskdata = static_cast<FileListEntryPreviewTaskData *>(
564 taskdata);
565 FileListEntryPreview *preview = preview_taskdata->preview;
566
567 /* XXX #THB_SOURCE_IMAGE for "historic" reasons. The case of an undefined source should be
568 * handled better. */
570
571 // printf("%s: Start (%d)...\n", __func__, threadid);
572
573 // printf("%s: %d - %s - %p\n", __func__, preview->index, preview->path, preview->img);
574 BLI_assert(preview->flags &
577 BLI_assert((preview->flags & FILE_TYPE_ASSET_ONLINE) == 0);
578
579 if (preview->flags & FILE_TYPE_IMAGE) {
580 source = THB_SOURCE_IMAGE;
581 }
583 {
584 source = THB_SOURCE_BLEND;
585 }
586 else if (preview->flags & FILE_TYPE_MOVIE) {
587 source = THB_SOURCE_MOVIE;
588 }
589 else if (preview->flags & FILE_TYPE_FTFONT) {
590 source = THB_SOURCE_FONT;
591 }
592 else if (preview->flags & FILE_TYPE_OBJECT_IO) {
593 source = THB_SOURCE_OBJECT_IO;
594 }
595
597 /* Always generate biggest preview size for now, it's simpler and avoids having to re-generate
598 * in case user switch to a bigger preview size. */
600 preview->filepath, THB_LARGE, source, &cache->previews_cancel_token);
602
603 if (imbuf) {
605 }
606
607 /* Move ownership to the done queue. */
608 preview_taskdata->preview = nullptr;
609
611
612 // printf("%s: End (%d)...\n", __func__, threadid);
613}
614
615static void filelist_cache_preview_freef(TaskPool *__restrict /*pool*/, void *taskdata)
616{
617 FileListEntryPreviewTaskData *preview_taskdata = static_cast<FileListEntryPreviewTaskData *>(
618 taskdata);
619
620 /* In case the preview wasn't moved to the "done" queue yet. */
621 if (preview_taskdata->preview) {
622 MEM_delete(preview_taskdata->preview);
623 }
624
625 MEM_delete(preview_taskdata);
626}
627
638
640{
641 if (cache->previews_pool) {
644
645 for (FileDirEntry &entry : cache->cached_entries) {
647 }
648
649 FileListEntryPreview *preview;
650 while ((preview = static_cast<FileListEntryPreview *>(
652 {
653 // printf("%s: DONE %d - %s - %p\n", __func__, preview->index, preview->path,
654 // preview->img);
655 BLI_assert((preview->flags & FILE_TYPE_ASSET_ONLINE) == 0);
656 if (preview->icon_id) {
657 BKE_icon_delete(preview->icon_id);
658 }
659 MEM_delete(preview);
660 }
661 cache->previews_todo_count = 0;
663 }
664}
665
667{
668 if (cache->previews_pool) {
670
672
675 cache->previews_pool = nullptr;
676 cache->previews_done = nullptr;
677 cache->previews_todo_count = 0;
678
680 }
681
682 cache->flags &= ~FLC_PREVIEWS_ACTIVE;
683}
684
691{
693 return false;
694 }
695
696 if (!(entry->typeflag &
699 {
700 return false;
701 }
702
703 /* If we know this is an external ID without a preview, skip loading the preview. Can save quite
704 * some time in heavy files, because otherwise for each missing preview and for each preview
705 * reload, we'd reopen the .blend to look for the preview. */
706 if ((entry->typeflag & FILE_TYPE_BLENDERLIB) &&
708 {
709 return false;
710 }
711
712 /* External ID that is also a directory is never previewed. */
713 if ((entry->typeflag & (FILE_TYPE_BLENDERLIB | FILE_TYPE_DIR)) ==
715 {
716 return false;
717 }
718
719 return true;
720}
721
723{
724 BLI_assert(entry->asset);
726
727 if (entry->preview_icon_id) {
728 return;
729 }
730
732 return;
733 }
734
735 /* Request online preview if needed. */
736 if (entry->asset->is_online_only()) {
738
739 const PreviewImage *preview = entry->asset->get_preview();
740
741 if (preview) {
742 entry->preview_icon_id = preview->runtime->icon_id;
743 }
744 else {
746 }
747 }
748}
749
754static bool filelist_cache_previews_push(FileList *filelist, FileDirEntry *entry, const int index)
755{
756 FileListEntryCache *cache = filelist->filelist_cache;
757
759
760 if (entry->preview_icon_id) {
761 return false;
762 }
763
764 if (entry->typeflag & FILE_TYPE_ASSET_ONLINE) {
765 /* Online assets use the UI system for async preview loading (see #PreviewLoadJob)
766 * instead of the file browser one. */
767 return false;
768 }
769
771 return false;
772 }
773
774 FileListInternEntry *intern_entry = filelist->filelist_intern.filtered[index];
775 const PreviewImage *preview_in_memory = intern_entry->local_data.preview_image;
776 if (preview_in_memory && !BKE_previewimg_is_finished(preview_in_memory, ICON_SIZE_PREVIEW)) {
777 /* Nothing to set yet. Wait for next call. */
778 return false;
779 }
780
783
785 preview->index = index;
786 preview->flags = entry->typeflag;
787 preview->icon_id = 0;
788
789 if (preview_in_memory) {
790 /* TODO(mano-wii): No need to use the thread API here. */
792 preview->filepath[0] = '\0';
794 if (imbuf) {
796 }
798 }
799 else {
800 if (entry->redirection_path) {
802 }
803 else {
804 filelist_file_get_full_path(filelist, entry, preview->filepath);
805 }
806 // printf("%s: %d - %s\n", __func__, preview->index, preview->filepath);
807
809 __func__);
810 preview_taskdata->preview = preview;
813 preview_taskdata,
814 true,
816 }
817 cache->previews_todo_count++;
818
819 return true;
820}
821
823{
824 block_entries = static_cast<FileDirEntry **>(
825 MEM_new_uninitialized(sizeof(*this->block_entries) * this->size, __func__));
826
827 this->misc_entries.reserve(this->size);
828 this->misc_entries_indices = MEM_new_array_uninitialized<int>(this->size, __func__);
829 std::fill_n(this->misc_entries_indices, this->size, -1);
830
831 this->uids.reserve(this->size * 2);
832}
833
835{
837
838 MEM_delete(this->block_entries);
839 MEM_delete(this->misc_entries_indices);
840
841 for (FileDirEntry &entry : this->cached_entries.items_mutable()) {
842 filelist_entry_free(&entry);
843 }
844}
845
846void filelist_cache_clear(FileListEntryCache *cache, size_t new_size)
847{
849
850 cache->block_cursor = cache->block_start_index = cache->block_center_index =
851 cache->block_end_index = 0;
852 if (new_size != cache->size) {
853 cache->block_entries = static_cast<FileDirEntry **>(
854 MEM_realloc_uninitialized(cache->block_entries, sizeof(*cache->block_entries) * new_size));
855 }
856
857 cache->misc_entries.clear();
858 cache->misc_entries.reserve(new_size);
859 if (new_size != cache->size) {
860 cache->misc_entries_indices = static_cast<int *>(MEM_realloc_uninitialized(
861 cache->misc_entries_indices, sizeof(*cache->misc_entries_indices) * new_size));
862 }
863 std::fill_n(cache->misc_entries_indices, new_size, -1);
864
865 cache->uids.clear();
866 cache->uids.reserve(new_size * 2);
867
868 cache->size = new_size;
869
870 for (FileDirEntry &entry : cache->cached_entries.items_mutable()) {
871 filelist_entry_free(&entry);
872 }
873 cache->cached_entries.clear_no_delete();
874}
875
876FileList *filelist_new(short type, const bool is_from_global_asset_list)
877{
878 FileList *p = MEM_new<FileList>(__func__);
879
880 p->filelist_cache = MEM_new<FileListEntryCache>("FileListEntryCache");
881
884 filelist_settype(p, type);
885 if (is_from_global_asset_list) {
887 }
888
889 return p;
890}
891
892void filelist_settype(FileList *filelist, short type)
893{
894 if (filelist->type == type) {
895 return;
896 }
897
898 filelist->type = eFileSelectType(type);
899 filelist->tags = 0;
900 filelist->indexer = &file_indexer_noop;
901 filelist->check_dir_fn = nullptr;
902 filelist->start_job_fn = nullptr;
903 filelist->timer_step_fn = nullptr;
904 filelist->read_job_fn = nullptr;
905 filelist->prepare_filter_fn = nullptr;
906 filelist->filter_fn = nullptr;
907
908 switch (filelist->type) {
909 case FILE_LOADLIB:
911 break;
914 break;
915 case FILE_MAIN_ASSET:
917 break;
920 break;
923 break;
926 break;
927 default:
929 break;
930 }
931
932 filelist->flags |= FL_FORCE_RESET;
933}
934
936{
937 /* The AssetLibraryService owns the AssetLibrary pointer, so no need for us to free it. */
938 filelist->asset_library = nullptr;
939 file_delete_asset_catalog_filter_settings(&filelist->filter_data.asset_catalog_filter);
940}
941
943 const bool do_asset_library,
944 const bool do_cache,
945 const bool do_selection)
946{
947 if (!filelist) {
948 return;
949 }
950
952
953 if (do_cache) {
955 }
956
957 filelist_intern_free(filelist);
958
960
961 if (do_selection && filelist->selection_state) {
962 BLI_ghash_clear(filelist->selection_state, nullptr, nullptr);
963 }
964
965 if (do_asset_library) {
967 }
968}
969
971 const bool do_asset_library,
972 const bool do_cache,
973 const bool do_selection)
974{
975 if (!filelist || !(filelist->tags & FILELIST_TAGS_USES_MAIN_DATA)) {
976 return;
977 }
979 return;
980 }
981 const int removed_files = filelist_intern_free_main_files(filelist);
982 /* File list contains no main files to clear. */
983 if (removed_files == 0) {
984 return;
985 }
986
988
989 if (do_cache) {
991 }
992
993 filelist->filelist.entries_num -= removed_files;
996
997 if (do_selection && filelist->selection_state) {
998 BLI_ghash_clear(filelist->selection_state, nullptr, nullptr);
999 }
1000
1001 if (do_asset_library) {
1003 }
1004}
1005
1007{
1008 filelist_clear_ex(filelist, true, true, true);
1009}
1010
1012{
1013 /* Do a full clear if needed. */
1014 if (filelist->flags & FL_FORCE_RESET) {
1015 filelist_clear(filelist);
1016 return;
1017 }
1018
1019 if (filelist->flags & FL_FORCE_RESET_MAIN_FILES) {
1020 filelist_clear_main_files(filelist, false, true, false);
1021 return;
1022 }
1023}
1024
1026{
1027 if (!filelist) {
1028 printf("Attempting to delete empty filelist.\n");
1029 return;
1030 }
1031
1032 /* No need to clear cache & selection_state, we free them anyway. */
1033 filelist_clear_ex(filelist, true, false, false);
1034 MEM_delete(filelist->filelist_cache);
1035
1036 if (filelist->selection_state) {
1037 BLI_ghash_free(filelist->selection_state, nullptr, nullptr);
1038 filelist->selection_state = nullptr;
1039 }
1040
1041 MEM_SAFE_DELETE(filelist->asset_library_ref);
1042
1043 memset(&filelist->filter_data, 0, sizeof(filelist->filter_data));
1044
1045 filelist->flags &= ~(FL_NEED_SORTING | FL_NEED_FILTERING);
1046
1047 MEM_delete(filelist);
1048}
1049
1051{
1052 return filelist->asset_library;
1053}
1054
1056{
1057 if (filelist->libfiledata) {
1059 }
1060 filelist->libfiledata = nullptr;
1061}
1062
1063BlendHandle *filelist_lib(FileList *filelist)
1064{
1065 return filelist->libfiledata;
1066}
1067
1069{
1070 return filelist->filelist.entries_num;
1071}
1072
1073const char *fileentry_uiname(const char *root, FileListInternEntry *entry, char *buff)
1074{
1075 if (asset_system::AssetRepresentation *asset = entry->get_asset()) {
1076 const StringRefNull asset_name = asset->get_name();
1077 return BLI_strdupn(asset_name.c_str(), asset_name.size());
1078 }
1079
1080 const char *relpath = entry->relpath;
1081 const eFileSel_File_Types typeflag = entry->typeflag;
1082 char *name = nullptr;
1083
1084 if (typeflag & FILE_TYPE_FTFONT && !(typeflag & FILE_TYPE_BLENDERLIB)) {
1085 if (entry->redirection_path) {
1087 }
1088 else {
1089 char abspath[FILE_MAX_LIBEXTRA];
1090 BLI_path_join(abspath, sizeof(abspath), root, relpath);
1091 name = BLF_display_name_from_file(abspath);
1092 }
1093 if (name) {
1094 /* Allocated string, so no need to #BLI_strdup. */
1095 return name;
1096 }
1097 }
1098
1099 if (typeflag & FILE_TYPE_BLENDERLIB) {
1100 char abspath[FILE_MAX_LIBEXTRA];
1101 char *group;
1102
1103 BLI_path_join(abspath, sizeof(abspath), root, relpath);
1104 BKE_blendfile_library_path_explode(abspath, buff, &group, &name);
1105 if (!name) {
1106 name = group;
1107 }
1108 }
1109 /* Depending on platforms, 'my_file.blend/..' might be viewed as dir or not... */
1110 if (!name) {
1111 if (typeflag & FILE_TYPE_DIR) {
1112 name = const_cast<char *>(relpath);
1113 }
1114 else {
1115 name = const_cast<char *>(BLI_path_basename(relpath));
1116 }
1117 }
1118 BLI_assert(name);
1119
1120 return BLI_strdup(name);
1121}
1122
1123const char *filelist_dir(const FileList *filelist)
1124{
1125 return filelist->filelist.root;
1126}
1127
1128bool filelist_is_dir(const FileList *filelist, const char *path)
1129{
1130 return filelist->check_dir_fn(filelist, const_cast<char *>(path), false);
1131}
1132
1133void filelist_setdir(FileList *filelist, char dirpath[FILE_MAX_LIBEXTRA])
1134{
1135 const bool allow_invalid = filelist->asset_library_ref != nullptr;
1136 BLI_assert(strlen(dirpath) < FILE_MAX_LIBEXTRA);
1137
1140 const bool is_valid_path = filelist->check_dir_fn(filelist, dirpath, !allow_invalid);
1141 BLI_assert(is_valid_path || allow_invalid);
1142 UNUSED_VARS_NDEBUG(is_valid_path);
1143
1144 if (!STREQ(filelist->filelist.root, dirpath)) {
1145 STRNCPY(filelist->filelist.root, dirpath);
1146 filelist->flags |= FL_FORCE_RESET;
1147 }
1148}
1149
1150void filelist_setrecursion(FileList *filelist, const int recursion_level)
1151{
1152 if (filelist->max_recursion != recursion_level) {
1153 filelist->max_recursion = recursion_level;
1154 filelist->flags |= FL_FORCE_RESET;
1155 }
1156}
1157
1158void filelist_entry_glob_tag(FileListInternEntry *entry, const char *filter_glob)
1159{
1160 entry->typeflag &= ~FILE_TYPE_OPERATOR;
1161
1162 if (entry->typeflag & (FILE_TYPE_DIR | FILE_TYPE_BLENDERLIB)) {
1163 return;
1164 }
1165 if (filter_glob[0] == '\0') {
1166 return;
1167 }
1168
1169 /* Aliases & shortcuts match their target, its extension may differ from the link. */
1170 const char *path = entry->redirection_path ? entry->redirection_path : entry->relpath;
1171 if (BLI_path_extension_check_glob(path, filter_glob)) {
1172 entry->typeflag |= FILE_TYPE_OPERATOR;
1173 }
1174}
1175
1177{
1178 for (FileListInternEntry &entry : filelist->filelist_intern.entries) {
1179 filelist_entry_glob_tag(&entry, filelist->filter_glob);
1180 }
1181
1182 filelist->flags &= ~FL_NEED_RESET_GLOB;
1183}
1184
1185void filelist_setglob(FileList *filelist, const char *filter_glob)
1186{
1187 /* The glob is stored in #FileListInternEntry.typeflag, so filtering again isn't enough.
1188 * Re-tag the entries, reading the directory again would be needlessly heavy. */
1189
1190 if (!STREQ(filelist->filter_glob, filter_glob)) {
1191 STRNCPY(filelist->filter_glob, filter_glob);
1192 filelist->flags |= FL_NEED_RESET_GLOB;
1194 }
1195}
1196
1198{
1199 return (filelist->flags & (FL_FORCE_RESET | FL_FORCE_RESET_MAIN_FILES)) != 0;
1200}
1201
1203{
1204 filelist->flags |= FL_FORCE_RESET;
1205}
1206
1208{
1209 if (!(filelist->tags & FILELIST_TAGS_USES_MAIN_DATA)) {
1210 return;
1211 }
1212 filelist->flags |= FL_FORCE_RESET_MAIN_FILES;
1213}
1214
1216{
1217 filelist->flags |= FL_RELOAD_ASSET_LIBRARY;
1218}
1219
1220bool filelist_is_ready(const FileList *filelist)
1221{
1222 return (filelist->flags & FL_IS_READY) != 0;
1223}
1224
1225bool filelist_pending(const FileList *filelist)
1226{
1227 return (filelist->flags & FL_IS_PENDING) != 0;
1228}
1229
1231{
1232 return (filelist->tags & FILELIST_TAGS_USES_MAIN_DATA) != 0;
1233}
1234
1236{
1237 if (!filelist_needs_force_reset(filelist) || !filelist_needs_reading(filelist)) {
1238 filelist_sort(filelist);
1239 filelist_filter(filelist);
1240 }
1241
1242 return filelist->filelist.entries_filtered_num;
1243}
1244
1246{
1248 FileListEntryCache *cache = filelist->filelist_cache;
1250
1251 ret = MEM_new<FileDirEntry>(__func__);
1252
1253 ret->size = uint64_t(entry->st.st_size);
1254 ret->time = int64_t(entry->st.st_mtime);
1255
1256 ret->relpath = BLI_strdup(entry->relpath);
1257 if (entry->free_name) {
1258 ret->name = BLI_strdup(entry->name);
1259 ret->flags |= FILE_ENTRY_NAME_FREE;
1260 }
1261 else {
1262 ret->name = entry->name;
1263 }
1264 ret->uid = entry->uid;
1265 ret->blentype = entry->blentype;
1266 ret->typeflag = entry->typeflag;
1267 ret->attributes = entry->attributes;
1268 if (entry->redirection_path) {
1269 ret->redirection_path = BLI_strdup(entry->redirection_path);
1270 }
1271 ret->id = entry->local_data.id;
1272 ret->asset = entry->get_asset();
1273 /* For some file types the preview is already available. */
1274 if (entry->local_data.preview_image &&
1276 {
1277 ImBuf *ibuf = BKE_previewimg_to_imbuf(entry->local_data.preview_image, ICON_SIZE_PREVIEW);
1278 if (ibuf) {
1279 ret->preview_icon_id = BKE_icon_imbuf_create(ibuf);
1280 }
1281 }
1282 if (entry->blenderlib_has_no_preview) {
1284 }
1285 BLI_addtail(&cache->cached_entries, ret);
1286 return ret;
1287}
1288
1290{
1291 BLI_remlink(&filelist->filelist_cache->cached_entries, entry);
1292 filelist_entry_free(entry);
1293}
1294
1296{
1297 /* If the file is cached, we can get it from either the block or the misc entry storage. */
1298
1299 if (index >= cache->block_start_index && index < cache->block_end_index) {
1300 const int idx = (index - cache->block_start_index + cache->block_cursor) % cache->size;
1301 return cache->block_entries[idx];
1302 }
1303
1304 return cache->misc_entries.lookup_default(index, nullptr);
1305}
1306
1307FileDirEntry *filelist_file_ex(FileList *filelist, const int index, const bool use_request)
1308{
1309 FileDirEntry *ret = nullptr;
1310 FileListEntryCache *cache = filelist->filelist_cache;
1311 int old_index;
1312
1313 if ((index < 0) || (index >= filelist->filelist.entries_filtered_num)) {
1314 return ret;
1315 }
1316
1317 if ((ret = filelist_cache_file_lookup(cache, index))) {
1318 return ret;
1319 }
1320
1321 if (!use_request) {
1322 return nullptr;
1323 }
1324
1325 // printf("requesting file %d (not yet cached)\n", index);
1326
1327 /* Else, we have to add new entry to 'misc' cache - and possibly make room for it first! */
1329 old_index = cache->misc_entries_indices[cache->misc_cursor];
1330 if (FileDirEntry *old = cache->misc_entries.pop_default(old_index, nullptr)) {
1331 cache->uids.remove(old->uid);
1332 filelist_file_release_entry(filelist, old);
1333 }
1334 cache->misc_entries.add(index, ret);
1335 cache->uids.add(ret->uid, ret);
1336
1337 cache->misc_entries_indices[cache->misc_cursor] = index;
1338 cache->misc_cursor = (cache->misc_cursor + 1) % cache->size;
1339
1340#if 0 /* Actually no, only block cached entries should have preview IMHO. */
1341 if (cache->previews_pool) {
1343 }
1344#endif
1345
1346 return ret;
1347}
1348
1350{
1351 return filelist_file_ex(filelist, index, true);
1352}
1353
1354int filelist_file_find_path(FileList *filelist, const char *filename)
1355{
1357 return -1;
1358 }
1359
1360 /* XXX TODO: Cache could probably use a ghash on paths too? Not really urgent though.
1361 * This is only used to find again renamed entry,
1362 * annoying but looks hairy to get rid of it currently. */
1363
1364 for (int fidx = 0; fidx < filelist->filelist.entries_filtered_num; fidx++) {
1365 FileListInternEntry *entry = filelist->filelist_intern.filtered[fidx];
1366 if (STREQ(entry->relpath, filename)) {
1367 return fidx;
1368 }
1369 }
1370
1371 return -1;
1372}
1373
1374int filelist_file_find_id(const FileList *filelist, const ID *id)
1375{
1377 return -1;
1378 }
1379
1380 for (int fidx = 0; fidx < filelist->filelist.entries_filtered_num; fidx++) {
1381 FileListInternEntry *entry = filelist->filelist_intern.filtered[fidx];
1382 if (entry->local_data.id == id) {
1383 return fidx;
1384 }
1385 }
1386
1387 return -1;
1388}
1389
1391{
1392 BLI_assert(index >= 0 && index < filelist->filelist.entries_filtered_num);
1393 return filelist->filelist_intern.filtered[index];
1394}
1395
1396ID *filelist_entry_get_id(const FileList *filelist, const int index)
1397{
1398 const FileListInternEntry *intern_entry = filelist_entry_intern_get(filelist, index);
1399 return intern_entry->local_data.id;
1400}
1401
1403 const FileList *filelist, const int index)
1404{
1405 const FileListInternEntry *intern_entry = filelist_entry_intern_get(filelist, index);
1406 return intern_entry->get_asset();
1407}
1408
1410{
1411 return file->id;
1412}
1413
1414const char *filelist_entry_get_relpath(const FileList *filelist, int index)
1415{
1416 const FileListInternEntry *intern_entry = filelist_entry_intern_get(filelist, index);
1417 return intern_entry->relpath;
1418}
1419
1420#define FILE_UID_UNSET 0
1421
1423{
1424 /* Using an atomic operation to avoid having to lock thread...
1425 * Note that we do not really need this here currently, since there is a single listing thread,
1426 * but better remain consistent about threading! */
1428}
1429
1431{
1432 FileUID unset_uid;
1433 filelist_uid_unset(&unset_uid);
1434 return unset_uid != uid;
1435}
1436
1438{
1439 *r_uid = FILE_UID_UNSET;
1440}
1441
1442void filelist_file_cache_slidingwindow_set(FileList *filelist, size_t window_size)
1443{
1444 /* Always keep it power of 2, in [256, 8192] range for now,
1445 * cache being app. twice bigger than requested window. */
1446 size_t size = 256;
1447 window_size *= 2;
1448
1449 while (size < window_size && size < 8192) {
1450 size *= 2;
1451 }
1452
1453 if (size != filelist->filelist_cache->size) {
1454 filelist_cache_clear(filelist->filelist_cache, size);
1455 }
1456}
1457
1458/* Helpers, low-level, they assume cursor + size <= cache_size */
1460 const int start_index,
1461 const int size,
1462 int cursor)
1463{
1464 FileListEntryCache *cache = filelist->filelist_cache;
1465
1466 int i, idx;
1467
1468 for (i = 0, idx = start_index; i < size; i++, idx++, cursor++) {
1469 FileDirEntry *entry;
1470
1471 /* That entry might have already been requested and stored in misc cache... */
1472 if ((entry = cache->misc_entries.pop_default(idx, nullptr)) == nullptr) {
1473 entry = filelist_file_create_entry(filelist, idx);
1474 cache->uids.add(entry->uid, entry);
1475 }
1476 cache->block_entries[cursor] = entry;
1477 }
1478 return true;
1479}
1480
1481static void filelist_file_cache_block_release(FileList *filelist, const int size, int cursor)
1482{
1483 FileListEntryCache *cache = filelist->filelist_cache;
1484
1485 int i;
1486
1487 for (i = 0; i < size; i++, cursor++) {
1488 FileDirEntry *entry = cache->block_entries[cursor];
1489#if 0
1490 printf("%s: release cacheidx %d (%%p %%s)\n",
1491 __func__,
1492 cursor /*, cache->block_entries[cursor], cache->block_entries[cursor]->relpath*/);
1493#endif
1494 cache->uids.remove(entry->uid);
1495 filelist_file_release_entry(filelist, entry);
1496#ifndef NDEBUG
1497 cache->block_entries[cursor] = nullptr;
1498#endif
1499 }
1500}
1501
1502bool filelist_file_cache_block(FileList *filelist, const int index)
1503{
1504 FileListEntryCache *cache = filelist->filelist_cache;
1505 const size_t cache_size = cache->size;
1506
1507 const int entries_num = filelist->filelist.entries_filtered_num;
1508 int start_index = max_ii(0, index - (cache_size / 2));
1509 int end_index = min_ii(entries_num, index + (cache_size / 2));
1510 int i;
1511 const bool full_refresh = (filelist->flags & FL_IS_READY) == 0;
1512
1513 if ((index < 0) || (index >= entries_num)) {
1514 // printf("Wrong index %d ([%d:%d])", index, 0, entries_num);
1515 return false;
1516 }
1517
1518 /* Maximize cached range! */
1519 if ((end_index - start_index) < cache_size) {
1520 if (start_index == 0) {
1521 end_index = min_ii(entries_num, start_index + cache_size);
1522 }
1523 else if (end_index == entries_num) {
1524 start_index = max_ii(0, end_index - cache_size);
1525 }
1526 }
1527
1528 BLI_assert((end_index - start_index) <= cache_size);
1529
1530 // printf("%s: [%d:%d] around index %d (current cache: [%d:%d])\n", __func__,
1531 // start_index, end_index, index, cache->block_start_index, cache->block_end_index);
1532
1533 /* If we have something to (re)cache... */
1534 if (full_refresh || (start_index != cache->block_start_index) ||
1535 (end_index != cache->block_end_index))
1536 {
1537 if (full_refresh || (start_index >= cache->block_end_index) ||
1538 (end_index <= cache->block_start_index))
1539 {
1540 int size1 = cache->block_end_index - cache->block_start_index;
1541 int size2 = 0;
1542 int idx1 = cache->block_cursor, idx2 = 0;
1543
1544 // printf("Full Recaching!\n");
1545
1546 if (cache->flags & FLC_PREVIEWS_ACTIVE) {
1548 }
1549
1550 if (idx1 + size1 > cache_size) {
1551 size2 = idx1 + size1 - cache_size;
1552 size1 -= size2;
1553 filelist_file_cache_block_release(filelist, size2, idx2);
1554 }
1555 filelist_file_cache_block_release(filelist, size1, idx1);
1556
1557 cache->block_start_index = cache->block_end_index = cache->block_cursor = 0;
1558
1559 /* New cached block does not overlap existing one, simple. */
1560 if (!filelist_file_cache_block_create(filelist, start_index, end_index - start_index, 0)) {
1561 return false;
1562 }
1563
1564 cache->block_start_index = start_index;
1565 cache->block_end_index = end_index;
1566 }
1567 else {
1568 // printf("Partial Recaching!\n");
1569
1570 /* At this point, we know we keep part of currently cached entries, so update previews
1571 * if needed, and remove everything from working queue - we'll add all newly needed
1572 * entries at the end. */
1573 if (cache->flags & FLC_PREVIEWS_ACTIVE) {
1576 }
1577
1578 // printf("\tpreview cleaned up...\n");
1579
1580 if (start_index > cache->block_start_index) {
1581 int size1 = start_index - cache->block_start_index;
1582 int size2 = 0;
1583 int idx1 = cache->block_cursor, idx2 = 0;
1584
1585 // printf("\tcache releasing: [%d:%d] (%d, %d)\n",
1586 // cache->block_start_index, cache->block_start_index + size1,
1587 // cache->block_cursor, size1);
1588
1589 if (idx1 + size1 > cache_size) {
1590 size2 = idx1 + size1 - cache_size;
1591 size1 -= size2;
1592 filelist_file_cache_block_release(filelist, size2, idx2);
1593 }
1594 filelist_file_cache_block_release(filelist, size1, idx1);
1595
1596 cache->block_cursor = (idx1 + size1 + size2) % cache_size;
1597 cache->block_start_index = start_index;
1598 }
1599 if (end_index < cache->block_end_index) {
1600 int size1 = cache->block_end_index - end_index;
1601 int size2 = 0;
1602 int idx1, idx2 = 0;
1603
1604#if 0
1605 printf("\tcache releasing: [%d:%d] (%d)\n",
1606 cache->block_end_index - size1,
1607 cache->block_end_index,
1608 cache->block_cursor);
1609#endif
1610
1611 idx1 = (cache->block_cursor + end_index - cache->block_start_index) % cache_size;
1612 if (idx1 + size1 > cache_size) {
1613 size2 = idx1 + size1 - cache_size;
1614 size1 -= size2;
1615 filelist_file_cache_block_release(filelist, size2, idx2);
1616 }
1617 filelist_file_cache_block_release(filelist, size1, idx1);
1618
1619 cache->block_end_index = end_index;
1620 }
1621
1622 // printf("\tcache cleaned up...\n");
1623
1624 if (start_index < cache->block_start_index) {
1625 /* Add (request) needed entries before already cached ones. */
1626 /* NOTE: We need some index black magic to wrap around (cycle)
1627 * inside our cache_size array... */
1628 int size1 = cache->block_start_index - start_index;
1629 int size2 = 0;
1630 int idx1, idx2;
1631
1632 if (size1 > cache->block_cursor) {
1633 size2 = size1;
1634 size1 -= cache->block_cursor;
1635 size2 -= size1;
1636 idx2 = 0;
1637 idx1 = cache_size - size1;
1638 }
1639 else {
1640 idx1 = cache->block_cursor - size1;
1641 }
1642
1643 if (size2) {
1644 if (!filelist_file_cache_block_create(filelist, start_index + size1, size2, idx2)) {
1645 return false;
1646 }
1647 }
1648 if (!filelist_file_cache_block_create(filelist, start_index, size1, idx1)) {
1649 return false;
1650 }
1651
1652 cache->block_cursor = idx1;
1653 cache->block_start_index = start_index;
1654 }
1655 // printf("\tstart-extended...\n");
1656 if (end_index > cache->block_end_index) {
1657 /* Add (request) needed entries after already cached ones. */
1658 /* NOTE: We need some index black magic to wrap around (cycle)
1659 * inside our cache_size array... */
1660 int size1 = end_index - cache->block_end_index;
1661 int size2 = 0;
1662 int idx1, idx2;
1663
1664 idx1 = (cache->block_cursor + end_index - cache->block_start_index - size1) % cache_size;
1665 if ((idx1 + size1) > cache_size) {
1666 size2 = size1;
1667 size1 = cache_size - idx1;
1668 size2 -= size1;
1669 idx2 = 0;
1670 }
1671
1672 if (size2) {
1673 if (!filelist_file_cache_block_create(filelist, end_index - size2, size2, idx2)) {
1674 return false;
1675 }
1676 }
1677 if (!filelist_file_cache_block_create(filelist, end_index - size1 - size2, size1, idx1)) {
1678 return false;
1679 }
1680
1681 cache->block_end_index = end_index;
1682 }
1683
1684 // printf("\tend-extended...\n");
1685 }
1686 }
1687 else if ((cache->block_center_index != index) && (cache->flags & FLC_PREVIEWS_ACTIVE)) {
1688 /* We try to always preview visible entries first, so 'restart' preview background task. */
1691 }
1692
1693 // printf("Re-queueing previews...\n");
1694
1695 if (cache->flags & FLC_PREVIEWS_ACTIVE) {
1696 /* Note we try to preview first images around given index - i.e. assumed visible ones. */
1697 int block_index = cache->block_cursor + (index - start_index);
1698 int offs_max = max_ii(end_index - index, index - start_index);
1699 for (i = 0; i <= offs_max; i++) {
1700 int offs = i;
1701 do {
1702 int offs_idx = index + offs;
1703 if (start_index <= offs_idx && offs_idx < end_index) {
1704 int offs_block_idx = (block_index + offs) % int(cache_size);
1705 filelist_cache_previews_push(filelist, cache->block_entries[offs_block_idx], offs_idx);
1706 }
1707 } while ((offs = -offs) < 0); /* Switch between negative and positive offset. */
1708 }
1709 }
1710
1711 cache->block_center_index = index;
1712
1713 // printf("%s Finished!\n", __func__);
1714
1715 return true;
1716}
1717
1718void filelist_cache_previews_set(FileList *filelist, const bool use_previews)
1719{
1720 FileListEntryCache *cache = filelist->filelist_cache;
1721
1722 if (use_previews == ((cache->flags & FLC_PREVIEWS_ACTIVE) != 0)) {
1723 return;
1724 }
1725 /* Do not start preview work while listing, gives nasty flickering! */
1726 if (use_previews && (filelist->flags & FL_IS_READY)) {
1727 cache->flags |= FLC_PREVIEWS_ACTIVE;
1728
1729 BLI_assert((cache->previews_pool == nullptr) && (cache->previews_done == nullptr) &&
1730 (cache->previews_todo_count == 0));
1731
1732 // printf("%s: Init Previews...\n", __func__);
1733
1734 /* No need to populate preview queue here, filelist_file_cache_block() handles this. */
1735 }
1736 else {
1737 // printf("%s: Clear Previews...\n", __func__);
1738
1740 }
1741}
1742
1744{
1745 FileListEntryCache *cache = filelist->filelist_cache;
1746 TaskPool *pool = cache->previews_pool;
1747 bool changed = false;
1748
1749 if (!pool) {
1750 return changed;
1751 }
1752
1753 // printf("%s: Update Previews...\n", __func__);
1754
1755 while (!BLI_thread_queue_is_empty(cache->previews_done)) {
1756 FileListEntryPreview *preview = static_cast<FileListEntryPreview *>(
1758 FileDirEntry *entry;
1759
1760 /* Paranoid (should never happen currently
1761 * since we consume this queue from a single thread), but... */
1762 if (!preview) {
1764 continue;
1765 }
1766 /* entry might have been removed from cache in the mean time,
1767 * we do not want to cache it again here. */
1768 entry = filelist_file_ex(filelist, preview->index, false);
1769
1771 "Online assets shouldn't use the file preview loading system");
1772
1773 // printf("%s: %d - %s - %p\n", __func__, preview->index, preview->filepath, preview->img);
1774
1775 if (entry) {
1776 if (preview->icon_id) {
1777 /* The FILE_ENTRY_PREVIEW_LOADING flag should have prevented any other asynchronous
1778 * process from trying to generate the same preview icon. */
1779 BLI_assert_msg(!entry->preview_icon_id, "Preview icon should not have been generated yet");
1780
1781 /* Move ownership over icon. */
1782 entry->preview_icon_id = preview->icon_id;
1783 preview->icon_id = 0;
1784 }
1785 else {
1786 /* We want to avoid re-processing this entry continuously!
1787 * Note that, since entries only live in cache,
1788 * preview will be retried quite often anyway. */
1790 }
1792 changed = true;
1793 }
1794 else {
1795 BKE_icon_delete(preview->icon_id);
1796 }
1797
1798 MEM_delete(preview);
1799 cache->previews_todo_count--;
1800 }
1801
1802 return changed;
1803}
1804
1806{
1807 FileListEntryCache *cache = filelist->filelist_cache;
1808
1809 return (cache->previews_pool != nullptr);
1810}
1811
1813{
1814 FileListEntryCache *cache = filelist->filelist_cache;
1815 if ((cache->flags & FLC_PREVIEWS_ACTIVE) == 0) {
1816 /* There are no previews. */
1817 return false;
1818 }
1819
1820 return (cache->previews_pool == nullptr) || (cache->previews_done == nullptr) ||
1821 (cache->previews_todo_count == 0);
1822}
1823
1824/* would recognize .blend as well */
1825static bool file_is_blend_backup(const char *str)
1826{
1827 const size_t a = strlen(str);
1828 size_t b = 7;
1829 bool retval = false;
1830
1831 if (a == 0 || b >= a) {
1832 /* pass */
1833 }
1834 else {
1835 const char *loc;
1836
1837 if (a > b + 1) {
1838 b++;
1839 }
1840
1841 /* allow .blend1 .blend2 .blend32 */
1842 loc = BLI_strcasestr(str + a - b, ".blend");
1843
1844 if (loc) {
1845 retval = true;
1846 }
1847 }
1848
1849 return retval;
1850}
1851
1852int ED_path_extension_type(const char *path)
1853{
1854 /* ATTENTION: Never return OR'ed bit-flags here, always return a single enum value! Some code
1855 * using this may do `ELEM()`-like checks. */
1856
1858 return FILE_TYPE_BLENDER;
1859 }
1860 if (file_is_blend_backup(path)) {
1862 }
1863#ifdef __APPLE__
1865 /* Application bundle */
1866 ".app",
1867 /* Safari in-progress/paused download */
1868 ".download",
1869 nullptr))
1870 {
1871 return FILE_TYPE_BUNDLE;
1872 }
1873#endif
1874 if (BLI_path_extension_check(path, ".py")) {
1875 return FILE_TYPE_PYSCRIPT;
1876 }
1878 ".txt",
1879 ".glsl",
1880 ".osl",
1881 ".data",
1882 ".pov",
1883 ".ini",
1884 ".mcr",
1885 ".inc",
1886 ".fountain",
1887 ".toml",
1888 nullptr))
1889 {
1890 return FILE_TYPE_TEXT;
1891 }
1892
1893 /* NOTE: While `.ttc` & `.otc` files can be loaded, only a single "face" is supported,
1894 * users will have to extract bold/italic etc manually for Blender to use them, see #44254. */
1895 if (BLI_path_extension_check_n(path, ".ttf", ".pfb", ".otf", ".woff", ".woff2", nullptr)) {
1896 return FILE_TYPE_FTFONT;
1897 }
1898 if (BLI_path_extension_check(path, ".btx")) {
1899 return FILE_TYPE_BTX;
1900 }
1901 if (BLI_path_extension_check(path, ".abc")) {
1902 return FILE_TYPE_ALEMBIC;
1903 }
1904 if (BLI_path_extension_check_n(path, ".usd", ".usda", ".usdc", ".usdz", nullptr)) {
1905 return FILE_TYPE_USD;
1906 }
1907 if (BLI_path_extension_check(path, ".vdb")) {
1908 return FILE_TYPE_VOLUME;
1909 }
1910 if (BLI_path_extension_check(path, ".zip")) {
1911 return FILE_TYPE_ARCHIVE;
1912 }
1914 ".obj",
1915 ".mtl",
1916 ".3ds",
1917 ".fbx",
1918 ".glb",
1919 ".gltf",
1920 ".svg",
1921 ".pdf",
1922 ".ply",
1923 ".stl",
1924 nullptr))
1925 {
1926 return FILE_TYPE_OBJECT_IO;
1927 }
1929 return FILE_TYPE_IMAGE;
1930 }
1931 if (BLI_path_extension_check(path, ".ogg")) {
1932 if (MOV_is_movie_file(path)) {
1933 return FILE_TYPE_MOVIE;
1934 }
1935 return FILE_TYPE_SOUND;
1936 }
1938 return FILE_TYPE_MOVIE;
1939 }
1941 return FILE_TYPE_SOUND;
1942 }
1943 return 0;
1944}
1945
1946int ED_file_extension_icon(const char *path)
1947{
1948 const int type = ED_path_extension_type(path);
1949
1950 switch (type) {
1951 case FILE_TYPE_BLENDER:
1952 return ICON_FILE_BLEND;
1954 return ICON_FILE_BACKUP;
1955 case FILE_TYPE_IMAGE:
1956 return ICON_FILE_IMAGE;
1957 case FILE_TYPE_MOVIE:
1958 return ICON_FILE_MOVIE;
1959 case FILE_TYPE_PYSCRIPT:
1960 return ICON_FILE_SCRIPT;
1961 case FILE_TYPE_SOUND:
1962 return ICON_FILE_SOUND;
1963 case FILE_TYPE_FTFONT:
1964 return ICON_FILE_FONT;
1965 case FILE_TYPE_BTX:
1966 return ICON_FILE_BLANK;
1967 case FILE_TYPE_ALEMBIC:
1969 return ICON_FILE_3D;
1970 case FILE_TYPE_TEXT:
1971 return ICON_FILE_TEXT;
1972 case FILE_TYPE_ARCHIVE:
1973 return ICON_FILE_ARCHIVE;
1974 case FILE_TYPE_VOLUME:
1975 return ICON_FILE_VOLUME;
1976 default:
1977 return ICON_FILE_BLANK;
1978 }
1979}
1980
1982{
1983 return (filelist->filelist.entries_num == FILEDIR_NBR_ENTRIES_UNSET) ||
1985}
1986
1988 const FileDirEntry *entry,
1990 const eDirEntry_SelectFlag flag,
1991 FileCheckType check)
1992{
1993 /* Default nullptr pointer if not found is fine here! */
1994 void **es_p = BLI_ghash_lookup_p(filelist->selection_state, POINTER_FROM_UINT(entry->uid));
1995 eDirEntry_SelectFlag entry_flag = eDirEntry_SelectFlag(es_p ? POINTER_AS_UINT(*es_p) : 0);
1996 const eDirEntry_SelectFlag org_entry_flag = entry_flag;
1997
1998 BLI_assert(entry);
2000
2001 if ((check == CHECK_ALL) || ((check == CHECK_DIRS) && (entry->typeflag & FILE_TYPE_DIR)) ||
2002 ((check == CHECK_FILES) && !(entry->typeflag & FILE_TYPE_DIR)))
2003 {
2004 switch (select) {
2005 case FILE_SEL_REMOVE:
2006 entry_flag &= ~flag;
2007 break;
2008 case FILE_SEL_ADD:
2009 entry_flag |= flag;
2010 break;
2011 case FILE_SEL_TOGGLE:
2012 entry_flag ^= flag;
2013 break;
2014 }
2015 }
2016
2017 if (entry_flag != org_entry_flag) {
2018 if (es_p) {
2019 if (entry_flag) {
2020 *es_p = POINTER_FROM_UINT(entry_flag);
2021 }
2022 else {
2024 filelist->selection_state, POINTER_FROM_UINT(entry->uid), nullptr, nullptr);
2025 }
2026 }
2027 else if (entry_flag) {
2029 filelist->selection_state, POINTER_FROM_UINT(entry->uid), POINTER_FROM_UINT(entry_flag));
2030 }
2031 }
2032
2033 return entry_flag;
2034}
2035
2037 const int index,
2039 const eDirEntry_SelectFlag flag,
2040 FileCheckType check)
2041{
2042 FileDirEntry *entry = filelist_file(filelist, index);
2043
2044 if (entry) {
2045 filelist_entry_select_set(filelist, entry, select, flag, check);
2046 }
2047}
2048
2050 FileSelection *sel,
2052 const eDirEntry_SelectFlag flag,
2053 FileCheckType check)
2054{
2055 /* select all valid files between first and last indicated */
2056 if ((sel->first >= 0) && (sel->first < filelist->filelist.entries_filtered_num) &&
2057 (sel->last >= 0) && (sel->last < filelist->filelist.entries_filtered_num))
2058 {
2059 int current_file;
2060 for (current_file = sel->first; current_file <= sel->last; current_file++) {
2061 filelist_entry_select_index_set(filelist, current_file, select, flag, check);
2062 }
2063 }
2064}
2065
2067 FileDirEntry *entry,
2068 FileCheckType check)
2069{
2070 BLI_assert(entry);
2072
2073 if ((check == CHECK_ALL) || ((check == CHECK_DIRS) && (entry->typeflag & FILE_TYPE_DIR)) ||
2074 ((check == CHECK_FILES) && !(entry->typeflag & FILE_TYPE_DIR)))
2075 {
2076 /* Default nullptr pointer if not found is fine here! */
2079 }
2080
2081 return eDirEntry_SelectFlag(0);
2082}
2083
2085 const int index,
2086 FileCheckType check)
2087{
2088 FileDirEntry *entry = filelist_file(filelist, index);
2089
2090 if (entry) {
2091 return filelist_entry_select_get(filelist, entry, check);
2092 }
2093
2094 return eDirEntry_SelectFlag(0);
2095}
2096
2098{
2099 BLI_assert(index >= 0 && index < filelist->filelist.entries_filtered_num);
2100 FileListInternEntry *intern_entry = filelist->filelist_intern.filtered[index];
2101
2102 /* BLI_ghash_lookup returns nullptr if not found, which gets mapped to 0, which gets mapped to
2103 * "not selected". */
2105 BLI_ghash_lookup(filelist->selection_state, POINTER_FROM_UINT(intern_entry->uid))));
2106
2107 return selection_state != 0;
2108}
2109
2112 const eDirEntry_SelectFlag flag,
2113 FileCheckType check)
2114{
2115 if ((filelist->filter_data.flags & FLF_HIDE_PARENT) == 0) {
2116 filelist_entry_select_index_set(filelist, 0, select, flag, check);
2117 }
2118}
2119
2120bool filelist_islibrary(FileList *filelist, char *dir, char **r_group)
2121{
2122 if (filelist->asset_library) {
2123 return true;
2124 }
2125 return BKE_blendfile_library_path_explode(filelist->filelist.root, dir, r_group, nullptr);
2126}
2127
2128} // namespace blender
Main runtime representation of an asset.
File and directory operations.
#define FILE_ATTR_ANY_LINK
#define BLI_path_join(...)
#define FILE_MAXDIR
#define FILENAME_IS_PARENT(_n)
#define FILE_MAX_LIBEXTRA
Read Blender memory allocation and freeing.
#define C
Definition RandGen.cpp:29
Provides wrapper around system-specific atomic primitives, and some extensions (faked-atomic operatio...
ATOMIC_INLINE uint32_t atomic_add_and_fetch_uint32(uint32_t *p, uint32_t x)
#define BLI_assert_unreachable()
#define POINTER_AS_UINT(i)
#define UNUSED_VARS_NDEBUG(...)
#define SET_FLAG_FROM_TEST(value, test, flag)
#define ELEM(...)
#define POINTER_FROM_UINT(i)
#define BLI_assert_msg(a, msg)
#define STREQ(a, b)
#define MEM_realloc_uninitialized(vmemh, len)
constexpr const char * c_str() const
bool remove_asset(AssetRepresentation &asset)
void ensure_previewable(const bContext &C, ReportList *reports=nullptr)
constexpr bool is_empty() const
constexpr int64_t size() const
#define str(s)
#define FILE_UID_UNSET
Definition filelist.cc:1420
#define FILELIST_ENTRYCACHESIZE_DEFAULT
#define FILEDIR_NBR_ENTRIES_UNSET
bool is_or_contains_remote_libraries(const AssetLibraryReference &reference)
bool contains_assets_from_remote_url(const AssetLibrary &library, StringRef remote_url)
AssetCatalogFilterSettings * file_create_asset_catalog_filter_settings()
std::string filename(const std::string_view &str, size_t pos)
int icon_from_idcode(int idcode)
ImBuf * svg_icon_bitmap(uint icon_id, float size, bool multicolor=false)
BMesh Iterators.
eDirEntry_SelectFlag filelist_entry_select_index_get(FileList *filelist, int index, FileCheckType check)
Definition filelist.cc:2084
void * MEM_new_uninitialized(size_t len, const char *str) ATTR_WARN_UNUSED_RESULT ATTR_ALLOC_SIZE(1) ATTR_NONNULL(2)
UserDef U
Definition blender.cc:58
BLI_assert(slot->slot_subtype.map==BMO_OP_SLOT_SUBTYPE_MAP_FLT)
static bool filelist_file_preview_load_poll(const FileDirEntry *entry)
Definition filelist.cc:690
FSMenu * ED_fsmenu_get()
Definition fsmenu.cc:48
void filelist_set_readjob_all_asset_library(FileList *filelist)
unsigned __int64 uint64_t
Definition BKE_text.h:91
const FileIndexerType file_indexer_noop
__int64 int64_t
Definition BKE_text.h:90
void BLI_thread_queue_nowait(ThreadQueue *queue)
Definition threads.cc:856
char * STRNCPY(char(&dst)[N], const char *src)
static void filelist_clear_main_files(FileList *filelist, const bool do_asset_library, const bool do_cache, const bool do_selection)
Definition filelist.cc:970
static bool file_is_blend_backup(const char *str)
Definition filelist.cc:1825
void IMB_thumb_locks_release()
Definition thumbs.cc:807
int filelist_file_find_path(FileList *filelist, const char *filename)
Definition filelist.cc:1354
@ ICON_SIZE_PREVIEW
void filelist_settype(FileList *filelist, short type)
Definition filelist.cc:892
void filelist_freelib(FileList *filelist)
Definition filelist.cc:1055
void filelist_tag_needs_filtering(FileList *filelist)
@ BLI_THREAD_QUEUE_WORK_PRIORITY_NORMAL
bool filelist_cache_previews_update(FileList *filelist)
Definition filelist.cc:1743
bool filelist_intern_entry_is_main_file(const FileListInternEntry *intern_entry)
Definition filelist.cc:452
int ED_file_icon(const FileDirEntry *file)
Definition filelist.cc:446
unsigned int uint
Definition BKE_text.h:55
void filelist_uid_unset(FileUID *r_uid)
Definition filelist.cc:1437
void * MEM_new_array_uninitialized(size_t len, size_t size, const char *str) ATTR_WARN_UNUSED_RESULT ATTR_ALLOC_SIZE(1
bool BLI_path_abs(char path[FILE_MAX], const char *basepath) ATTR_NONNULL(1
void IMB_thumb_path_unlock(const char *path)
Definition thumbs.cc:836
ImBuf * filelist_file_get_preview_image(const FileDirEntry *file)
Definition filelist.cc:284
bool filelist_is_dir(const FileList *filelist, const char *path)
Definition filelist.cc:1128
void * BLI_thread_queue_pop_timeout(ThreadQueue *queue, int ms)
Definition threads.cc:787
@ FL_ASSETS_INCLUDE_ONLINE
@ FL_RELOAD_ASSET_LIBRARY
@ FL_FORCE_RESET_MAIN_FILES
ImBuf * filelist_geticon_special_file_image(FileList *filelist, int index)
Definition filelist.cc:319
void filelist_entry_parent_select_set(FileList *filelist, FileSelType select, eDirEntry_SelectFlag flag, FileCheckType check)
Definition filelist.cc:2110
static void filelist_cache_preview_runf(TaskPool *__restrict pool, void *taskdata)
Definition filelist.cc:556
int ED_path_extension_type(const char *path)
Definition filelist.cc:1852
bool BKE_blendfile_library_path_explode(const char *path, char *r_dir, char **r_group, char **r_name)
Definition blendfile.cc:94
bool filelist_uid_is_set(const FileUID uid)
Definition filelist.cc:1430
static void filelist_cache_previews_free(FileListEntryCache *cache)
Definition filelist.cc:666
void BLO_blendhandle_close(BlendHandle *bh) ATTR_NONNULL(1)
void * BLI_ghash_lookup(const GHash *gh, const void *key) ATTR_WARN_UNUSED_RESULT
Definition BLI_ghash.cc:735
void filelist_set_readjob_current_file_asset_library(FileList *filelist)
int BLI_path_normalize_dir(char *dir, size_t dir_maxncpy) ATTR_NONNULL(1)
void filelist_online_asset_preview_request(const bContext *C, FileDirEntry *entry)
Definition filelist.cc:722
@ TASK_PRIORITY_LOW
Definition BLI_task_c.hh:60
bool BKE_icon_is_imbuf(int icon_id) ATTR_WARN_UNUSED_RESULT
Definition icons.cc:412
static void filelist_intern_free(FileList *filelist)
Definition filelist.cc:522
void IMB_thumb_locks_acquire()
Definition thumbs.cc:793
static bool filelist_cache_previews_push(FileList *filelist, FileDirEntry *entry, const int index)
Definition filelist.cc:754
bool BLI_thread_queue_is_empty(ThreadQueue *queue)
Definition threads.cc:844
static FileDirEntry * filelist_geticon_get_file(FileList *filelist, const int index)
Definition filelist.cc:277
void filelist_setrecursion(FileList *filelist, int recursion_level)
Definition filelist.cc:1150
static int filelist_intern_free_main_files(FileList *filelist)
Definition filelist.cc:536
struct bUserAssetLibrary * BKE_preferences_asset_library_find_index(const struct UserDef *userdef, int index) ATTR_NONNULL() ATTR_WARN_UNUSED_RESULT
void filelist_set_asset_include_online(FileList *filelist, bool show_online_assets)
Definition filelist.cc:139
void filelist_reset_glob(FileList *filelist)
Definition filelist.cc:1176
char * BLI_strdupn(const char *str, size_t len) ATTR_MALLOC ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1)
const char * BKE_main_blendfile_path_from_global()
Definition main.cc:1063
MINLINE int max_ii(int a, int b)
int ED_file_extension_icon(const char *path)
Definition filelist.cc:1946
@ FILE_SEL_TOGGLE
Definition filelist.hh:39
@ FILE_SEL_REMOVE
Definition filelist.hh:37
@ FILE_SEL_ADD
Definition filelist.hh:38
void filelist_clear_ex(FileList *filelist, bool do_asset_library, bool do_cache, bool do_selection)
Definition filelist.cc:942
void filelist_set_asset_catalog_filter_options(FileList *filelist, eFileSel_Params_AssetCatalogVisibility catalog_visibility, const bUUID *catalog_id)
Definition filelist.cc:163
@ FILE_ENTRY_INVALID_PREVIEW
@ FILE_ENTRY_BLENDERLIB_NO_PREVIEW
@ FILE_ENTRY_PREVIEW_LOADING
void filelist_setdir(FileList *filelist, char dirpath[1282])
void filelist_clear_from_reset_tag(FileList *filelist)
Definition filelist.cc:1011
int filelist_geticon_file_type(FileList *filelist, int index, bool is_main)
Definition filelist.cc:439
asset_system::AssetLibrary * filelist_asset_library(FileList *filelist)
Definition filelist.cc:1050
int char * BLI_strcasestr(const char *s, const char *find) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1
@ ASSET_LIBRARY_CUSTOM
eDirEntry_SelectFlag filelist_entry_select_get(FileList *filelist, FileDirEntry *entry, FileCheckType check)
Definition filelist.cc:2066
void filelist_setglob(FileList *filelist, const char *filter_glob)
Definition filelist.cc:1185
static FileDirEntry * filelist_cache_file_lookup(FileListEntryCache *cache, const int index)
Definition filelist.cc:1295
asset_system::AssetRepresentation * filelist_entry_get_asset_representation(const FileList *filelist, const int index)
Definition filelist.cc:1402
void IMB_thumb_path_lock(const char *path)
Definition thumbs.cc:822
void BLI_ghash_insert(GHash *gh, void *key, void *val)
Definition BLI_ghash.cc:711
FileList * filelist_new(short type, bool is_from_global_asset_list=false)
Definition filelist.cc:876
void filelist_free_icons()
Definition filelist.cc:237
void filelist_set_readjob_essentials_asset_library(FileList *filelist)
void BLI_task_pool_work_and_wait(TaskPool *pool)
Definition task_pool.cc:455
void filelist_cache_clear(FileListEntryCache *cache, size_t new_size)
Definition filelist.cc:846
static FileDirEntry * filelist_file_create_entry(FileList *filelist, const int index)
Definition filelist.cc:1245
void * BLI_task_pool_user_data(TaskPool *pool)
Definition task_pool.cc:460
Global G
Definition blender.cc:57
void ** BLI_ghash_lookup_p(GHash *gh, const void *key) ATTR_WARN_UNUSED_RESULT
Definition BLI_ghash.cc:749
bool MOV_is_movie_file(const char *filepath)
@ FILE_ATTR_TEMPORARY
@ FILE_ATTR_OFFLINE
@ FILE_ATTR_SYSTEM
uint32_t FileUID
Definition filelist.hh:34
void filelist_set_readjob_library(FileList *filelist)
void void void const char * BLI_path_basename(const char *path) ATTR_NONNULL(1) ATTR_WARN_UNUSED_RESULT
@ FILE_ASSET_LIBRARY_ALL
@ FILE_ASSET_LIBRARY_ESSENTIALS
@ FILE_ASSET_LIBRARY_REMOTE
void filelist_set_readjob_remote_asset_library(FileList *filelist)
static int filelist_geticon_file_type_ex(const FileList *filelist, const FileDirEntry *file, const bool is_main, const bool ignore_libdir)
Definition filelist.cc:325
char * BLI_strncpy(char *__restrict dst, const char *__restrict src, size_t dst_maxncpy) ATTR_NONNULL(1
FileDirEntry * filelist_file_ex(FileList *filelist, int index, bool use_request)
Definition filelist.cc:1307
void IMB_freeImBuf(ImBuf *ibuf)
void filelist_set_readjob_directories(FileList *filelist)
void filelist_entry_glob_tag(FileListInternEntry *entry, const char *filter_glob)
Definition filelist.cc:1158
void * MEM_new_zeroed(size_t len, const char *str) ATTR_WARN_UNUSED_RESULT ATTR_ALLOC_SIZE(1) ATTR_NONNULL(2)
FileDirEntry * filelist_file(FileList *filelist, int index)
Definition filelist.cc:1349
bool filelist_cache_previews_done(FileList *filelist)
Definition filelist.cc:1812
void BLI_ghash_free(GHash *gh, GHashKeyFreeFP keyfreefp, GHashValFreeFP valfreefp)
Definition BLI_ghash.cc:866
void filelist_setindexer(FileList *filelist, const FileIndexerType *indexer)
Definition filelist.cc:131
void BLI_remlink(ListBase *listbase, void *vlink) ATTR_NONNULL(1)
Definition listbase.cc:138
bool filelist_needs_force_reset(const FileList *filelist)
Definition filelist.cc:1197
void filelist_entry_select_index_set(FileList *filelist, int index, FileSelType select, eDirEntry_SelectFlag flag, FileCheckType check)
Definition filelist.cc:2036
FileCheckType
Definition filelist.hh:42
@ CHECK_ALL
Definition filelist.hh:45
@ CHECK_DIRS
Definition filelist.hh:43
@ CHECK_FILES
Definition filelist.hh:44
ImBuf * filelist_geticon_special_file_image_ex(const FileDirEntry *file)
Definition filelist.cc:300
bool filelist_islibrary(FileList *filelist, char *dir, char **r_group)
Definition filelist.cc:2120
static void filelist_clear_asset_library(FileList *filelist)
Definition filelist.cc:935
void BLI_ghash_clear(GHash *gh, GHashKeyFreeFP keyfreefp, GHashValFreeFP valfreefp)
Definition BLI_ghash.cc:861
int filelist_needs_reading(const FileList *filelist)
Definition filelist.cc:1981
bool filelist_file_cache_block(FileList *filelist, int index)
Definition filelist.cc:1502
bool filelist_is_ready(const FileList *filelist)
Definition filelist.cc:1220
void filelist_tag_force_reset(FileList *filelist)
Definition filelist.cc:1202
static void filelist_cache_previews_clear(FileListEntryCache *cache)
Definition filelist.cc:639
static void filelist_direntryarr_free(FileDirEntryArr *array)
Definition filelist.cc:486
static void filelist_entry_free(FileDirEntry *entry)
Definition filelist.cc:480
void filelist_setlibrary(FileList *filelist, const AssetLibraryReference *asset_library_ref, FunctionRef< void()> on_change=nullptr)
Definition filelist.cc:203
bool BLI_ghashutil_intcmp(const void *a, const void *b)
void filelist_remote_asset_library_refresh_online_assets_status(const FileList *filelist, StringRef remote_url, StringRef absolute_downloaded_file)
constexpr size_t ARRAY_SIZE(const T(&arg)[N]) noexcept
void filelist_set_readjob_on_disk_asset_library(FileList *filelist)
void BLI_thread_queue_free(ThreadQueue *queue)
Definition threads.cc:638
BlendHandle * filelist_lib(FileList *filelist)
Definition filelist.cc:1063
int filelist_files_ensure(FileList *filelist)
Definition filelist.cc:1235
ThreadQueue * BLI_thread_queue_init()
Definition threads.cc:627
const char * fileentry_uiname(const char *root, FileListInternEntry *entry, char *buff)
Definition filelist.cc:1073
void * BLI_thread_queue_pop(ThreadQueue *queue)
Definition threads.cc:717
int BLI_path_slash_ensure(char *path, size_t path_maxncpy) ATTR_NONNULL(1)
bool filelist_needs_reset_on_main_changes(const FileList *filelist)
Definition filelist.cc:1230
static bool filelist_compare_asset_libraries(const AssetLibraryReference *library_a, const AssetLibraryReference *library_b)
Definition filelist.cc:186
void filelist_tag_reload_asset_library(FileList *filelist)
Definition filelist.cc:1215
@ FILELIST_TAGS_USES_MAIN_DATA
@ FILELIST_TAGS_FROM_GLOBAL_ASSET_LIST
void BLI_task_pool_free(TaskPool *pool)
Definition task_pool.cc:441
bool BKE_previewimg_is_finished(const PreviewImage *prv, int size)
@ THB_SOURCE_IMAGE
Definition IMB_thumbs.hh:33
@ THB_SOURCE_MOVIE
Definition IMB_thumbs.hh:34
@ THB_SOURCE_FONT
Definition IMB_thumbs.hh:36
@ THB_SOURCE_BLEND
Definition IMB_thumbs.hh:35
@ THB_SOURCE_OBJECT_IO
Definition IMB_thumbs.hh:37
static void remote_asset_library_refresh_online_assets_status(const FileList *filelist, const StringRef downloaded_file_abspath)
Definition filelist.cc:77
unsigned int filelist_entry_select_set(const FileList *filelist, const FileDirEntry *entry, FileSelType select, const eDirEntry_SelectFlag flag, FileCheckType check)
Definition filelist.cc:1987
int BKE_icon_imbuf_create(ImBuf *ibuf) ATTR_WARN_UNUSED_RESULT
Definition icons.cc:387
eFileSel_Params_AssetCatalogVisibility
void filelist_filter(FileList *filelist)
void filelist_sort(FileList *filelist)
static void filelist_entry_clear(FileDirEntry *entry)
Definition filelist.cc:459
static void filelist_cache_preview_freef(TaskPool *__restrict, void *taskdata)
Definition filelist.cc:615
bool BKE_previewimg_is_rendering(const PreviewImage *prv, int size)
static FileListInternEntry * filelist_entry_intern_get(const FileList *filelist, const int index)
Definition filelist.cc:1390
bool filelist_file_is_preview_pending(const FileList *filelist, const FileDirEntry *file)
Definition filelist.cc:261
ImBuf * IMB_thumb_manage(const char *file_or_lib_path, ThumbSize size, ThumbSource source, const ThumbCancellationToken *cancel_token=nullptr)
Definition thumbs.cc:601
FileUID filelist_uid_generate(FileList *filelist)
Definition filelist.cc:1422
void BLI_addtail(ListBase *listbase, void *vlink) ATTR_NONNULL(1)
Definition listbase.cc:118
int filelist_file_find_id(const FileList *filelist, const ID *id)
Definition filelist.cc:1374
char * BLI_strdup(const char *str) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1) ATTR_MALLOC
char * BLF_display_name_from_file(const char *filepath) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1)
Definition blf.cc:1115
bool BLI_path_extension_check_array(const char *path, const char **ext_array) ATTR_NONNULL(1
bool BLI_path_extension_check(const char *path, const char *ext) ATTR_NONNULL(1
static ImBuf * gSpecialFileImages[int(SpecialFileImages::_Max)]
Definition filelist.cc:75
bool filelist_cache_previews_running(FileList *filelist)
Definition filelist.cc:1805
ID * filelist_file_get_id(const FileDirEntry *file)
Definition filelist.cc:1409
bool BLI_ghash_remove(GHash *gh, const void *key, GHashKeyFreeFP keyfreefp, GHashValFreeFP valfreefp)
Definition BLI_ghash.cc:792
static ImBuf * filelist_ensure_special_file_image(SpecialFileImages image, int icon)
Definition filelist.cc:291
@ FILE_TYPE_ASSET_ONLINE
@ FILE_TYPE_BLENDER_BACKUP
ImBuf * BKE_previewimg_to_imbuf(const PreviewImage *prv, int size)
bool BKE_blendfile_extension_check(const char *str)
Definition blendfile.cc:88
void filelist_file_cache_slidingwindow_set(FileList *filelist, size_t window_size)
Definition filelist.cc:1442
bool filelist_entry_is_selected(FileList *filelist, int index)
Definition filelist.cc:2097
@ FS_CATEGORY_SYSTEM_BOOKMARKS
static bool filelist_file_cache_block_create(FileList *filelist, const int start_index, const int size, int cursor)
Definition filelist.cc:1459
void filelist_tag_force_reset_mainfiles(FileList *filelist)
Definition filelist.cc:1207
bool BLI_path_extension_check_glob(const char *path, const char *ext_fnmatch) ATTR_NONNULL(1
void filelist_free(FileList *filelist)
Definition filelist.cc:1025
static void filelist_intern_entry_free(FileList *filelist, FileListInternEntry *entry)
Definition filelist.cc:503
@ PRV_RENDERING
Definition DNA_ID.h:622
void filelist_entries_select_index_range_set(FileList *filelist, FileSelection *sel, FileSelType select, eDirEntry_SelectFlag flag, FileCheckType check)
Definition filelist.cc:2049
GHash * BLI_ghash_new(GHashHashFP hashfp, GHashCmpFP cmpfp, const char *info) ATTR_MALLOC ATTR_WARN_UNUSED_RESULT
Definition BLI_ghash.cc:690
void filelist_cache_previews_set(FileList *filelist, bool use_previews)
Definition filelist.cc:1718
unsigned int BLI_ghashutil_inthash_p(const void *ptr)
ReportList * CTX_wm_reports(const bContext *C)
uint64_t BLI_thread_queue_push(ThreadQueue *queue, void *work, ThreadQueueWorkPriority priority)
Definition threads.cc:648
FSMenuEntry * ED_fsmenu_get_category(FSMenu *fsmenu, FSMenuCategory category)
Definition fsmenu.cc:56
void filelist_file_get_full_path(const FileList *filelist, const FileDirEntry *file, char r_filepath[1282])
bool BKE_icon_delete(int icon_id)
Definition icons.cc:545
MINLINE int min_ii(int a, int b)
const char * filelist_dir(const FileList *filelist)
Definition filelist.cc:1123
bool BLI_is_file(const char *path) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL()
Definition storage.cc:469
void BLI_task_pool_push(TaskPool *pool, TaskRunFunction run, void *taskdata, bool free_taskdata, TaskFreeFunction freedata)
Definition task_pool.cc:446
ImBuf * BKE_icon_imbuf_get_buffer(int icon_id) ATTR_WARN_UNUSED_RESULT
Definition icons.cc:397
bool BLI_path_extension_check_n(const char *path,...) ATTR_NONNULL(1) ATTR_SENTINEL(0)
static void filelist_cache_preview_ensure_running(FileListEntryCache *cache)
Definition filelist.cc:628
int filelist_files_num_entries(FileList *filelist)
Definition filelist.cc:1068
ID * filelist_entry_get_id(const FileList *filelist, int index)
Definition filelist.cc:1396
const char * filelist_entry_get_relpath(const FileList *filelist, int index)
Definition filelist.cc:1414
bool filelist_pending(const FileList *filelist)
Definition filelist.cc:1225
static void filelist_file_cache_block_release(FileList *filelist, const int size, int cursor)
Definition filelist.cc:1481
static void filelist_file_release_entry(FileList *filelist, FileDirEntry *entry)
Definition filelist.cc:1289
void filelist_clear(FileList *filelist)
Definition filelist.cc:1006
TaskPool * BLI_task_pool_create_background(void *userdata, eTaskPriority priority)
Definition task_pool.cc:409
struct FileDirEntry * next
asset_system::AssetRepresentation * asset
ListBaseT< FileDirEntry > cached_entries
ThumbCancellationToken previews_cancel_token
Map< int, FileDirEntry * > uids
Map< int, FileDirEntry * > misc_entries
char filepath[FILE_MAX_LIBEXTRA]
ed::asset_browser::AssetCatalogFilterSettings * asset_catalog_filter
std::weak_ptr< asset_system::AssetRepresentation > asset
struct blender::FileListInternEntry::@000065073311321332173152260127375002005026343052 local_data
asset_system::AssetRepresentation * get_asset() const
ListBaseT< FileListInternEntry > entries
FileListInternEntry ** filtered
void(*) prepare_filter_fn(const FileList *filelist, FileListFilter *filter)
void(*) timer_step_fn(FileListReadJob *job_params)
bool(*) check_dir_fn(const FileList *filelist, char dirpath[FILE_MAX_LIBEXTRA], const bool do_change)
void(*) start_job_fn(FileListReadJob *job_params)
AssetLibraryReference * asset_library_ref
void(*) read_job_fn(FileListReadJob *job_params, bool *stop, bool *do_update, float *progress)
FileListEntryCache * filelist_cache
FileDirEntryArr filelist
FileListFilter filter_data
bool(*) filter_fn(FileListInternEntry *file, const char *root, FileListFilter *filter)
BlendHandle * libfiledata
eFileSelectType type
const FileIndexerType * indexer
char filter_glob[FILE_MAXFILE]
FileListIntern filelist_intern
asset_system::AssetLibrary * asset_library
bke::PreviewImageRuntime * runtime
Definition DNA_ID.h:651
Universally Unique Identifier according to RFC4122.