Public/Functions.Public.ps1

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
Function Set-WTBackgroundImage {
    [Alias("wtimg")]
    Param(
        [Parameter(Mandatory)]
        [string]$ImagePath
    )

    $CurrentExec = [System.IO.Path]::GetFileNameWithoutExtension([Environment]::GetCommandLineArgs())
    CheckPath -Path $ImagePath
    $ProfilePath = $Script:CommonConfig.ProfilePath.Replace('LOCALAPPDATA',$env:LOCALAPPDATA)
    $Config = Get-CurrentAppConfig -ProfilePath $global:CommonConfig.ProfilePath.Replace('LOCALAPPDATA',$env:LOCALAPPDATA)
    $CurrentAppConfig = $Config.Profiles | Where-Object -FilterScript {[System.IO.Path]::GetFileNameWithoutExtension($_.CommandLine) -eq $CurrentExec }

    if($CurrentAppConfig.BackgroundImage){
        $CurrentAppConfig.BackgroundImage = $ImagePath
    }
    else{
        $CurrentAppConfig | Add-Member -MemberType NoteProperty -Name backgroundImage -Value $ImagePath -Force
    }

    $Config | ConvertTo-Json -Depth 99 | Out-File -FilePath $ProfilePath -Force -Encoding utf8
}