Commit Graph

15 Commits

Author SHA1 Message Date
Julian Eisel 95077549c1 Fix failure in recently added asset library tests
Mistake in 1efc94bb2f.
2022-11-09 22:51:32 +01:00
Julian Eisel 1efc94bb2f Asset System: New core type to represent assets (`AssetRepresenation`)
Introduces a new `AssetRepresentation` type, as a runtime only container
to hold asset information. It is supposed to become _the_ main way to
represent and refer to assets in the asset system, see T87235. It can
store things like the asset name, asset traits, preview and other asset
metadata.

Technical documentation:
https://wiki.blender.org/wiki/Source/Architecture/Asset_System/Back_End#Asset_Representation.

By introducing a proper asset representation type, we do an important
step away from the previous, non-optimal representation of assets as
files in the file browser backend, and towards the asset system as
backend. It should replace the temporary & hacky `AssetHandle` design in
the near future. Note that the loading of asset data still happens
through the file browser backend, check the linked to Wiki page for more
information on that.

As a side-effect, asset metadata isn't stored in file browser file
entries when browsing with link/append anymore. Don't think this was
ever used, but scripts may have accessed this. Can be brought back if
there's a need for it.
2022-11-09 19:30:47 +01:00
Campbell Barton d66f24cfe3 Fix potential buffer overflow with BLI_path_slash_ensure use
BLI_path_slash_ensure was appending to fixed sized buffers without
a size check.
2022-10-30 15:34:02 +11:00
Campbell Barton e96ad822b3 Fix AssetCatalogTest failure on WIN32
Recent changes to path handling (most likely [0]) caused
AssetCatalogTest.create_catalog_after_loading_file to fail on WIN32.

The test relied on the resulting path to be joined with "/" as a path
separator. The resulting path used both forward and back-slashes.
While these do work for some API's on WIN32, mixing both in a file path
isn't expected behavior in most cases, so update the tests to use native
slash direction for file-paths.

[0]: 9f6a045e23
2022-10-17 21:27:05 +11:00
Campbell Barton c434782e3a File headers: SPDX License migration
Use a shorter/simpler license convention, stops the header taking so
much space.

Follow the SPDX license specification: https://spdx.org/licenses

- C/C++/objc/objc++
- Python
- Shell Scripts
- CMake, GNUmakefile

While most of the source tree has been included

- `./extern/` was left out.
- `./intern/cycles` & `./intern/atomic` are also excluded because they
  use different header conventions.

doc/license/SPDX-license-identifiers.txt has been added to list SPDX all
used identifiers.

See P2788 for the script that automated these edits.

Reviewed By: brecht, mont29, sergey

Ref D14069
2022-02-11 09:14:36 +11:00
Campbell Barton 76471dbd5e Cleanup: capitalize NOTE tag 2021-11-30 10:15:17 +11:00
Julian Eisel 9de4f64197 Fix compile error on Windows
Caused by 7150f919d3. This undid part of 79a88b5e91. Added a comment
for why this include is needed, to avoid this error from happening
again.
2021-11-01 14:44:18 +01:00
Sybren A. Stüvel cdcca917cf Tests: assets, add BKE callback init/finalize to test setup/teardown
Add calls to `BKE_callback_global_init()` and `BKE_callback_global_finalize()`
to ensure unit tests mimick Blender (and don't trip the assertions added
in rBbeea601e7253).

No functional changes to Blender.
2021-10-25 14:21:43 +02:00
Sybren A. Stüvel 70aad5f498 Asset Catalogs: support reloading without losing local changes
Keep track of unsaved asset catalog changes, in a more granular way than
just one boolean per asset library. Individual catalogs can now be
marked with a flag `has_unsaved_changes`. This is taken into account
when reloading data from the catalog definition file (CDF):

- New catalog in CDF: gets loaded
- Already-known catalog in CDF:
    - local unsaved changes: on-disk catalog is ignored
    - otherwise: on-disk catalog replaces in-memory one
- Already-known catalog that does not exist in CDF:
    - local unsaved changes: catalog is kept around
    - otherwise: catalog is deleted.

Because this saving-is-also-loading behaviour, the "has unsaved changes"
flags are all stored in the undo buffer; undoing after saving will not
change the CDF, but at least it'll undo the loading from disk, and it'll
re-mark any changes as "not saved".

Reviewed By: Severin

Differential Revision: https://developer.blender.org/D12967
2021-10-22 16:31:32 +02:00
Sybren A. Stüvel 823996b034 Asset Browser: Improved workflow for asset catalog saving
No longer save asset catalogs on blendfile save. Instead:

- extend the confirmation prompt for unsaved changes to show unsaved
  catalogs.
- In the confirmation prompt, make catalog saving explicit & optional,
  just like we do it for external images. {F10881736}
- In the Asset Browser catalog tree, show an operator icon to save the
  catalogs to disk. It's grayed out if there are no changes to save, or
  if the .blend wasn't saved yet (required to know where to save the
  catalog definitions to). {F10881743}

Much of the work was done by @Severin and reviewed by me, then we
swapped roles.

Reviewed By: Severin

Differential Revision: https://developer.blender.org/D12796
2021-10-19 18:07:22 +02:00
Sybren A. Stüvel 79a88b5e91 Fix compilation error about undefined `PATH_MAX` 2021-10-19 16:47:17 +02:00
Sybren A. Stüvel 9a1d75e0b9 Asset Library Service: make insensitive to trailing slashes
Make `AssetLibraryService::get_asset_library_on_disk(path)` insensitive
to trailing slashes; i.e. `get_asset_library_on_disk("/path")` and
`get_asset_library_on_disk("/path/¨)` will now return the same
`AssetLibrary*`.
2021-10-19 15:53:11 +02:00
Sybren A. Stüvel 46fe43feca Fix failing `AssetLibraryService` test by removing test code
Remove the code I had hoped to fix in rB3edae09e, the fix was unreliable.

No functional changes to Blender.
2021-10-18 17:29:24 +02:00
Sybren A. Stüvel 3edae09eaa Asset Library Service: fix failing unit test
On GCC in release mode (and maybe also debug mode without ASAN enabled),
allocating an `AssetLibraryService` will reuse the space that should
have just been freed. This made a test fail, as it was testing that new
memory was allocated and not some old instance reused.

To ensure that the calls that should allocate a new block of memory
return a unique pointer, I added some dummy allocation to the test.

No functional changes to Blender
2021-10-18 15:48:06 +02:00
Sybren A. Stüvel f9113c4be8 Assets: add global `bke::AssetLibraryService` class
Add `blender::bke::AssetLibraryService` class that acts like a
blendfile-scoped singleton. It's allocated upon the first call to
`BKE_asset_library_load` and destroyed in the LOAD-PRE handler.

The `AssetLibraryService` ensures that edits to asset catalogs are not
lost when the asset browser editor closes (or even reloads). Instead,
the `AssetLibrary` pointers it owns are kept around as long as the blend
file is open.

Reviewed By: Severin

Maniphest Tasks: T92151

Differential Revision: https://developer.blender.org/D12885
2021-10-18 14:21:41 +02:00