functions/private/Get-KlippyRegistryPath.ps1
|
function Get-KlippyRegistryPath { <# .SYNOPSIS Gets the path to the KlippyCLI registry directory and printers file. .DESCRIPTION Returns the paths used for storing KlippyCLI configuration. Creates the registry directory if it doesn't exist. .PARAMETER FileOnly Return only the printers.json file path instead of the directory path. .OUTPUTS System.String - The path to the registry directory or file. #> [CmdletBinding()] [OutputType([string])] param( [Parameter()] [switch]$FileOnly ) # Use HOME environment variable for cross-platform compatibility $homePath = if ($env:HOME) { $env:HOME } else { $env:USERPROFILE } $registryDir = Join-Path -Path $homePath -ChildPath '.klippycli' # Auto-create directory if missing if (-not (Test-Path -Path $registryDir -PathType Container)) { try { $null = New-Item -Path $registryDir -ItemType Directory -Force -ErrorAction Stop Write-Verbose "Created KlippyCLI registry directory: $registryDir" } catch { throw "Failed to create KlippyCLI registry directory '$registryDir': $_" } } if ($FileOnly) { return Join-Path -Path $registryDir -ChildPath 'printers.json' } return $registryDir } |