UpdateKrita.ps1


<#PSScriptInfo

.VERSION 0.0.2

.GUID 92609713-2eab-4c4e-b0bc-fc9b9f90136b

.AUTHOR Fabrice Sanga

.COMPANYNAME sangafabrice

.COPYRIGHT © 2022 SangaFabrice. All rights reserved.

.TAGS krita nsis update image-editor

.LICENSEURI https://github.com/sangafabrice/reg-cli/blob/main/LICENSE.md

.PROJECTURI https://github.com/sangafabrice/reg-cli/tree/krita

.ICONURI https://rawcdn.githack.com/sangafabrice/reg-cli/c3fd097258816175baeb2e92bd776d781a77fd1b/icon.png

.EXTERNALMODULEDEPENDENCIES DownloadInfo,RegCli

.REQUIREDSCRIPTS

.EXTERNALSCRIPTDEPENDENCIES

.RELEASENOTES
Initialize Krita updater script.

.PRIVATEDATA

#>


#Requires -Module @{ModuleName = 'DownloadInfo'; ModuleVersion = '5.0.4'}
#Requires -Module @{ModuleName = 'RegCli'; ModuleVersion = '6.3.2'}

[CmdletBinding()]
Param (
    [ValidateNotNullOrEmpty()]
    [ValidateScript({ Test-InstallLocation $_ $PSScriptRoot })]
    [string]
    $InstallLocation = "${Env:ProgramData}\Krita",
    [ValidateNotNullOrEmpty()]
    [ValidateScript({ Test-InstallerLocation $_ })]
    [string]
    $SaveTo = $PSScriptRoot
)

& {
    $NameLocation = "$InstallLocation\bin\Krita.exe"
    $MachineType = Get-ExecutableType $NameLocation
    Try {
        $UpdateModule =
            Import-CommonScript chrome-installer |
            Import-Module -PassThru -Force -Verbose:$False
        @{
            UpdateInfo = $(
                Write-Verbose 'Retrieve install or update information...'
                Try { Get-DownloadInfo -PropertyList @{ OSArch = $MachineType } -From Krita }
                Catch { }
            )
            InstallLocation = $InstallLocation
            NameLocation = $NameLocation
            SaveTo = $SaveTo
            SoftwareName = 'Krita'
            InstallerDescription = "Krita ($MachineType) * Setup"
            InstallerType = 'BasicNSIS'
            Verbose = $VerbosePreference -ine 'SilentlyContinue'
        } | ForEach-Object { Invoke-CommonScript @_ }
    }
    Catch { }
    Finally { $UpdateModule | Remove-Module -Verbose:$False }
}

<#
.SYNOPSIS
    Updates Krita software.
.DESCRIPTION
    The script installs or updates Krita image editor on Windows.
.NOTES
    Required: at least Powershell Core 7.
.PARAMETER InstallLocation
    Path to the installation directory.
    It is restricted to file system paths.
    It does not necessary exists.
    It defaults to "%ProgramData%\Krita".
.PARAMETER SaveTo
    Path to the directory of the downloaded installer.
    It is an existing file system path.
    It defaults to the script directory.
.EXAMPLE
    Get-ChildItem 'C:\ProgramData\Krita\bin' -ErrorAction SilentlyContinue

    PS > .\UpdateKrita.ps1 -InstallLocation 'C:\ProgramData\Krita\bin' -SaveTo .

    PS > Get-ChildItem 'C:\ProgramData\Krita\bin' | Where-Object Name -Like 'krita*' | Select-Object Name
    Name
    ----
    krita.com
    krita.dll
    krita.exe
    kritarunner.com
    kritarunner.exe

    PS > Get-ChildItem | Select-Object Name
    Name
    ----
    krita_5.1.1.exe
    UpdateKrita.ps1

    Install Krita to 'C:\ProgramData\Krita\bin' and save its setup installer to the current directory.
#>