Terminal.ps1

$ScriptDir = Split-Path -Path $MyInvocation.MyCommand.Definition -Parent

. ($ScriptDir + "./Global.ps1")

$TerminalProductName =  "logeto-terminal"
$TerminalPackageName = "B158BDD8.LogetoTerminal"

<#
    Return Json file for Terminal appx, if there is no newer version null is returned.
#>

function Get-LogetoTerminalUpdateInfo 
{
    Write-LogetoDebug "Getting Terminal Update Info." 

    $scope = Get-LogetoScope
    $appxVersion = Get-LogetoAppxVersion $TerminalPackageName        
    return Get-LogetoUpdateInfo -Product $TerminalProductName -Scope $scope -Version $appxVersion
}

<#
    Install logeto-terminal product
#>

function Install-LogetoTerminal {

    Param(
        [parameter(Mandatory=$true)]
        $UpdateInfo,
        [parameter(Mandatory=$false)]
        $ProductName = 'logeto-terminal'
    )

    Write-LogetoDebug "Installing terminal" 

    Get-LogetoProduct $UpdateInfo $ProductName

    Install $LogetoFolder + $DownloadFolderPath + $ProductName
}

<#
    Install logeto-terminal product
#>

function Uninstall-LogetoTerminal {

    Param(
        [parameter(Mandatory=$false)]
        $ProductName = 'logeto-terminal'
    )

    Write-LogetoDebug "Uninstalling terminal" 

    Uninstall $LogetoFolder + $DownloadFolderPath + $ProductName
}

<#
    Return Json file from the URL for set product and scope. If version parameter is set it returns Json file only if higher version was found, otherwise returns null.
#>

function Set-LogetoTerminalPrepareEnvironment
{
    Param(
        [parameter(Mandatory=$false)]
        $ProductName = 'logeto-terminal'
    )

    Write-LogetoDebug "Preparing environment for terminal"

    $keyname = "AllowAllTrustedApps"
    $regname = "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\AppModelUnlock"

    if (Test-Path $regname)
    {
        $regvalue = (Get-ItemProperty -Path $regname).$keyname

        if ($regvalue -lt 1)
        {
            New-ItemProperty -Path $regname -Name $keyname -Value 1 -PropertyType DWORD -Force
        }
    }

    $keyname = "LogetoTerminal"
    $regname = "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall"
    $fullpath = $regname + "\" + $keyname

    if (-Not (Test-Path $fullpath))
    {
        New-Item -Path $regname -Name $keyname   
    }

    New-ItemProperty -Path $fullpath -Name "DisplayName" -Value "Logeto Terminal" -Force

    $value = $TerminalFolder + $ProductName + "\Uninstall\LogetoInstaller.exe -uninstallAsCurrentUser"
    New-ItemProperty -Path $fullpath -Name "UninstallString" -Value $value -Force

    New-ItemProperty -Path $fullpath -Name "Publisher" -Value "Systemart s.r.o." -Force

    $value = $TerminalFolder + $ProductName + "\Uninstall\ProductLogo.ico"
    New-ItemProperty -Path $fullpath -Name "DisplayIcon" -Value $value -Force
}