Changeset View
Changeset View
Standalone View
Standalone View
source/blender/blenkernel/intern/asset_catalog.cc
| Show All 13 Lines | |||||
| * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | ||||
| */ | */ | ||||
| /** \file | /** \file | ||||
| * \ingroup bke | * \ingroup bke | ||||
| */ | */ | ||||
| #include "BKE_asset_catalog.hh" | #include "BKE_asset_catalog.hh" | ||||
| #include "BKE_asset_library.h" | |||||
| #include "BKE_preferences.h" | #include "BKE_preferences.h" | ||||
| #include "BLI_fileops.h" | #include "BLI_fileops.h" | ||||
| #include "BLI_path_util.h" | #include "BLI_path_util.h" | ||||
| #include "BLI_string_ref.hh" | #include "BLI_string_ref.hh" | ||||
| #include "DNA_userdef_types.h" | #include "DNA_userdef_types.h" | ||||
| ▲ Show 20 Lines • Show All 259 Lines • ▼ Show 20 Lines | bool AssetCatalogService::write_to_disk_on_blendfile_save(const char *blend_file_path) | ||||
| this->catalog_definition_file_ = construct_cdf_in_memory(cdf_path_to_write); | this->catalog_definition_file_ = construct_cdf_in_memory(cdf_path_to_write); | ||||
| merge_from_disk_before_writing(); | merge_from_disk_before_writing(); | ||||
| return catalog_definition_file_->write_to_disk(); | return catalog_definition_file_->write_to_disk(); | ||||
| } | } | ||||
| CatalogFilePath AssetCatalogService::find_suitable_cdf_path_for_writing( | CatalogFilePath AssetCatalogService::find_suitable_cdf_path_for_writing( | ||||
| const CatalogFilePath &blend_file_path) | const CatalogFilePath &blend_file_path) | ||||
| { | { | ||||
| BLI_assert_msg(!blend_file_path.empty(), | |||||
| "A non-empty .blend file path is required to be able to determine where the " | |||||
| "catalog definition file should be put"); | |||||
| /* Determine the default CDF path in the same directory of the blend file. */ | /* Determine the default CDF path in the same directory of the blend file. */ | ||||
| char blend_dir_path[PATH_MAX]; | char blend_dir_path[PATH_MAX]; | ||||
| BLI_split_dir_part(blend_file_path.c_str(), blend_dir_path, sizeof(blend_dir_path)); | BLI_split_dir_part(blend_file_path.c_str(), blend_dir_path, sizeof(blend_dir_path)); | ||||
| const CatalogFilePath cdf_path_next_to_blend = asset_definition_default_file_path_from_dir( | const CatalogFilePath cdf_path_next_to_blend = asset_definition_default_file_path_from_dir( | ||||
| blend_dir_path); | blend_dir_path); | ||||
| if (BLI_exists(cdf_path_next_to_blend.c_str())) { | if (BLI_exists(cdf_path_next_to_blend.c_str())) { | ||||
| /* - The directory containing the blend file has a blender_assets.cats.txt file? | /* - The directory containing the blend file has a blender_assets.cats.txt file? | ||||
| * -> Merge with & write to that file. */ | * -> Merge with & write to that file. */ | ||||
| return cdf_path_next_to_blend; | return cdf_path_next_to_blend; | ||||
| } | } | ||||
| const bUserAssetLibrary *asset_lib_pref = BKE_preferences_asset_library_containing_path( | /* - There's no definition file next to the .blend file. | ||||
| &U, blend_file_path.c_str()); | * -> Ask the asset library API for an appropriate location. */ | ||||
| if (asset_lib_pref) { | char suitable_root_path[PATH_MAX]; | ||||
| /* - The directory containing the blend file is part of an asset library, as per | BKE_asset_library_find_suitable_root_path_from_path(blend_file_path.c_str(), | ||||
| * the user's preferences? | suitable_root_path); | ||||
| * -> Merge with & write to ${ASSET_LIBRARY_ROOT}/blender_assets.cats.txt */ | |||||
| char asset_lib_cdf_path[PATH_MAX]; | char asset_lib_cdf_path[PATH_MAX]; | ||||
| BLI_path_join(asset_lib_cdf_path, | BLI_path_join(asset_lib_cdf_path, | ||||
| sizeof(asset_lib_cdf_path), | sizeof(asset_lib_cdf_path), | ||||
| asset_lib_pref->path, | suitable_root_path, | ||||
| DEFAULT_CATALOG_FILENAME.c_str(), | DEFAULT_CATALOG_FILENAME.c_str(), | ||||
| NULL); | NULL); | ||||
| return asset_lib_cdf_path; | return asset_lib_cdf_path; | ||||
| } | } | ||||
| /* - Otherwise | |||||
| * -> Create a new file blender_assets.cats.txt next to the blend file. */ | |||||
| return cdf_path_next_to_blend; | |||||
| } | |||||
| std::unique_ptr<AssetCatalogDefinitionFile> AssetCatalogService::construct_cdf_in_memory( | std::unique_ptr<AssetCatalogDefinitionFile> AssetCatalogService::construct_cdf_in_memory( | ||||
| const CatalogFilePath &file_path) | const CatalogFilePath &file_path) | ||||
| { | { | ||||
| auto cdf = std::make_unique<AssetCatalogDefinitionFile>(); | auto cdf = std::make_unique<AssetCatalogDefinitionFile>(); | ||||
| cdf->file_path = file_path; | cdf->file_path = file_path; | ||||
| for (auto &catalog : catalogs_.values()) { | for (auto &catalog : catalogs_.values()) { | ||||
| cdf->add_new(catalog.get()); | cdf->add_new(catalog.get()); | ||||
| ▲ Show 20 Lines • Show All 421 Lines • Show Last 20 Lines | |||||