Select Git revision
development_iskeyfree.py
asset_catalog.cc 35.53 KiB
/* SPDX-License-Identifier: GPL-2.0-or-later */
/** \file
* \ingroup bke
*/
#include <fstream>
#include <set>
#include "BKE_asset_catalog.hh"
#include "BKE_asset_library.h"
#include "BLI_fileops.hh"
#include "BLI_path_util.h"
/* For S_ISREG() and S_ISDIR() on Windows. */
#ifdef WIN32
# include "BLI_winstuff.h"
#endif
#include "CLG_log.h"
static CLG_LogRef LOG = {"bke.asset_service"};
namespace blender::bke {
const CatalogFilePath AssetCatalogService::DEFAULT_CATALOG_FILENAME = "blender_assets.cats.txt";
const int AssetCatalogDefinitionFile::SUPPORTED_VERSION = 1;
const std::string AssetCatalogDefinitionFile::VERSION_MARKER = "VERSION ";
const std::string AssetCatalogDefinitionFile::HEADER =
"# This is an Asset Catalog Definition file for Blender.\n"
"#\n"
"# Empty lines and lines starting with `#` will be ignored.\n"
"# The first non-ignored line should be the version indicator.\n"
"# Other lines are of the format \"UUID:catalog/path/for/assets:simple catalog name\"\n";
AssetCatalogService::AssetCatalogService()
: catalog_collection_(std::make_unique<AssetCatalogCollection>())
{
}
AssetCatalogService::AssetCatalogService(const CatalogFilePath &asset_library_root)
: catalog_collection_(std::make_unique<AssetCatalogCollection>()),
asset_library_root_(asset_library_root)
{
}
void AssetCatalogService::tag_has_unsaved_changes(AssetCatalog *edited_catalog)
{
if (edited_catalog) {
edited_catalog->flags.has_unsaved_changes = true;
}
BLI_assert(catalog_collection_);
catalog_collection_->has_unsaved_changes_ = true;
}
void AssetCatalogService::untag_has_unsaved_changes()
{
BLI_assert(catalog_collection_);
catalog_collection_->has_unsaved_changes_ = false;
/* TODO(Sybren): refactor; this is more like "post-write cleanup" than "remove a tag" code. */
/* Forget about any deleted catalogs. */
if (catalog_collection_->catalog_definition_file_) {
for (CatalogID catalog_id : catalog_collection_->deleted_catalogs_.keys()) {
catalog_collection_->catalog_definition_file_->forget(catalog_id);
}