UpdateSourceTree.ps1


<#PSScriptInfo

.VERSION 0.0.4

.GUID 2ce4bb1c-1ecf-4b6a-83fc-638475a03115

.AUTHOR Fabrice Sanga

.COMPANYNAME sangafabrice

.COPYRIGHT © 2022 SangaFabrice. All rights reserved.

.TAGS sourcetree nuget-package update git

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

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

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

.EXTERNALMODULEDEPENDENCIES DownloadInfo,RegCli

.REQUIREDSCRIPTS

.EXTERNALSCRIPTDEPENDENCIES

.RELEASENOTES
Initialize SourceTree updater script.

.PRIVATEDATA

#>


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

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

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

<#
.SYNOPSIS
    Updates SourceTree software.
.DESCRIPTION
    The script installs or updates SourceTree 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%\SourceTree".
.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\SourceTree' -ErrorAction SilentlyContinue

    PS > .\UpdateSourceTree.ps1 -InstallLocation 'C:\ProgramData\SourceTree' -SaveTo .

    PS > Get-ChildItem 'C:\ProgramData\SourceTree' | Select-Object Name -First 5
    Name
    ----
    de
    es
    extras
    fr
    icons

    PS > Get-ChildItem | Select-Object Name
    Name
    ----
    sourcetree_3.4.9.exe
    UpdateSourceTree.ps1

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