internal/configurations/settings/paths.ps1

<#
This is designed for all paths you need configurations for.
#>


$temp = ([System.IO.Path]::GetTempPath()).TrimEnd("\")
$docs = $([Environment]::GetFolderPath("MyDocuments"))

# get crazy here to support multiple enviornments

if (-not $temp) {
    if ($psVersionTable.Platform -eq 'Unix') {
        $temp = "/tmp"
    } else {
        $temp = "C:\windows\temp"
    }
}

if (-not $docs) {
    $docs = $temp
}

if (-not $home) {
    $home = $temp
}

if (-not (Test-Path -Path $temp)) {
    $null = New-Item -Path $temp -ItemType Directory -Force
}

if (-not (Test-Path -Path $home)) {
    $null = New-Item -Path $home -ItemType Directory -Force
}

if (-not (Test-Path -Path $docs)) {
    $null = New-Item -Path $docs -ItemType Directory -Force
}

if (-not $script:AppData) {
    $script:AppData = "$temp\AppData"
}

if (-not (Test-Path -Path $script:AppData)) {
    $null = New-Item -Path $script:AppData -ItemType Directory -Force
}

# The default path where dbatools stores persistent data
Set-DbatoolsConfig -FullName 'Path.DbatoolsData' -Value (Join-DbaPath $script:AppData "PowerShell" "dbatools") -Initialize -Validation string -Handler { } -Description "The path where dbatools stores persistent data on a per user basis."

# The default path where dbatools stores temporary data
Set-DbatoolsConfig -FullName 'Path.DbatoolsTemp' -Value $temp -Initialize -Validation string -Handler { } -Description "The path where dbatools stores temporary data."

# The default path for writing logs
Set-DbatoolsConfig -FullName 'Path.DbatoolsLogPath' -Value (Join-DbaPath $script:AppData "PowerShell" "dbatools") -Initialize -Validation string -Handler { [Sqlcollaborative.Dbatools.Message.LogHost]::LoggingPath = $args[0] } -Description "The path where dbatools writes all its logs and debugging information."

# The default Path for where the tags Json is stored
Set-DbatoolsConfig -FullName 'Path.TagCache' -Value (Resolve-Path "$script:PSModuleRoot\bin\dbatools-index.json") -Initialize -Validation string -Handler { } -Description "The file in which dbatools stores the tag cache. That cache is used in Find-DbaCommand for more comfortable autocomplete"

# The default Path for the server list (Get-DbaInstanceList, etc)
Set-DbatoolsConfig -FullName 'Path.Servers' -Value (Join-DbaPath $script:AppData "PowerShell" "dbatools" "servers.xml") -Initialize -Validation string -Handler { } -Description "The file in which dbatools stores the current user's server list, as managed by Get/Add/Update-DbaInstanceList"

# The default path for writing exported SQL scripts
Set-DbatoolsConfig -FullName 'Path.DbatoolsExport' -Value (Join-DbaPath -Path $docs -Child "DbatoolsExport") -Initialize -Validation string -Handler { [Sqlcollaborative.Dbatools.Message.LogHost]::LoggingPath = $args[0] } -Description "The default path where dbatools writes scripts generated by Export-* functions."