param ([String[]] $only)

# Create folders
$buildPath = '.\@501st Community Auxiliary Mod\addons'
New-Item $buildPath -ItemType Directory -Force

$buildPath = Resolve-Path $buildPath
$includePath = Resolve-Path '.\include.txt'

$addonBuilder = Join-Path (Get-ItemProperty "HKCU:\Software\Bohemia Interactive\Arma 3 Tools").path "AddonBuilder\AddonBuilder.exe"

function Build-Addon
{
    param ([string] $addonFolder)
    $addonPath = Resolve-Path ".\addons - Copy\$addonFolder"
    & "$addonBuilder" $addonPath $buildPath -prefix="rd501" -clear -include="$includePath"
}

if ($PSBoundParameters.ContainsKey('only'))
{
    foreach($addonFolder in $only)
    {
        Build-Addon -addonFolder $addonFolder
    }
}
else
{
    foreach($addonFolder in Get-ChildItem -Directory '.\addons - Copy')
    {
        Build-Addon -addonFolder $addonFolder
    }
}