//--------------------------------------------------------------------------------------------------
static void GenerateFileMappingConfig
(
    std::ofstream& cfgStream,
    const legato::App& app
)
//--------------------------------------------------------------------------------------------------
{
    size_t index = 0;

    // Create nodes under "files", where each node is named with an index, starting a 0,
    // and contains a "src" node and a "dest" node.
    cfgStream << "  \"files\"" << std::endl;
    cfgStream << "  {" << std::endl;

    // Import the files specified in the .adef file.
    for (const auto& mapping : app.RequiredFiles())
    {
        GenerateSingleFileMappingConfig(cfgStream, index++, mapping);
    }

    // Bundled files also need to be imported into the application sandbox.
    for (const auto& mapping : app.BundledFiles())
    {
        GenerateBundledObjectMappingConfig(cfgStream, index++, mapping);
    }

    // Bundled directories also need to be imported into the application sandbox.
    for (const auto& mapping : app.BundledDirs())
    {
        GenerateBundledObjectMappingConfig(cfgStream, index++, mapping);
    }

    // Map into the sandbox all the files for all the components.
    for (const auto& pair : app.ComponentMap())
    {
        const auto& componentPtr = pair.second;

        // External files...
        for (const auto& mapping : componentPtr->RequiredFiles())
        {
            GenerateSingleFileMappingConfig(cfgStream, index++, mapping);
        }

        // External directories...
        for (const auto& mapping : componentPtr->RequiredDirs())
        {
            GenerateSingleFileMappingConfig(cfgStream, index++, mapping);
        }

        // NOTE: Bundled files and directories also need to be mapped into the application sandbox
        // because the application's on-target install directory is outside its runtime sandbox.

        // Bundled files...
        for (const auto& mapping : componentPtr->BundledFiles())
        {
            GenerateBundledObjectMappingConfig(cfgStream, index++, mapping);
        }

        // Bundled directories...
        for (const auto& mapping : componentPtr->BundledDirs())
        {
            GenerateBundledObjectMappingConfig(cfgStream, index++, mapping);
        }
    }

    cfgStream << "  }" << std::endl << std::endl;
}