Compare commits
3 commits
770445ea95
...
6de06321ca
Author | SHA1 | Date | |
---|---|---|---|
Manuel Thalmann | 6de06321ca | ||
Manuel Thalmann | 9b8ba848f6 | ||
Manuel Thalmann | 7532873c6c |
|
@ -158,8 +158,12 @@ $null = New-Module {
|
|||
}
|
||||
|
||||
if (Get-Config "valhalla.hardware.elgatoWave") {
|
||||
Install-ChocoPackage wavelink;
|
||||
if (-not (Test-ChocoPackage wavelink)) {
|
||||
Install-ChocoPackage wavelink -ArgumentList '--install-arguments="/norestart"';
|
||||
Remove-DesktopIcon "*Wave Link*";
|
||||
Restart-Intermediate;
|
||||
exit;
|
||||
}
|
||||
}
|
||||
|
||||
if (Get-Config "valhalla.hardware.eyeX") {
|
||||
|
@ -167,13 +171,21 @@ $null = New-Module {
|
|||
}
|
||||
};
|
||||
|
||||
$null = New-Module {
|
||||
# Windows Config
|
||||
. "$PSScriptRoot/../Software/Windows/Manage.ps1" @arguments;
|
||||
$softwarePath = "$PSScriptRoot/../Software";
|
||||
. "$softwarePath/Windows/Manage.ps1" @arguments;
|
||||
|
||||
if (Test-Collection "essential") {
|
||||
# Essentials
|
||||
. "$PSScriptRoot/../Software/OpenSSH/Manage.ps1" @arguments;
|
||||
. "$softwarePath/OpenSSH/Manage.ps1" @arguments;
|
||||
}
|
||||
|
||||
if (Test-Collection "common") {
|
||||
# Common Software
|
||||
. "$softwarePath/WinSCP/Manage.ps1" @arguments;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
switch (Get-Stage) {
|
||||
|
|
|
@ -1,62 +1,102 @@
|
|||
using namespace System.Xml;
|
||||
|
||||
$null = New-Module {
|
||||
class AppAssociations {
|
||||
static $defaultAssociationsSelector = "/DefaultAssociations";
|
||||
static $associationSelector = "./Association";
|
||||
$rootSelector = "/DefaultAssociations";
|
||||
$associationSelector = "./Association";
|
||||
|
||||
static [string] GetSelector([string] $identifier) {
|
||||
return "$([AppAssociations]::associationSelector)[@Identifier='$identifier']";
|
||||
<#
|
||||
.SYNOPSIS
|
||||
Generates a selector for getting the association of the specified identifier.
|
||||
|
||||
.PARAMETER Identifier
|
||||
The identifier to get the association of.
|
||||
#>
|
||||
$getSelector = {
|
||||
param(
|
||||
[string] $Identifier
|
||||
)
|
||||
|
||||
[string] $filter = "";
|
||||
|
||||
if ($Identifier) {
|
||||
$filter = "[@Identifier='$Identifier']";
|
||||
}
|
||||
|
||||
static [xml] GetAppAssociations() {
|
||||
[xml] $associations = [xml]::new();
|
||||
$associations.LoadXml(((DISM /Online /Get-DefaultAppAssociations) | Select-Object -Skip 6 | Select-Object -SkipLast 2 | Out-String));
|
||||
return $associations;
|
||||
"$rootSelector/$associationSelector$filter";
|
||||
}
|
||||
|
||||
static SetAssociation([string] $identifier, [string] $progId, [string] $applicationName) {
|
||||
$document = [AppAssociations]::GetAppAssociations();
|
||||
$associations = $document.SelectSingleNode([AppAssociations]::defaultAssociationsSelector);
|
||||
|
||||
[System.Xml.XmlNode] $association = $null;
|
||||
$candidates = $associations.SelectNodes([AppAssociations]::GetSelector($identifier));
|
||||
|
||||
if ($candidates.Count -eq 1) {
|
||||
$association = $candidates[0];
|
||||
} else {
|
||||
$association = ($associations.SelectNodes([AppAssociations]::associationSelector) | Select-Object -Last 1).CloneNode($true);
|
||||
$association.Identifier = $identifier;
|
||||
$association = $associations.AppendChild($association);
|
||||
<#
|
||||
.SYNOPSIS
|
||||
Gets the default app associations of the running Windows system.
|
||||
#>
|
||||
function Get-DefaultAppAssociations {
|
||||
[OutputType([xml])]
|
||||
param()
|
||||
[xml]::new().LoadXml(((DISM /Online /Get-DefaultAppAssociations) | Select-Object -Skip 6 | Select-Object -SkipLast 2 | Out-String));
|
||||
}
|
||||
|
||||
$association.ProgId = $progId;
|
||||
$association.ApplicationName = $applicationName;
|
||||
[AppAssociations]::SaveAssociations($document);
|
||||
}
|
||||
<#
|
||||
.SYNOPSIS
|
||||
Sets a default app association.
|
||||
|
||||
static SaveAssociations([xml] $document) {
|
||||
$associations = $document.SelectSingleNode([AppAssociations]::defaultAssociationsSelector);
|
||||
$defaultAssociations = $associations.SelectNodes([AppAssociations]::associationSelector);
|
||||
$defaultAssociations | ForEach-Object { $associations.RemoveChild($_); } | Sort-Object -Property "Identifier" | ForEach-Object { $associations.AppendChild($_); };
|
||||
.PARAMETER Identifier
|
||||
The identifier of the association to set.
|
||||
|
||||
$configFile = New-TemporaryFile;
|
||||
$writerSettings = [System.Xml.XmlWriterSettings]::new();
|
||||
$writerSettings.Indent = $true;
|
||||
$writerSettings.Encoding = [System.Text.UTF8Encoding]::new();
|
||||
$writer = [System.Xml.XmlWriter]::Create($configFile.FullName, $writerSettings);
|
||||
$document.Save($writer);
|
||||
$writer.Dispose();
|
||||
DISM /Online "/Import-DefaultAppAssociations:$($configFile.FullName)";
|
||||
Remove-Item $configFile;
|
||||
}
|
||||
}
|
||||
.PARAMETER ProgId
|
||||
The ProgId to set the association to.
|
||||
|
||||
.PARAMETER ApplicationName
|
||||
The ApplicationName to set the association to.
|
||||
#>
|
||||
function Set-DefaultAppAssociation {
|
||||
param (
|
||||
param(
|
||||
[string] $Identifier,
|
||||
[string] $ProgId,
|
||||
[string] $ApplicationName
|
||||
)
|
||||
|
||||
[AppAssociations]::SetAssociation($Identifier, $ProgId, $ApplicationName);
|
||||
[System.Xml.XmlNode] $association = $null;
|
||||
$document = Get-DefaultAppAssociations;
|
||||
$candidates = $document.SelectNodes((& $getSelector $Identifier));
|
||||
|
||||
if ($candidates.Count -eq 1) {
|
||||
$association = $candidates[0];
|
||||
} else {
|
||||
$association = ([System.Xml.XmlNode]($document.SelectNodes((& $getSelector)) | Select-Object -Last 1)[0]).CloneNode($true);
|
||||
$association.Identifier = $Identifier;
|
||||
}
|
||||
|
||||
$association.ProgId = $ProgId;
|
||||
$association.ApplicationName = $ApplicationName;
|
||||
Save-DefaultAppAssociations $document;
|
||||
}
|
||||
|
||||
<#
|
||||
.SYNOPSIS
|
||||
Saves the default app associations.
|
||||
|
||||
.PARAMETER Document
|
||||
The xml document containing the declarations of the app associations.
|
||||
#>
|
||||
function Save-DefaultAppAssociations {
|
||||
param(
|
||||
[xml] $Document
|
||||
)
|
||||
|
||||
$root = $document.SelectSingleNode($rootSelector);
|
||||
$associations = $root.SelectNodes((& $getSelector));
|
||||
|
||||
# Reorder associations by their Identifier
|
||||
$associations | ForEach-Object { $root.RemoveChild($_); } | Sort-Object -Property "Identifier" | ForEach-Object { $root.AppendChild($_); };
|
||||
|
||||
$configFile = New-TemporaryFile;
|
||||
$writerSettings = [XmlWriterSettings]::new();
|
||||
$writerSettings.Indent = $true;
|
||||
$writerSettings.Encoding = [System.Text.UTF8Encoding]::new();
|
||||
$writer = [XmlWriter]::Create($configFile.FullName, $writerSettings);
|
||||
$document.Save($writer);
|
||||
$writer.Dispose();
|
||||
DISM /Online "/Import-DefaultAppAssociations:$($configFile.FullName)";
|
||||
Remove-Item $configFile;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -19,11 +19,16 @@ $null = New-Module {
|
|||
function Install-ChocoPackage {
|
||||
param(
|
||||
[switch] $Force,
|
||||
[string[]] $ArgumentList,
|
||||
[Parameter(Position=0)]
|
||||
[string] $Name,
|
||||
[Parameter(ValueFromRemainingArguments = $true)]
|
||||
[string[]] $Names
|
||||
[string[]] $AdditionalNames = @()
|
||||
)
|
||||
|
||||
[System.Collections.ArrayList] $Names = $Names;
|
||||
[System.Collections.ArrayList] $Names = @();
|
||||
$null = $Names.Add($Name);
|
||||
$Names.AddRange($AdditionalNames);
|
||||
|
||||
if (-not ($Force.IsPresent)) {
|
||||
for ($i = $Names.Count - 1; $i -ge 0; $i--) {
|
||||
|
@ -34,7 +39,7 @@ $null = New-Module {
|
|||
}
|
||||
|
||||
if ($Names.Count -ge 1) {
|
||||
choco install -y $Names;
|
||||
choco install -y $ArgumentList $Names;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
25
scripts/Windows/Software/WinSCP/Manage.ps1
Normal file
25
scripts/Windows/Software/WinSCP/Manage.ps1
Normal file
|
@ -0,0 +1,25 @@
|
|||
using namespace Microsoft.Win32;
|
||||
|
||||
param(
|
||||
$Action,
|
||||
[hashtable] $Arguments
|
||||
)
|
||||
|
||||
. "$PSScriptRoot/../../Scripts/AppAssociations.ps1";
|
||||
. "$PSScriptRoot/../../Scripts/Software.ps1";
|
||||
. "$PSScriptRoot/../../Scripts/System.ps1";
|
||||
|
||||
Start-SoftwareInstaller @PSBoundParameters `
|
||||
-Installer {
|
||||
param(
|
||||
[scriptblock] $Installer
|
||||
)
|
||||
|
||||
Install-ChocoPackage winscp;
|
||||
& $Installer -Action ([InstallerAction]::Configure)
|
||||
} `
|
||||
-Configurator {
|
||||
Remove-DesktopIcon "WinSCP*";
|
||||
Write-Host "Making WinSCP the default FTP program…";
|
||||
Set-DefaultAppAssociation -Identifier "ftp" -ProgId "WinSCP.Url" -ApplicationName "WinSCP: SFTP, FTP, WebDAV, S3 and SCP client";
|
||||
};
|
Loading…
Reference in a new issue