Changeset View
Changeset View
Standalone View
Standalone View
source/blender/editors/space_file/filelist.c
| Show First 20 Lines • Show All 270 Lines • ▼ Show 20 Lines | typedef struct FileListInternEntry { | ||||
| /** ID type, in case typeflag has FILE_TYPE_BLENDERLIB set. */ | /** ID type, in case typeflag has FILE_TYPE_BLENDERLIB set. */ | ||||
| int blentype; | int blentype; | ||||
| char *relpath; | char *relpath; | ||||
| /** Optional argument for shortcuts, aliases etc. */ | /** Optional argument for shortcuts, aliases etc. */ | ||||
| char *redirection_path; | char *redirection_path; | ||||
| /** not strictly needed, but used during sorting, avoids to have to recompute it there... */ | /** not strictly needed, but used during sorting, avoids to have to recompute it there... */ | ||||
| char *name; | char *name; | ||||
| bool free_name; | |||||
| /** | /** | ||||
| * This is data from the current main, represented by this file. It's crucial that this is | * This is data from the current main, represented by this file. It's crucial that this is | ||||
| * updated correctly on undo, redo and file reading (without UI). The space is responsible to | * updated correctly on undo, redo and file reading (without UI). The space is responsible to | ||||
| * take care of that. | * take care of that. | ||||
| */ | */ | ||||
| struct { | struct { | ||||
| /** When showing local IDs (FILE_MAIN, FILE_MAIN_ASSET), the ID this file entry represents. */ | /** When showing local IDs (FILE_MAIN, FILE_MAIN_ASSET), the ID this file entry represents. */ | ||||
| ▲ Show 20 Lines • Show All 1,074 Lines • ▼ Show 20 Lines | static bool filelist_checkdir_main_assets(struct FileList *UNUSED(filelist), | ||||
| const bool UNUSED(do_change)) | const bool UNUSED(do_change)) | ||||
| { | { | ||||
| /* Main is always valid. */ | /* Main is always valid. */ | ||||
| return true; | return true; | ||||
| } | } | ||||
| static void filelist_entry_clear(FileDirEntry *entry) | static void filelist_entry_clear(FileDirEntry *entry) | ||||
| { | { | ||||
| if (entry->name) { | if (entry->name && ((entry->flags & FILE_ENTRY_NAME_FREE) != 0)) { | ||||
| MEM_freeN(entry->name); | MEM_freeN(entry->name); | ||||
| } | } | ||||
| if (entry->description) { | if (entry->description) { | ||||
| MEM_freeN(entry->description); | MEM_freeN(entry->description); | ||||
| } | } | ||||
| if (entry->relpath) { | if (entry->relpath) { | ||||
| MEM_freeN(entry->relpath); | MEM_freeN(entry->relpath); | ||||
| } | } | ||||
| ▲ Show 20 Lines • Show All 68 Lines • ▼ Show 20 Lines | |||||
| static void filelist_intern_entry_free(FileListInternEntry *entry) | static void filelist_intern_entry_free(FileListInternEntry *entry) | ||||
| { | { | ||||
| if (entry->relpath) { | if (entry->relpath) { | ||||
| MEM_freeN(entry->relpath); | MEM_freeN(entry->relpath); | ||||
| } | } | ||||
| if (entry->redirection_path) { | if (entry->redirection_path) { | ||||
| MEM_freeN(entry->redirection_path); | MEM_freeN(entry->redirection_path); | ||||
| } | } | ||||
| if (entry->name) { | if (entry->name && entry->free_name) { | ||||
| MEM_freeN(entry->name); | MEM_freeN(entry->name); | ||||
| } | } | ||||
| /* If we own the asset-data (it was generated from external file data), free it. */ | /* If we own the asset-data (it was generated from external file data), free it. */ | ||||
| if (entry->imported_asset_data) { | if (entry->imported_asset_data) { | ||||
| BKE_asset_metadata_free(&entry->imported_asset_data); | BKE_asset_metadata_free(&entry->imported_asset_data); | ||||
| } | } | ||||
| MEM_freeN(entry); | MEM_freeN(entry); | ||||
| } | } | ||||
| ▲ Show 20 Lines • Show All 485 Lines • ▼ Show 20 Lines | static FileDirEntry *filelist_file_create_entry(FileList *filelist, const int index) | ||||
| rev = MEM_callocN(sizeof(*rev), __func__); | rev = MEM_callocN(sizeof(*rev), __func__); | ||||
| rev->size = (uint64_t)entry->st.st_size; | rev->size = (uint64_t)entry->st.st_size; | ||||
| rev->time = (int64_t)entry->st.st_mtime; | rev->time = (int64_t)entry->st.st_mtime; | ||||
| ret->entry = rev; | ret->entry = rev; | ||||
| ret->relpath = BLI_strdup(entry->relpath); | ret->relpath = BLI_strdup(entry->relpath); | ||||
| if (entry->free_name) { | |||||
| ret->name = BLI_strdup(entry->name); | ret->name = BLI_strdup(entry->name); | ||||
| ret->flags |= FILE_ENTRY_NAME_FREE; | |||||
| } | |||||
| else { | |||||
| ret->name = entry->name; | |||||
| } | |||||
| ret->description = BLI_strdupcat(filelist->filelist.root, entry->relpath); | ret->description = BLI_strdupcat(filelist->filelist.root, entry->relpath); | ||||
| memcpy(ret->uuid, entry->uuid, sizeof(ret->uuid)); | memcpy(ret->uuid, entry->uuid, sizeof(ret->uuid)); | ||||
| ret->blentype = entry->blentype; | ret->blentype = entry->blentype; | ||||
| ret->typeflag = entry->typeflag; | ret->typeflag = entry->typeflag; | ||||
| ret->attributes = entry->attributes; | ret->attributes = entry->attributes; | ||||
| if (entry->redirection_path) { | if (entry->redirection_path) { | ||||
| ret->redirection_path = BLI_strdup(entry->redirection_path); | ret->redirection_path = BLI_strdup(entry->redirection_path); | ||||
| } | } | ||||
| ▲ Show 20 Lines • Show All 1,205 Lines • ▼ Show 20 Lines | for (entry = entries.first; entry; entry = entry->next) { | ||||
| *((uint32_t *)entry->uuid) = atomic_add_and_fetch_uint32( | *((uint32_t *)entry->uuid) = atomic_add_and_fetch_uint32( | ||||
| (uint32_t *)filelist->filelist_intern.curr_uuid, 1); | (uint32_t *)filelist->filelist_intern.curr_uuid, 1); | ||||
| /* Only thing we change in direntry here, so we need to free it first. */ | /* Only thing we change in direntry here, so we need to free it first. */ | ||||
| MEM_freeN(entry->relpath); | MEM_freeN(entry->relpath); | ||||
| entry->relpath = BLI_strdup(dir + 2); /* + 2 to remove '//' | entry->relpath = BLI_strdup(dir + 2); /* + 2 to remove '//' | ||||
| * added by BLI_path_rel to rel_subdir. */ | * added by BLI_path_rel to rel_subdir. */ | ||||
| entry->name = BLI_strdup(fileentry_uiname(root, entry->relpath, entry->typeflag, dir)); | entry->name = BLI_strdup(fileentry_uiname(root, entry->relpath, entry->typeflag, dir)); | ||||
| entry->free_name = true; | |||||
| /* Here we decide whether current filedirentry is to be listed too, or not. */ | /* Here we decide whether current filedirentry is to be listed too, or not. */ | ||||
| if (max_recursion && (is_lib || (recursion_level <= max_recursion))) { | if (max_recursion && (is_lib || (recursion_level <= max_recursion))) { | ||||
| if (((entry->typeflag & FILE_TYPE_DIR) == 0) || FILENAME_IS_CURRPAR(entry->relpath)) { | if (((entry->typeflag & FILE_TYPE_DIR) == 0) || FILENAME_IS_CURRPAR(entry->relpath)) { | ||||
| /* Skip... */ | /* Skip... */ | ||||
| } | } | ||||
| else if (!is_lib && (recursion_level >= max_recursion) && | else if (!is_lib && (recursion_level >= max_recursion) && | ||||
| ((entry->typeflag & (FILE_TYPE_BLENDER | FILE_TYPE_BLENDER_BACKUP)) == 0)) { | ((entry->typeflag & (FILE_TYPE_BLENDER | FILE_TYPE_BLENDER_BACKUP)) == 0)) { | ||||
| ▲ Show 20 Lines • Show All 97 Lines • ▼ Show 20 Lines | FOREACH_MAIN_ID_BEGIN (current_main, id_iter) { | ||||
| if (!id_iter->asset_data) { | if (!id_iter->asset_data) { | ||||
| continue; | continue; | ||||
| } | } | ||||
| const char *id_code_name = BKE_idtype_idcode_to_name(GS(id_iter->name)); | const char *id_code_name = BKE_idtype_idcode_to_name(GS(id_iter->name)); | ||||
| entry = MEM_callocN(sizeof(*entry), __func__); | entry = MEM_callocN(sizeof(*entry), __func__); | ||||
| entry->relpath = BLI_strdup(id_code_name); | entry->relpath = BLI_strdup(id_code_name); | ||||
| entry->name = BLI_strdup(id_iter->name + 2); | entry->name = id_iter->name + 2; | ||||
| entry->free_name = false; | |||||
| entry->typeflag |= FILE_TYPE_BLENDERLIB | FILE_TYPE_ASSET; | entry->typeflag |= FILE_TYPE_BLENDERLIB | FILE_TYPE_ASSET; | ||||
| entry->blentype = GS(id_iter->name); | entry->blentype = GS(id_iter->name); | ||||
| *((uint32_t *)entry->uuid) = atomic_add_and_fetch_uint32( | *((uint32_t *)entry->uuid) = atomic_add_and_fetch_uint32( | ||||
| (uint32_t *)filelist->filelist_intern.curr_uuid, 1); | (uint32_t *)filelist->filelist_intern.curr_uuid, 1); | ||||
| entry->local_data.preview_image = BKE_asset_metadata_preview_get_from_id(id_iter->asset_data, | entry->local_data.preview_image = BKE_asset_metadata_preview_get_from_id(id_iter->asset_data, | ||||
| id_iter); | id_iter); | ||||
| entry->local_data.id = id_iter; | entry->local_data.id = id_iter; | ||||
| nbr_entries++; | nbr_entries++; | ||||
| ▲ Show 20 Lines • Show All 187 Lines • Show Last 20 Lines | |||||