diff --git a/Wrapper/Config/before_after.json b/Wrapper/Config/before_after.json new file mode 100644 index 00000000..2bcc75e8 --- /dev/null +++ b/Wrapper/Config/before_after.json @@ -0,0 +1,22 @@ +[ + { + "Id": 100, + "Region": "before", + "Function": "", + }, + { + "Id": 101, + "Region": "before", + "Function": "", + }, + { + "Id": 200, + "Region": "after", + "Function": "PostActions", + }, + { + "Id": 201, + "Region": "after", + "Function": "Errors", + } +] diff --git a/Wrapper/SophiaScriptWrapper.exe b/Wrapper/SophiaScriptWrapper.exe index c6121263..e2f82b2b 100644 Binary files a/Wrapper/SophiaScriptWrapper.exe and b/Wrapper/SophiaScriptWrapper.exe differ diff --git a/src/Sophia_Script_for_Windows_10/Module/Sophia.psm1 b/src/Sophia_Script_for_Windows_10/Module/Sophia.psm1 index eebcfc69..bb7a3407 100644 --- a/src/Sophia_Script_for_Windows_10/Module/Sophia.psm1 +++ b/src/Sophia_Script_for_Windows_10/Module/Sophia.psm1 @@ -4442,16 +4442,10 @@ function OneDrive return } - # Check if script was launched from OneDrive folder and preset file has function to uninstall OneDrive - # Check how the script was invoked: via a preset or Function.ps1 - $PresetName = (Get-PSCallStack).Position | Where-Object -FilterScript { - (($_.File -match ".ps1") -and ($_.File -notmatch "Functions.ps1")) -and ($_.Text -eq "OneDrive -Uninstall") -or ($_.Text -match "Invoke-Expression") - } # Check if user is logged into OneDrive account (Microsoft account) $UserEmail = Get-ItemProperty -Path HKCU:\Software\Microsoft\OneDrive\Accounts\Personal -Name UserEmail -ErrorAction Ignore - if ($PresetName -and $UserEmail) + if ($UserEmail) { - # Exit if user accidentally set function in preset to uninstall but he's logged into the app return } @@ -7706,6 +7700,7 @@ function WinPrtScrFolder $PresetName = (Get-PSCallStack).Position | Where-Object -FilterScript { (($_.File -match ".ps1") -and ($_.File -notmatch "Functions.ps1")) -and (($_.Text -eq "WinPrtScrFolder -Desktop") -or ($_.Text -match "Invoke-Expression")) } + if ($PresetName) { # Get the name of a preset (e.g Sophia.ps1) regardless it was named @@ -11844,6 +11839,8 @@ public static extern bool ShowWindowAsync(IntPtr hWnd, int nCmdShow); Description = $Localization.CleanupNotificationTaskDescription } Register-ScheduledTask @Parameters -Force + + $Script:ScheduledTasks = $true } "Delete" { @@ -12027,6 +12024,8 @@ Get-ChildItem -Path `$env:SystemRoot\SoftwareDistribution\Download -Recurse -For Description = $Localization.FolderTaskDescription -f "%SystemRoot%\SoftwareDistribution\Download" } Register-ScheduledTask @Parameters -Force + + $Script:ScheduledTasks = $true } "Delete" { @@ -12205,6 +12204,8 @@ Get-ChildItem -Path `$env:TEMP -Recurse -Force | Where-Object -FilterScript {`$_ Description = $Localization.FolderTaskDescription -f "%TEMP%" } Register-ScheduledTask @Parameters -Force + + $Script:ScheduledTasks = $true } "Delete" { @@ -14287,11 +14288,7 @@ public static void PostMessage() } # Check if any of scheduled tasks were created. Unless open Task Scheduler - # Check how the script was invoked: via a preset or Function.ps1 - $PresetName = (Get-PSCallStack).Position | Where-Object -FilterScript { - (($_.File -match ".ps1") -and ($_.File -notmatch "Functions.ps1")) -and (($_.Text -eq "CleanupTask -Register") -or ($_.Text -eq "CleanupTask -Register") -or ($_.Text -eq "TempTask -Register")) -or ($_.Text -match "Invoke-Expression") - } - if ($PresetName) + if ($Script:ScheduledTasks) { # Open Task Scheduler Start-Process -FilePath taskschd.msc diff --git a/src/Sophia_Script_for_Windows_10/Sophia.ps1 b/src/Sophia_Script_for_Windows_10/Sophia.ps1 index 5ff6477d..1506ccd6 100644 --- a/src/Sophia_Script_for_Windows_10/Sophia.ps1 +++ b/src/Sophia_Script_for_Windows_10/Sophia.ps1 @@ -979,7 +979,7 @@ InstallVCRedist <# Install the latest .NET Desktop Runtime 6, 7 (x86/x64) - Установить последнюю версию .NET Desktop Runtime 6 (x86/x64) + Установить последнюю версию .NET Desktop Runtime 6, 7 (x86/x64) https://dotnet.microsoft.com/en-us/download/dotnet #> diff --git a/src/Sophia_Script_for_Windows_10_LTSC_2019/Module/Sophia.psm1 b/src/Sophia_Script_for_Windows_10_LTSC_2019/Module/Sophia.psm1 index 86ba278a..c6a759df 100644 --- a/src/Sophia_Script_for_Windows_10_LTSC_2019/Module/Sophia.psm1 +++ b/src/Sophia_Script_for_Windows_10_LTSC_2019/Module/Sophia.psm1 @@ -8486,6 +8486,8 @@ public static extern bool ShowWindowAsync(IntPtr hWnd, int nCmdShow); Description = $Localization.CleanupNotificationTaskDescription } Register-ScheduledTask @Parameters -Force + + $Script:ScheduledTasks = $true } "Delete" { @@ -8669,6 +8671,8 @@ Get-ChildItem -Path `$env:SystemRoot\SoftwareDistribution\Download -Recurse -For Description = $Localization.FolderTaskDescription -f "%SystemRoot%\SoftwareDistribution\Download" } Register-ScheduledTask @Parameters -Force + + $Script:ScheduledTasks = $true } "Delete" { @@ -8847,6 +8851,8 @@ Get-ChildItem -Path `$env:TEMP -Recurse -Force | Where-Object -FilterScript {`$_ Description = $Localization.FolderTaskDescription -f "%TEMP%" } Register-ScheduledTask @Parameters -Force + + $Script:ScheduledTasks = $true } "Delete" { @@ -10707,11 +10713,7 @@ public static void PostMessage() } # Check if any of scheduled tasks were created. Unless open Task Scheduler - # Check how the script was invoked: via a preset or Function.ps1 - $PresetName = (Get-PSCallStack).Position | Where-Object -FilterScript { - (($_.File -match ".ps1") -and ($_.File -notmatch "Functions.ps1")) -and (($_.Text -eq "CleanupTask -Register") -or ($_.Text -eq "CleanupTask -Register") -or ($_.Text -eq "TempTask -Register")) -or ($_.Text -match "Invoke-Expression") - } - if ($PresetName) + if ($Script:ScheduledTasks) { # Open Task Scheduler Start-Process -FilePath taskschd.msc diff --git a/src/Sophia_Script_for_Windows_10_LTSC_2019/Sophia.ps1 b/src/Sophia_Script_for_Windows_10_LTSC_2019/Sophia.ps1 index 342389d0..1e575cbd 100644 --- a/src/Sophia_Script_for_Windows_10_LTSC_2019/Sophia.ps1 +++ b/src/Sophia_Script_for_Windows_10_LTSC_2019/Sophia.ps1 @@ -780,7 +780,7 @@ InstallVCRedist <# Install the latest .NET Desktop Runtime 6, 7 (x86/x64) - Установить последнюю версию .NET Desktop Runtime 6 (x86/x64) + Установить последнюю версию .NET Desktop Runtime 6, 7 (x86/x64) https://dotnet.microsoft.com/en-us/download/dotnet #> diff --git a/src/Sophia_Script_for_Windows_10_LTSC_2021/Module/Sophia.psm1 b/src/Sophia_Script_for_Windows_10_LTSC_2021/Module/Sophia.psm1 index 716e3200..0249559d 100644 --- a/src/Sophia_Script_for_Windows_10_LTSC_2021/Module/Sophia.psm1 +++ b/src/Sophia_Script_for_Windows_10_LTSC_2021/Module/Sophia.psm1 @@ -8297,7 +8297,13 @@ function InstallVCRedist Start-Process -FilePath "$DownloadsFolder\VC_redist.x64.exe" -ArgumentList "/install /passive /norestart" -Wait # PowerShell 5.1 (7.3 too) interprets 8.3 file name literally, if an environment variable contains a non-latin word - Get-ChildItem -Path "$DownloadsFolder\VC_redist.x86.exe", "$DownloadsFolder\VC_redist.x64.exe", "$env:TEMP\dd_vcredist_amdx86_*.log", "$env:TEMP\dd_vcredist_amd64_*.log" -Force | Remove-Item -Recurse -Force -ErrorAction Ignore + $Paths = @( + "$DownloadsFolder\VC_redist.x86.exe", + "$DownloadsFolder\VC_redist.x64.exe", + "$env:TEMP\dd_vcredist_x86_*.log", + "$env:TEMP\dd_vcredist_amd64_*.log" + ) + Get-ChildItem -Path $Paths -Recurse -Force | Remove-Item -Recurse -Force -ErrorAction Ignore } catch [System.Net.WebException] { @@ -8321,7 +8327,7 @@ function InstallVCRedist .NOTES Machine-wide #> -function InstallVCRedist +function InstallDotNetRuntimes { try { @@ -8339,41 +8345,95 @@ function InstallVCRedist if ([System.Version](Get-AppxPackage -Name Microsoft.DesktopAppInstaller -ErrorAction Ignore).Version -ge [System.Version]"1.17") { - winget install --id=Microsoft.VCRedist.2015+.x86 --exact --accept-source-agreements - winget install --id=Microsoft.VCRedist.2015+.x64 --exact --accept-source-agreements + # .NET Desktop Runtime 6 x86 + winget install --id=Microsoft.DotNet.DesktopRuntime.6 --architecture x86 --exact --accept-source-agreements + # .NET Desktop Runtime 7 x64 + winget install --id=Microsoft.DotNet.DesktopRuntime.6 --architecture x64 --exact --accept-source-agreements + + # .NET Desktop Runtime 7 x86 + winget install --id=Microsoft.DotNet.DesktopRuntime.7 --architecture x86 --exact --accept-source-agreements + # .NET Desktop Runtime 7 x64 + winget install --id=Microsoft.DotNet.DesktopRuntime.7 --architecture x64 --exact --accept-source-agreements } else { + # Install .NET Desktop Runtime 6 + # https://github.com/dotnet/core/blob/main/release-notes/releases-index.json + $Parameters = @{ + Uri = "https://dotnetcli.blob.core.windows.net/dotnet/release-metadata/6.0/releases.json" + UseBasicParsing = $true + } + $LatestRelease = (Invoke-RestMethod @Parameters)."latest-release" + $DownloadsFolder = Get-ItemPropertyValue -Path "HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders" -Name "{374DE290-123F-4565-9164-39C4925E467B}" + + # .NET Desktop Runtime 6 x86 + $Parameters = @{ + Uri = "https://dotnetcli.azureedge.net/dotnet/Runtime/$LatestRelease/dotnet-runtime-$LatestRelease-win-x86.exe" + OutFile = "$DownloadsFolder\dotnet-runtime-$LatestRelease-win-x86.exe" + UseBasicParsing = $true + Verbose = $true + } + Invoke-WebRequest @Parameters + + Start-Process -FilePath "$DownloadsFolder\dotnet-runtime-$LatestRelease-win-x86.exe" -ArgumentList "/install /passive /norestart" -Wait + + # .NET Desktop Runtime 6 x64 + $Parameters = @{ + Uri = "https://dotnetcli.azureedge.net/dotnet/Runtime/$LatestRelease/dotnet-runtime-$LatestRelease-win-x64.exe" + OutFile = "$DownloadsFolder\dotnet-runtime-$LatestRelease-win-x64.exe" + UseBasicParsing = $true + Verbose = $true + } + Invoke-WebRequest @Parameters + + Start-Process -FilePath "$DownloadsFolder\dotnet-runtime-$LatestRelease-win-x64.exe" -ArgumentList "/install /passive /norestart" -Wait + + # PowerShell 5.1 (7.3 too) interprets 8.3 file name literally, if an environment variable contains a non-latin word + $Paths = @( + "$DownloadsFolder\dotnet-runtime-$LatestRelease-win-x86.exe", + "$DownloadsFolder\dotnet-runtime-$LatestRelease-win-x64.exe", + "$env:TEMP\Microsoft_.NET_Runtime*.log" + ) + Get-ChildItem -Path $Paths -Force -ErrorAction Ignore | Remove-Item -Recurse -Force -ErrorAction Ignore + + # .NET Desktop Runtime 7 + # https://github.com/dotnet/core/blob/main/release-notes/releases-index.json + $Parameters = @{ + Uri = "https://dotnetcli.blob.core.windows.net/dotnet/release-metadata/7.0/releases.json" + UseBasicParsing = $true + } + $LatestRelease = (Invoke-RestMethod @Parameters)."latest-release" $DownloadsFolder = Get-ItemPropertyValue -Path "HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders" -Name "{374DE290-123F-4565-9164-39C4925E467B}" + + # .NET Desktop Runtime 7 x86 $Parameters = @{ - Uri = "https://aka.ms/vs/17/release/VC_redist.x86.exe" - OutFile = "$DownloadsFolder\VC_redist.x86.exe" + Uri = "https://dotnetcli.azureedge.net/dotnet/Runtime/$LatestRelease/dotnet-runtime-$LatestRelease-win-x86.exe" + OutFile = "$DownloadsFolder\dotnet-runtime-$LatestRelease-win-x86.exe" UseBasicParsing = $true Verbose = $true } Invoke-WebRequest @Parameters - Start-Process -FilePath "$DownloadsFolder\VC_redist.x86.exe" -ArgumentList "/install /passive /norestart" -Wait + Start-Process -FilePath "$DownloadsFolder\dotnet-runtime-$LatestRelease-win-x86.exe" -ArgumentList "/install /passive /norestart" -Wait + # .NET Desktop Runtime 7 x64 $Parameters = @{ - Uri = "https://aka.ms/vs/17/release/VC_redist.x64.exe" - OutFile = "$DownloadsFolder\VC_redist.x64.exe" + Uri = "https://dotnetcli.azureedge.net/dotnet/Runtime/$LatestRelease/dotnet-runtime-$LatestRelease-win-x64.exe" + OutFile = "$DownloadsFolder\dotnet-runtime-$LatestRelease-win-x64.exe" UseBasicParsing = $true Verbose = $true } Invoke-WebRequest @Parameters - Start-Process -FilePath "$DownloadsFolder\VC_redist.x64.exe" -ArgumentList "/install /passive /norestart" -Wait + Start-Process -FilePath "$DownloadsFolder\dotnet-runtime-$LatestRelease-win-x64.exe" -ArgumentList "/install /passive /norestart" -Wait # PowerShell 5.1 (7.3 too) interprets 8.3 file name literally, if an environment variable contains a non-latin word $Paths = @( - "$DownloadsFolder\VC_redist.x86.exe", - "$DownloadsFolder\VC_redist.x64.exe", - "$env:TEMP\dd_vcredist_x86_*.log", - "$env:TEMP\dd_vcredist_amd64_*.log", - "$env:TEMP\WinGet" + "$DownloadsFolder\dotnet-runtime-$LatestRelease-win-x86.exe", + "$DownloadsFolder\dotnet-runtime-$LatestRelease-win-x64.exe", + "$env:TEMP\Microsoft_.NET_Runtime*.log" ) - Get-ChildItem -Path $Paths -Recurse -Force | Remove-Item -Recurse -Force -ErrorAction Ignore + Get-ChildItem -Path $Paths -Force -ErrorAction Ignore | Remove-Item -Recurse -Force -ErrorAction Ignore } } catch [System.Net.WebException] @@ -8559,7 +8619,7 @@ function PreventEdgeShortcutCreation .SYNOPSIS Windows Subsystem for Linux (WSL) - .PARAMETER Install + .PARAMETER Enable Windows Subsystem for Linux (WSL), install the latest WSL Linux kernel version, and a Linux distribution using a pop-up form .EXAMPLE @@ -8573,6 +8633,15 @@ function PreventEdgeShortcutCreation #> function Install-WSL { + [System.Console]::OutputEncoding = [System.Text.Encoding]::Unicode + + $Distros = (wsl --list --online | Select-Object -Skip 8).Replace(" ", "").Replace("* ", "") | ForEach-Object -Process { + [PSCustomObject]@{ + "Distro" = $_ -split " ", 2 | Select-Object -Last 1 + "Alias" = $_ -split " ", 2 | Select-Object -First 1 + } + } + Add-Type -AssemblyName PresentationCore, PresentationFramework #region Variables @@ -8586,19 +8655,12 @@ function Install-WSL xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" Name="Window" Title="WSL" - MinHeight="400" MinWidth="350" + MinHeight="460" MinWidth="350" SizeToContent="WidthAndHeight" WindowStartupLocation="CenterScreen" TextOptions.TextFormattingMode="Display" SnapsToDevicePixels="True" FontFamily="Candara" FontSize="16" ShowInTaskbar="True" Background="#F1F1F1" Foreground="#262626"> - -