2023-07-12 20:37:31 +00:00
|
|
|
#!/bin/pwsh
|
2024-03-24 14:18:01 +00:00
|
|
|
. "$PSScriptRoot/../../Scripts/KnownFolders.ps1";
|
2024-08-07 19:05:32 +00:00
|
|
|
. "$PSScriptRoot/../../../Common/Scripts/Context.ps1";
|
2023-06-07 20:13:51 +00:00
|
|
|
|
2023-06-08 00:28:33 +00:00
|
|
|
$null = New-Module {
|
|
|
|
$programs32Path = $(Get-KnownFolder "ProgramFilesX86").Path;
|
|
|
|
$vsInstaller = "$programs32Path/Microsoft Visual Studio/Installer/vs_installer.exe";
|
2023-06-07 20:13:51 +00:00
|
|
|
|
2023-06-08 00:28:33 +00:00
|
|
|
[System.Tuple[string, string, string][]]$versions = @(
|
2024-03-24 16:34:25 +00:00
|
|
|
[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"));
|
2023-06-08 00:28:33 +00:00
|
|
|
|
|
|
|
function Get-ConfigPath([Context] $context, [string] $packageName) {
|
2023-07-30 02:13:30 +00:00
|
|
|
return Join-Path $($context.BackupRoot()) "Visual Studio" $packageName ".vsconfig";
|
2023-06-08 00:28:33 +00:00
|
|
|
}
|
2023-06-07 20:13:51 +00:00
|
|
|
|
2023-06-30 10:19:54 +00:00
|
|
|
function Backup-VisualStudio([Context] $context) {
|
2023-06-30 12:23:20 +00:00
|
|
|
Write-Host "Backing up Visual Studio";
|
|
|
|
|
2023-06-08 00:28:33 +00:00
|
|
|
foreach ($version in $versions) {
|
2024-03-24 16:37:13 +00:00
|
|
|
if ((choco list -e $version[0])) {
|
|
|
|
Write-Information "Backing up $($version[1]): $($version[2])";
|
|
|
|
|
|
|
|
$configPath = Get-ConfigPath $context $version[0];
|
|
|
|
$null = New-Item -Force -ItemType Directory "$(Split-Path -Parent $configPath)";
|
|
|
|
|
|
|
|
Start-Process -FilePath "$vsInstaller" `
|
|
|
|
-Wait `
|
|
|
|
-ArgumentList @(
|
|
|
|
"export",
|
|
|
|
"--channelId", "$($version[1])",
|
|
|
|
"--productId", "$($version[2])",
|
|
|
|
"--config", "`"$configPath`"",
|
|
|
|
"--quiet");
|
|
|
|
}
|
2023-06-08 00:28:33 +00:00
|
|
|
}
|
2023-06-07 20:13:51 +00:00
|
|
|
}
|
2023-07-02 14:14:10 +00:00
|
|
|
|
|
|
|
function Restore-VisualStudio([Context] $context) {
|
|
|
|
Write-Host "Restoring Visual Studio";
|
|
|
|
|
|
|
|
foreach ($version in $versions) {
|
|
|
|
$configFileName = Get-ConfigPath $context $version[0];
|
|
|
|
|
|
|
|
if (Test-Path $configFileName) {
|
2024-03-24 16:17:57 +00:00
|
|
|
Write-Information "Restoring $($version[1]): $($version[2])";
|
2023-07-02 14:14:10 +00:00
|
|
|
$arguments = "--config `"$configFileName`"";
|
|
|
|
|
2024-03-24 16:17:57 +00:00
|
|
|
choco install -y $version[0] --params "$arguments";
|
|
|
|
$context.RemoveDesktopIcon("CocosCreator*");
|
|
|
|
$context.RemoveDesktopIcon("Unity Hub*");
|
|
|
|
}
|
2023-07-02 14:14:10 +00:00
|
|
|
}
|
|
|
|
}
|
2023-06-07 20:13:51 +00:00
|
|
|
}
|