# Asset Library Verification (Optional)

##### <a class="anchor" id="bkmrk--43"></a>Description

The optional Asset Library Verification feature allows asset version checks and provides means to verify the compatibility between an asset library file and an application.

##### **Asset Version Information** 

The asset file contains the following data to support asset verification:

<div class="contents" id="bkmrk-asset-version-%28int32"><div class="contents"><div class="textblock">- **Asset Version (Int32):** Describes the version of the asset file format. This version must match the version of the [Candera](http://dev.doc.cgistudio.at/APILINK/namespace_candera.html "[DataBinding_RefTypeSample]") AssetLoader to be able to load the asset file.
- **File Size (Int32):** Size of the file in bytes.
- **File Timestamp (Int64):** Contains the creation time of the asset.
- **Widget Hash (UInt32):** Hash value generated from the available widgets and their properties.
- **Widget Set Version (Int32):** Version of the Widget Set.
- **[Candera](http://dev.doc.cgistudio.at/APILINK/namespace_candera.html "[DataBinding_RefTypeSample]") Version (Int32\[4\]):** [Candera](http://dev.doc.cgistudio.at/APILINK/namespace_candera.html "[DataBinding_RefTypeSample]") version used within SceneComposer.
- **Solution GUID (Char\[16\]):** Unique ID of the Solution.
- **Custom ID (Int32):** Custom Id that can be set by the user upon asset generation.
- **SceneComposer Version (Int32\[4\]):** SceneComposer version used to generate the asset file.

</div></div></div>##### <a class="anchor" id="bkmrk--45"></a>Feature Comparison

Without the optional asset verification, only a limited set of information is available. The table below gives a comparison of asset information available by default in [Candera](http://dev.doc.cgistudio.at/APILINK/namespace_candera.html "[DataBinding_RefTypeSample]"), and asset information available with enabled asset verification feature.

<div class="contents" id="bkmrk-candera-default-asse"><div class="textblock"><table border="1" cellpadding="5" cellspacing="0" width="500"><tbody><tr bgcolor="#d4d4d4"><th width="34%">  
</th><th width="33%">**[Candera](http://dev.doc.cgistudio.at/APILINK/namespace_candera.html "[DataBinding_RefTypeSample]") Default**</th><th width="33%">**Asset Verification Enabled**</th></tr><tr><th bgcolor="#d4d4d4">**Asset Version**</th><td align="center">X</td><td align="center">  
</td></tr><tr><th bgcolor="#d4d4d4">**File Size**</th><td align="center">X</td><td align="center">  
</td></tr><tr><th bgcolor="#d4d4d4">**Time Stamp**</th><td align="center">  
</td><td align="center">X</td></tr><tr><th bgcolor="#d4d4d4">**Widget Hash**</th><td align="center">  
</td><td align="center">X</td></tr><tr><th bgcolor="#d4d4d4">**Widget Set Version**</th><td align="center">  
</td><td align="center">X</td></tr><tr><th bgcolor="#d4d4d4">**[Candera](http://dev.doc.cgistudio.at/APILINK/namespace_candera.html "[DataBinding_RefTypeSample]") Version**</th><td align="center">  
</td><td align="center">X</td></tr><tr><th bgcolor="#d4d4d4">**Solution GUID**</th><td align="center">  
</td><td align="center">X</td></tr><tr><th bgcolor="#d4d4d4">**Custom ID**</th><td align="center">  
</td><td align="center">X</td></tr><tr><th bgcolor="#d4d4d4">**SceneComposer Version**</th><td align="center">  
</td><td align="center">X</td></tr></tbody></table>

</div></div>##### **Export of Asset Version Info** 

##### <a class="anchor" id="bkmrk--46"></a>Automatic / User Defined Values

Most of the asset information is automatically generated by SceneComposer during asset export, but some can be controlled directly. The following table shows which properties can be set manually.

<div class="contents" id="bkmrk-user-defined-sceneco"><div class="contents"><div class="textblock"><table border="1" cellpadding="5" cellspacing="0" width="500"><tbody><tr bgcolor="#d4d4d4"><th width="34%">  
</th><th width="33%">**User Defined**</th><th width="33%">**SceneComposer**</th></tr><tr><th bgcolor="#d4d4d4">**Asset Version**</th><td align="center">  
</td><td align="center">X</td></tr><tr><th bgcolor="#d4d4d4">**File Size**</th><td align="center">  
</td><td align="center">X</td></tr><tr><th bgcolor="#d4d4d4">**Time Stamp**</th><td align="center">  
</td><td align="center">X</td></tr><tr><th bgcolor="#d4d4d4">**Widget Hash**</th><td align="center">  
</td><td align="center">X</td></tr><tr><th bgcolor="#d4d4d4">**Widget Set Version**</th><td align="center">X</td><td align="center">  
</td></tr><tr><th bgcolor="#d4d4d4">**[Candera](http://dev.doc.cgistudio.at/APILINK/namespace_candera.html "[DataBinding_RefTypeSample]") Version**</th><td align="center">  
</td><td align="center">X</td></tr><tr><th bgcolor="#d4d4d4">**Solution GUID**</th><td align="center">  
</td><td align="center">X</td></tr><tr><th bgcolor="#d4d4d4">**Custom ID**</th><td align="center">X</td><td align="center">  
</td></tr><tr><th bgcolor="#d4d4d4">**Scenecomposer Version**</th><td align="center">  
</td><td align="center">X</td></tr></tbody></table>

</div></div></div>##### <a class="anchor" id="bkmrk--47"></a>Set the WidgetSet Version Number

To set the user-defined WidgetSet version number the new macro `CdaVersion` can be used in the WidgetSet definition.

```
<a class="code" href="http://dev.doc.cgistudio.at/APILINK/group___widget_base.html#gaf22698a7899d856911f78b17f154dcb2">CdaWidgetSet</a>(DemoWidgetSet)
    CdaDescription("<a class="code" href="http://dev.doc.cgistudio.at/APILINK/group___c_o_u_r_i_e_r___m_e_s_s_a_g_i_n_g.html#ggac4e3f0853af916ef773e65d02a15c95dac1224e2f0bf57d4eede7026521a13aa8">Widget</a> Set Demo")
    <a class="code" href="http://dev.doc.cgistudio.at/APILINK/group___meta_info.html#gaf9690830e5c1261bd50034f8f5e5153d">CdaVersion</a>(1) // Sets the Widget-Set version
    <a class="code" href="http://dev.doc.cgistudio.at/APILINK/group___widget_base.html#gada111508ebf4b6014fe2564083936d3e">CdaWidgets</a>()
    
    <a class="code" href="http://dev.doc.cgistudio.at/APILINK/group___widget_base.html#ga311ed10f0878a04c24365fa67fd7e152">CdaWidget</a>(DemoWidget1)
    <a class="code" href="http://dev.doc.cgistudio.at/APILINK/group___widget_base.html#ga311ed10f0878a04c24365fa67fd7e152">CdaWidget</a>(DemoWidget2)
    
    <a class="code" href="http://dev.doc.cgistudio.at/APILINK/group___widget_base.html#gac004125a84968249f4727adb5f00d6a8">CdaWidgetsEnd</a>()
<a class="code" href="http://dev.doc.cgistudio.at/APILINK/group___widget_base.html#gaed11f2e55f8dc7cd01b081fefdbf601b">CdaWidgetSetEnd</a>()
```

##### <a class="anchor" id="bkmrk--48"></a>Set the Custom-Id

The Custom-Id can be set inside of the asset creation dialog of SceneComposer.

<div drawio-diagram="1965"><img src="https://doc316en.candera.eu/uploads/images/drawio/2023-02/drawing-4-1676877218.png" alt=""/></div>

<div class="contents" id="bkmrk--2"></div>##### **Asset Verification at Runtime** 

##### <a class="anchor" id="bkmrk--50"></a>Read Asset Version Data from Asset

The following code example will show how to extract the asset version information from an Asset Repository.

```
    AssetData::AssetVersionInfo versionInfo;
    m_assetDescriptor->GetVersionInfo(versionInfo);
```

The information is now available in the `versionInfo` structure.

##### <a class="anchor" id="bkmrk--51"></a>Get Runtime Version Info from Application

To compare asset version info from the loaded asset with the runtime values from the application, use following interfaces:

<div class="contents" id="bkmrk-get-candera-version-"><div class="contents"><div class="textblock">- Get Candera Version Number
- Get the Supported Asset Version
- WidgetSet verification

</div></div></div>##### <a class="anchor" id="bkmrk--52"></a>Get Candera Version Number

The version number of the currently used [Candera](http://dev.doc.cgistudio.at/APILINK/namespace_candera.html "[DataBinding_RefTypeSample]") can be found in the `CanderaVersionGen.h` file. This file is generated automatically by the build system and contains defines similar to this, describing the exact version of [Candera](http://dev.doc.cgistudio.at/APILINK/namespace_candera.html "[DataBinding_RefTypeSample]").

```
#define CANDERA_VERSION_MAJOR 3
#define CANDERA_VERSION_MINOR 12
#define CANDERA_VERSION_PATCH 0
#define CANDERA_VERSION_TWEAK 0
```

And can be used for example like this:

```
    AssetData::AssetVersionInfo versionInfo;
    assetDescriptor->GetVersionInfo(versionInfo);
    FEATSTD_LOG_INFO("Current Candera version = %d.%d.%d.%d, asset generated with version =  %d.%d.%d.%d\n",
        CANDERA_VERSION_MAJOR, CANDERA_VERSION_MINOR, CANDERA_VERSION_PATCH, CANDERA_VERSION_TWEAK,
        versionInfo.m_canderaVersion[0],versionInfo.m_canderaVersion[1],versionInfo.m_canderaVersion[2],versionInfo.m_canderaVersion[3]);
```

##### <a class="anchor" id="bkmrk--53"></a>Get the Supported Asset Version

The number of the asset file format that is supported by the asset loader is located in the `AssetValidation.h` file and can be accessed like this:

```
    if (versionInfo.m_fileVersion != Candera::AssetValidation::CURRENT_VERSION) {
        FEATSTD_LOG_ERROR("Asset version (%d) does not match supported asset file version (%d)\n", versionInfo.m_fileVersion, Candera::AssetValidation::CURRENT_VERSION);
    }
```

##### <a class="anchor" id="bkmrk--54"></a>WidgetSet verification

To retrieve the currently used WidgetSet version number and WidgetSet hash value, the following code can be used.

```
    if (<a class="code" href="http://dev.doc.cgistudio.at/APILINK/group___widget_base.html#ga6bd6cbb74cc17dacb3d610a2c584eebd">GetWidgetSet</a>() != 0) {
        FEATSTD_LOG_INFO("Widget set version: %d, asset generated with version: %d",
            <a class="code" href="http://dev.doc.cgistudio.at/APILINK/group___widget_base.html#ga6bd6cbb74cc17dacb3d610a2c584eebd">GetWidgetSet</a>()->GetVersion(), versionInfo.m_widgetSetVersion);
        FEATSTD_LOG_INFO("Widget set hash: %d, asset generated with hash: %d",
            <a class="code" href="http://dev.doc.cgistudio.at/APILINK/group___widget_base.html#ga6bd6cbb74cc17dacb3d610a2c584eebd">GetWidgetSet</a>()->GetHash(), versionInfo.m_widgetHash);
    }
```

<div class="contents" id="bkmrk-the-getwidgetset-fun"><div class="textblock"><dl class="note"><dd><p class="callout info">The `GetWidgetSet`-Function is part of the `WidgetMetaInfo.h` file.</p>

</dd></dl></div></div>##### **Candera::AssetValidation** 

Another option of asset verification is to use [Candera::AssetValidation](http://dev.doc.cgistudio.at/APILINK/class_candera_1_1_asset_validation.html) during asset loading. In this case, specific asset validation flags will be evaluated during asset loading

##### <a class="anchor" id="bkmrk--55"></a>Validation Attributes

Refer to [Candera::AssetValidationAttributes](http://dev.doc.cgistudio.at/APILINK/group___asset_loader_base.html#ga784eb587a8c308a03062e4d1d026b826) for all attributes which can be used for asset validation during asset loading.

##### <a class="anchor" id="bkmrk--56"></a>Validation Levels

Refer to [Candera::AssetValidationLevels](http://dev.doc.cgistudio.at/APILINK/group___asset_loader_base.html#ga1219c7b5206a24c2aff2d16b55f243e4) for the actions, which shall be taken after asset validation.

##### <a class="anchor" id="bkmrk--57"></a>Asset Validation during Asset Loading

[Candera::DefaultAssetProvider::Initialize](http://dev.doc.cgistudio.at/APILINK/class_candera_1_1_default_asset_provider.html#a18f6829c9b11c7e875adc523c6bbe852) method allows to specify asset validation flags as a parameter:

```
    if (!m_assetProvider->Initialize(&m_assetConfig, m_validationFlags)) {
        m_assetConfig.ClearRepositoryList();
        return false;
    }
```