PortValhalla/scripts/Windows/Software/VisualStudio/Manage.ps1

85 lines
3.1 KiB
PowerShell
Raw Normal View History

2024-08-08 02:36:35 +00:00
& {
2024-09-03 10:02:32 +00:00
. "$PSScriptRoot/../../Scripts/Restoration.ps1";
2024-09-23 01:33:17 +00:00
. "$PSScriptRoot/../../Scripts/SoftwareManagement.ps1";
2024-08-08 02:36:35 +00:00
. "$PSScriptRoot/../../../Common/Scripts/BrowserAutomation.ps1";
. "$PSScriptRoot/../../../Common/Scripts/Software.ps1";
2024-09-03 10:02:32 +00:00
. "$PSScriptRoot/../../../Common/Scripts/SoftwareManagement.ps1";
2024-08-08 02:36:35 +00:00
. "$PSScriptRoot/../../../Common/Scripts/System.ps1";
[System.Tuple[string, string, string][]] $versions = @(
[System.Tuple]::Create("visualstudio2019enterprise", "VisualStudio.16.Release", "Microsoft.VisualStudio.Product.Enterprise"),
[System.Tuple]::Create("visualstudio2019community", "VisualStudio.16.Release", "Microsoft.VisualStudio.Product.Community"),
[System.Tuple]::Create("visualstudio2022enterprise", "VisualStudio.17.Release", "Microsoft.VisualStudio.Product.Enterprise"),
[System.Tuple]::Create("visualstudio2022community", "VisualStudio.17.Release", "Microsoft.VisualStudio.Product.Community")
);
2024-09-03 10:02:32 +00:00
<#
.SYNOPSIS
Gets the path to the Visual Studio Installer.
#>
function Get-InstallerPath {
return "$((Get-KnownFolder ProgramFilesX86).Path)/Microsoft Visual Studio/Installer/vs_installer.exe";
}
<#
.SYNOPSIS
Gets the path to the configuration file in the backup archive.
2024-09-29 15:39:26 +00:00
.PARAMETER Name
The name of the software.
2024-09-03 10:02:32 +00:00
.PARAMETER PackageName
The name of the package to get the configuration for.
#>
function Get-ConfigPath {
param(
[string] $Name,
2024-09-03 10:02:32 +00:00
[string] $PackageName
)
return Join-Path "$Name" "$PackageName.vsconfig";
2024-09-03 10:02:32 +00:00
}
2024-09-30 03:00:20 +00:00
Start-SoftwareInstaller @args `
2024-09-03 10:02:32 +00:00
-Backup {
param([string] $Name)
2024-09-03 10:02:32 +00:00
foreach ($version in $versions) {
if (Test-ChocoPackage $version[0]) {
Write-Host "Backing up ``$($version[0])";
$configFile = New-TemporaryFile;
Start-Process -FilePath (Get-InstallerPath) -Wait `
-ArgumentList @(
"export",
"--channelId", $version[1],
"--productId", $version[2],
"--config", $configFile,
"--quiet"
);
Add-BackupArtifacts -Source $configFile -Path (Get-ConfigPath $Name $version[0]);
2024-09-03 10:02:32 +00:00
Remove-Item $configFile;
}
}
} `
2024-08-08 02:36:35 +00:00
-Installer {
param([string] $Name)
2024-08-08 02:36:35 +00:00
foreach ($version in $versions) {
$packageName = $version[0];
2024-09-03 10:02:32 +00:00
$file = New-TemporaryFile;
Remove-Item $file;
Expand-BackupArtifacts -Path (Get-ConfigPath $Name $packageName) -Target $file;
2024-09-03 10:02:32 +00:00
if (Test-Path $file) {
Write-Host "Restoring ``$packageName``";
2024-10-06 19:25:34 +00:00
Install-ChocoPackage $packageName -ArgumentList "--params", "--config `"$file`"";
2024-09-03 10:02:32 +00:00
}
2024-08-08 02:36:35 +00:00
}
2024-08-08 23:33:04 +00:00
Remove-DesktopIcon "CocosCreator*";
Remove-DesktopIcon "Unity Hub*";
2024-08-08 02:36:35 +00:00
};
2024-09-30 03:00:20 +00:00
} @args;