From 8eb786e39ac141d3516944f7ed916149ec74a993 Mon Sep 17 00:00:00 2001 From: Dmitry Nefedov Date: Sun, 28 May 2023 00:30:35 +0300 Subject: [PATCH] Fixed typos --- .../Module/Sophia.psm1 | 38 ++++++++++++------- src/Sophia_Script_for_Windows_10/Sophia.ps1 | 6 +-- .../Module/Sophia.psm1 | 38 ++++++++++++------- .../Sophia.ps1 | 6 +-- .../Module/Sophia.psm1 | 38 ++++++++++++------- .../Sophia.ps1 | 6 +-- .../Module/Sophia.psm1 | 38 ++++++++++++------- .../Sophia.ps1 | 6 +-- .../Module/Sophia.psm1 | 38 ++++++++++++------- src/Sophia_Script_for_Windows_11/Sophia.ps1 | 6 +-- .../Module/Sophia.psm1 | 38 ++++++++++++------- .../Sophia.ps1 | 6 +-- 12 files changed, 162 insertions(+), 102 deletions(-) diff --git a/src/Sophia_Script_for_Windows_10/Module/Sophia.psm1 b/src/Sophia_Script_for_Windows_10/Module/Sophia.psm1 index 97cd59a0..ef4c0499 100644 --- a/src/Sophia_Script_for_Windows_10/Module/Sophia.psm1 +++ b/src/Sophia_Script_for_Windows_10/Module/Sophia.psm1 @@ -8934,13 +8934,13 @@ function Set-Association if (-not (Test-Path -Path $ProgramPath)) { # We cannot call here $MyInvocation.Line.Trim() to print function with error - ($Icon) + if ($Icon) { - Write-Error -Message ($Localization.RestartFunction -f "Set-Association -ProgramPath $ProgramPath -Extension $Extension -Icon $Icon") -ErrorAction SilentlyContinue + Write-Error -Message ($Localization.RestartFunction -f "Set-Association -ProgramPath `"$ProgramPath`" -Extension $Extension -Icon `"$Icon`"") -ErrorAction SilentlyContinue } else { - Write-Error -Message ($Localization.RestartFunction -f "Set-Association -ProgramPath $ProgramPath -Extension $Extension") -ErrorAction SilentlyContinue + Write-Error -Message ($Localization.RestartFunction -f "Set-Association -ProgramPath `"$ProgramPath`" -Extension $Extension") -ErrorAction SilentlyContinue } return @@ -8952,13 +8952,13 @@ function Set-Association if (-not (Test-Path -Path "Registry::HKEY_CLASSES_ROOT\$ProgramPath")) { # We cannot call here $MyInvocation.Line.Trim() to print function with error - ($Icon) + if ($Icon) { - Write-Error -Message ($Localization.RestartFunction -f "Set-Association -ProgramPath $ProgramPath -Extension $Extension -Icon $Icon") -ErrorAction SilentlyContinue + Write-Error -Message ($Localization.RestartFunction -f "Set-Association -ProgramPath `"$ProgramPath`" -Extension `"$Extension`" -Icon `"$Icon`"") -ErrorAction SilentlyContinue } else { - Write-Error -Message ($Localization.RestartFunction -f "Set-Association -ProgramPath $ProgramPath -Extension $Extension") -ErrorAction SilentlyContinue + Write-Error -Message ($Localization.RestartFunction -f "Set-Association -ProgramPath `"$ProgramPath`" -Extension `"$Extension`"") -ErrorAction SilentlyContinue } return @@ -9727,7 +9727,7 @@ public static void Refresh() Export-Associations .NOTES - Associations will be exported as AppAssoc.json file in script root folder + Associations will be exported as Application_Associations.json file in script root folder .NOTES Import exported JSON file after a clean installation. You have to install all apps according to an exported JSON file to restore all associations @@ -9737,14 +9737,14 @@ public static void Refresh() #> function Export-Associations { - Dism.exe /Online /Export-DefaultAppAssociations:"$env:TEMP\AppAssoc.xml" + Dism.exe /Online /Export-DefaultAppAssociations:"$env:TEMP\Application_Associations.xml" Clear-Variable -Name AllJSON, ProgramPath, Icon -ErrorAction Ignore $AllJSON = @() $AppxProgIds = @((Get-ChildItem -Path "Registry::HKEY_CLASSES_ROOT\Local Settings\Software\Microsoft\Windows\CurrentVersion\AppModel\PackageRepository\Extensions\ProgIDs").PSChildName) - [xml]$XML = Get-Content -Path "$env:TEMP\AppAssoc.xml" -Encoding UTF8 -Force + [xml]$XML = Get-Content -Path "$env:TEMP\Application_Associations.xml" -Encoding UTF8 -Force $XML.DefaultAssociations.Association | ForEach-Object -Process { if ($AppxProgIds -contains $_.ProgId) { @@ -9878,9 +9878,9 @@ function Export-Associations $AllJSON += $JSON } - $AllJSON | ConvertTo-Json | Set-Content -Path "$PSScriptRoot\..\AppAssoc.json" -Force -Encoding utf8 + $AllJSON | ConvertTo-Json | Set-Content -Path "$PSScriptRoot\..\Application_Associations.json" -Force -Encoding utf8 - Remove-Item -Path "$env:TEMP\AppAssoc.xml" -Force + Remove-Item -Path "$env:TEMP\Application_Associations.xml" -Force } <# @@ -9915,19 +9915,29 @@ function Import-Associations { $AppxProgIds = @((Get-ChildItem -Path "Registry::HKEY_CLASSES_ROOT\Local Settings\Software\Microsoft\Windows\CurrentVersion\AppModel\PackageRepository\Extensions\ProgIDs").PSChildName) - $JSON = Get-Content -Path $OpenFileDialog.FileName -Encoding UTF8 -Force | ConvertFrom-JSON + try + { + $JSON = Get-Content -Path $OpenFileDialog.FileName -Encoding UTF8 -Force | ConvertFrom-JSON + } + catch [System.Exception] + { + Write-Error -Message ($Localization.RestartFunction -f $MyInvocation.Line.Trim()) -ErrorAction SilentlyContinue + + return + } + $JSON | ForEach-Object -Process { if ($AppxProgIds -contains $_.ProgId) { Write-Information -MessageData "" -InformationAction Continue - Write-Verbose -Message ([string]($_.ProgId, '|', $_.Extension)) -Verbose + Write-Verbose -Message ([string]($_.ProgId, "|", $_.Extension)) -Verbose Set-Association -ProgramPath $_.ProgId -Extension $_.Extension } else { Write-Information -MessageData "" -InformationAction Continue - Write-Verbose -Message ([string]($_.ProgrammPath, '|', $_.Extension, '|', $_.Icon)) -Verbose + Write-Verbose -Message ([string]($_.ProgrammPath, "|", $_.Extension, "|", $_.Icon)) -Verbose Set-Association -ProgramPath $_.ProgrammPath -Extension $_.Extension -Icon $_.Icon } diff --git a/src/Sophia_Script_for_Windows_10/Sophia.ps1 b/src/Sophia_Script_for_Windows_10/Sophia.ps1 index c9b547bf..3a731200 100644 --- a/src/Sophia_Script_for_Windows_10/Sophia.ps1 +++ b/src/Sophia_Script_for_Windows_10/Sophia.ps1 @@ -959,13 +959,13 @@ ActiveHours -Automatically # Set-Association -ProgramPath "%ProgramFiles%\Notepad++\notepad++.exe" -Extension .txt -Icon "%ProgramFiles%\Notepad++\notepad++.exe,0" <# - Export all Windows associations. Associations will be exported as AppAssoc.json file in script root folder + Export all Windows associations. Associations will be exported as Application_Associations.json file in script root folder Import exported JSON file after a clean installation. You have to install all apps according to an exported JSON file to restore all associations #> -Export-Associations +# Export-Associations # Import all Windows associations from a JSON file. You have to install all apps according to an exported JSON file to restore all associations -Import-Associations +# Import-Associations <# Uninstall the "PC Health Check" app and prevent it from installing in the future 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 bd2d26f7..1d12fc27 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 @@ -7276,13 +7276,13 @@ function Set-Association if (-not (Test-Path -Path $ProgramPath)) { # We cannot call here $MyInvocation.Line.Trim() to print function with error - ($Icon) + if ($Icon) { - Write-Error -Message ($Localization.RestartFunction -f "Set-Association -ProgramPath $ProgramPath -Extension $Extension -Icon $Icon") -ErrorAction SilentlyContinue + Write-Error -Message ($Localization.RestartFunction -f "Set-Association -ProgramPath `"$ProgramPath`" -Extension $Extension -Icon `"$Icon`"") -ErrorAction SilentlyContinue } else { - Write-Error -Message ($Localization.RestartFunction -f "Set-Association -ProgramPath $ProgramPath -Extension $Extension") -ErrorAction SilentlyContinue + Write-Error -Message ($Localization.RestartFunction -f "Set-Association -ProgramPath `"$ProgramPath`" -Extension $Extension") -ErrorAction SilentlyContinue } return @@ -7294,13 +7294,13 @@ function Set-Association if (-not (Test-Path -Path "Registry::HKEY_CLASSES_ROOT\$ProgramPath")) { # We cannot call here $MyInvocation.Line.Trim() to print function with error - ($Icon) + if ($Icon) { - Write-Error -Message ($Localization.RestartFunction -f "Set-Association -ProgramPath $ProgramPath -Extension $Extension -Icon $Icon") -ErrorAction SilentlyContinue + Write-Error -Message ($Localization.RestartFunction -f "Set-Association -ProgramPath `"$ProgramPath`" -Extension `"$Extension`" -Icon `"$Icon`"") -ErrorAction SilentlyContinue } else { - Write-Error -Message ($Localization.RestartFunction -f "Set-Association -ProgramPath $ProgramPath -Extension $Extension") -ErrorAction SilentlyContinue + Write-Error -Message ($Localization.RestartFunction -f "Set-Association -ProgramPath `"$ProgramPath`" -Extension `"$Extension`"") -ErrorAction SilentlyContinue } return @@ -8069,7 +8069,7 @@ public static void Refresh() Export-Associations .NOTES - Associations will be exported as AppAssoc.json file in script root folder + Associations will be exported as Application_Associations.json file in script root folder .NOTES Import exported JSON file after a clean installation. You have to install all apps according to an exported JSON file to restore all associations @@ -8079,14 +8079,14 @@ public static void Refresh() #> function Export-Associations { - Dism.exe /Online /Export-DefaultAppAssociations:"$env:TEMP\AppAssoc.xml" + Dism.exe /Online /Export-DefaultAppAssociations:"$env:TEMP\Application_Associations.xml" Clear-Variable -Name AllJSON, ProgramPath, Icon -ErrorAction Ignore $AllJSON = @() $AppxProgIds = @((Get-ChildItem -Path "Registry::HKEY_CLASSES_ROOT\Local Settings\Software\Microsoft\Windows\CurrentVersion\AppModel\PackageRepository\Extensions\ProgIDs").PSChildName) - [xml]$XML = Get-Content -Path "$env:TEMP\AppAssoc.xml" -Encoding UTF8 -Force + [xml]$XML = Get-Content -Path "$env:TEMP\Application_Associations.xml" -Encoding UTF8 -Force $XML.DefaultAssociations.Association | ForEach-Object -Process { if ($AppxProgIds -contains $_.ProgId) { @@ -8220,9 +8220,9 @@ function Export-Associations $AllJSON += $JSON } - $AllJSON | ConvertTo-Json | Set-Content -Path "$PSScriptRoot\..\AppAssoc.json" -Force -Encoding utf8 + $AllJSON | ConvertTo-Json | Set-Content -Path "$PSScriptRoot\..\Application_Associations.json" -Force -Encoding utf8 - Remove-Item -Path "$env:TEMP\AppAssoc.xml" -Force + Remove-Item -Path "$env:TEMP\Application_Associations.xml" -Force } <# @@ -8257,19 +8257,29 @@ function Import-Associations { $AppxProgIds = @((Get-ChildItem -Path "Registry::HKEY_CLASSES_ROOT\Local Settings\Software\Microsoft\Windows\CurrentVersion\AppModel\PackageRepository\Extensions\ProgIDs").PSChildName) - $JSON = Get-Content -Path $OpenFileDialog.FileName -Encoding UTF8 -Force | ConvertFrom-JSON + try + { + $JSON = Get-Content -Path $OpenFileDialog.FileName -Encoding UTF8 -Force | ConvertFrom-JSON + } + catch [System.Exception] + { + Write-Error -Message ($Localization.RestartFunction -f $MyInvocation.Line.Trim()) -ErrorAction SilentlyContinue + + return + } + $JSON | ForEach-Object -Process { if ($AppxProgIds -contains $_.ProgId) { Write-Information -MessageData "" -InformationAction Continue - Write-Verbose -Message ([string]($_.ProgId, '|', $_.Extension)) -Verbose + Write-Verbose -Message ([string]($_.ProgId, "|", $_.Extension)) -Verbose Set-Association -ProgramPath $_.ProgId -Extension $_.Extension } else { Write-Information -MessageData "" -InformationAction Continue - Write-Verbose -Message ([string]($_.ProgrammPath, '|', $_.Extension, '|', $_.Icon)) -Verbose + Write-Verbose -Message ([string]($_.ProgrammPath, "|", $_.Extension, "|", $_.Icon)) -Verbose Set-Association -ProgramPath $_.ProgrammPath -Extension $_.Extension -Icon $_.Icon } 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 2586bf44..598217e2 100644 --- a/src/Sophia_Script_for_Windows_10_LTSC_2019/Sophia.ps1 +++ b/src/Sophia_Script_for_Windows_10_LTSC_2019/Sophia.ps1 @@ -768,13 +768,13 @@ ActiveHours -Automatically # Set-Association -ProgramPath "%ProgramFiles%\Notepad++\notepad++.exe" -Extension .txt -Icon "%ProgramFiles%\Notepad++\notepad++.exe,0" <# - Export all Windows associations. Associations will be exported as AppAssoc.json file in script root folder + Export all Windows associations. Associations will be exported as Application_Associations.json file in script root folder Import exported JSON file after a clean installation. You have to install all apps according to an exported JSON file to restore all associations #> -Export-Associations +# Export-Associations # Import all Windows associations from a JSON file. You have to install all apps according to an exported JSON file to restore all associations -Import-Associations +# Import-Associations <# Install the latest Microsoft Visual C++ Redistributable Packages 2015–2022 (x86/x64) 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 dd056472..546c1ebe 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 @@ -7904,13 +7904,13 @@ function Set-Association if (-not (Test-Path -Path $ProgramPath)) { # We cannot call here $MyInvocation.Line.Trim() to print function with error - ($Icon) + if ($Icon) { - Write-Error -Message ($Localization.RestartFunction -f "Set-Association -ProgramPath $ProgramPath -Extension $Extension -Icon $Icon") -ErrorAction SilentlyContinue + Write-Error -Message ($Localization.RestartFunction -f "Set-Association -ProgramPath `"$ProgramPath`" -Extension $Extension -Icon `"$Icon`"") -ErrorAction SilentlyContinue } else { - Write-Error -Message ($Localization.RestartFunction -f "Set-Association -ProgramPath $ProgramPath -Extension $Extension") -ErrorAction SilentlyContinue + Write-Error -Message ($Localization.RestartFunction -f "Set-Association -ProgramPath `"$ProgramPath`" -Extension $Extension") -ErrorAction SilentlyContinue } return @@ -7922,13 +7922,13 @@ function Set-Association if (-not (Test-Path -Path "Registry::HKEY_CLASSES_ROOT\$ProgramPath")) { # We cannot call here $MyInvocation.Line.Trim() to print function with error - ($Icon) + if ($Icon) { - Write-Error -Message ($Localization.RestartFunction -f "Set-Association -ProgramPath $ProgramPath -Extension $Extension -Icon $Icon") -ErrorAction SilentlyContinue + Write-Error -Message ($Localization.RestartFunction -f "Set-Association -ProgramPath `"$ProgramPath`" -Extension `"$Extension`" -Icon `"$Icon`"") -ErrorAction SilentlyContinue } else { - Write-Error -Message ($Localization.RestartFunction -f "Set-Association -ProgramPath $ProgramPath -Extension $Extension") -ErrorAction SilentlyContinue + Write-Error -Message ($Localization.RestartFunction -f "Set-Association -ProgramPath `"$ProgramPath`" -Extension `"$Extension`"") -ErrorAction SilentlyContinue } return @@ -8697,7 +8697,7 @@ public static void Refresh() Export-Associations .NOTES - Associations will be exported as AppAssoc.json file in script root folder + Associations will be exported as Application_Associations.json file in script root folder .NOTES Import exported JSON file after a clean installation. You have to install all apps according to an exported JSON file to restore all associations @@ -8707,14 +8707,14 @@ public static void Refresh() #> function Export-Associations { - Dism.exe /Online /Export-DefaultAppAssociations:"$env:TEMP\AppAssoc.xml" + Dism.exe /Online /Export-DefaultAppAssociations:"$env:TEMP\Application_Associations.xml" Clear-Variable -Name AllJSON, ProgramPath, Icon -ErrorAction Ignore $AllJSON = @() $AppxProgIds = @((Get-ChildItem -Path "Registry::HKEY_CLASSES_ROOT\Local Settings\Software\Microsoft\Windows\CurrentVersion\AppModel\PackageRepository\Extensions\ProgIDs").PSChildName) - [xml]$XML = Get-Content -Path "$env:TEMP\AppAssoc.xml" -Encoding UTF8 -Force + [xml]$XML = Get-Content -Path "$env:TEMP\Application_Associations.xml" -Encoding UTF8 -Force $XML.DefaultAssociations.Association | ForEach-Object -Process { if ($AppxProgIds -contains $_.ProgId) { @@ -8848,9 +8848,9 @@ function Export-Associations $AllJSON += $JSON } - $AllJSON | ConvertTo-Json | Set-Content -Path "$PSScriptRoot\..\AppAssoc.json" -Force -Encoding utf8 + $AllJSON | ConvertTo-Json | Set-Content -Path "$PSScriptRoot\..\Application_Associations.json" -Force -Encoding utf8 - Remove-Item -Path "$env:TEMP\AppAssoc.xml" -Force + Remove-Item -Path "$env:TEMP\Application_Associations.xml" -Force } <# @@ -8885,19 +8885,29 @@ function Import-Associations { $AppxProgIds = @((Get-ChildItem -Path "Registry::HKEY_CLASSES_ROOT\Local Settings\Software\Microsoft\Windows\CurrentVersion\AppModel\PackageRepository\Extensions\ProgIDs").PSChildName) - $JSON = Get-Content -Path $OpenFileDialog.FileName -Encoding UTF8 -Force | ConvertFrom-JSON + try + { + $JSON = Get-Content -Path $OpenFileDialog.FileName -Encoding UTF8 -Force | ConvertFrom-JSON + } + catch [System.Exception] + { + Write-Error -Message ($Localization.RestartFunction -f $MyInvocation.Line.Trim()) -ErrorAction SilentlyContinue + + return + } + $JSON | ForEach-Object -Process { if ($AppxProgIds -contains $_.ProgId) { Write-Information -MessageData "" -InformationAction Continue - Write-Verbose -Message ([string]($_.ProgId, '|', $_.Extension)) -Verbose + Write-Verbose -Message ([string]($_.ProgId, "|", $_.Extension)) -Verbose Set-Association -ProgramPath $_.ProgId -Extension $_.Extension } else { Write-Information -MessageData "" -InformationAction Continue - Write-Verbose -Message ([string]($_.ProgrammPath, '|', $_.Extension, '|', $_.Icon)) -Verbose + Write-Verbose -Message ([string]($_.ProgrammPath, "|", $_.Extension, "|", $_.Icon)) -Verbose Set-Association -ProgramPath $_.ProgrammPath -Extension $_.Extension -Icon $_.Icon } diff --git a/src/Sophia_Script_for_Windows_10_LTSC_2021/Sophia.ps1 b/src/Sophia_Script_for_Windows_10_LTSC_2021/Sophia.ps1 index 67267f57..5e701101 100644 --- a/src/Sophia_Script_for_Windows_10_LTSC_2021/Sophia.ps1 +++ b/src/Sophia_Script_for_Windows_10_LTSC_2021/Sophia.ps1 @@ -865,13 +865,13 @@ ActiveHours -Automatically # Set-Association -ProgramPath "%ProgramFiles%\Notepad++\notepad++.exe" -Extension .txt -Icon "%ProgramFiles%\Notepad++\notepad++.exe,0" <# - Export all Windows associations. Associations will be exported as AppAssoc.json file in script root folder + Export all Windows associations. Associations will be exported as Application_Associations.json file in script root folder Import exported JSON file after a clean installation. You have to install all apps according to an exported JSON file to restore all associations #> -Export-Associations +# Export-Associations # Import all Windows associations from a JSON file. You have to install all apps according to an exported JSON file to restore all associations -Import-Associations +# Import-Associations <# Install the latest Microsoft Visual C++ Redistributable Packages 2015–2022 (x86/x64) diff --git a/src/Sophia_Script_for_Windows_10_PowerShell_7/Module/Sophia.psm1 b/src/Sophia_Script_for_Windows_10_PowerShell_7/Module/Sophia.psm1 index 2304293a..fd0e1e5d 100644 --- a/src/Sophia_Script_for_Windows_10_PowerShell_7/Module/Sophia.psm1 +++ b/src/Sophia_Script_for_Windows_10_PowerShell_7/Module/Sophia.psm1 @@ -8939,13 +8939,13 @@ function Set-Association if (-not (Test-Path -Path $ProgramPath)) { # We cannot call here $MyInvocation.Line.Trim() to print function with error - ($Icon) + if ($Icon) { - Write-Error -Message ($Localization.RestartFunction -f "Set-Association -ProgramPath $ProgramPath -Extension $Extension -Icon $Icon") -ErrorAction SilentlyContinue + Write-Error -Message ($Localization.RestartFunction -f "Set-Association -ProgramPath `"$ProgramPath`" -Extension $Extension -Icon `"$Icon`"") -ErrorAction SilentlyContinue } else { - Write-Error -Message ($Localization.RestartFunction -f "Set-Association -ProgramPath $ProgramPath -Extension $Extension") -ErrorAction SilentlyContinue + Write-Error -Message ($Localization.RestartFunction -f "Set-Association -ProgramPath `"$ProgramPath`" -Extension $Extension") -ErrorAction SilentlyContinue } return @@ -8957,13 +8957,13 @@ function Set-Association if (-not (Test-Path -Path "Registry::HKEY_CLASSES_ROOT\$ProgramPath")) { # We cannot call here $MyInvocation.Line.Trim() to print function with error - ($Icon) + if ($Icon) { - Write-Error -Message ($Localization.RestartFunction -f "Set-Association -ProgramPath $ProgramPath -Extension $Extension -Icon $Icon") -ErrorAction SilentlyContinue + Write-Error -Message ($Localization.RestartFunction -f "Set-Association -ProgramPath `"$ProgramPath`" -Extension `"$Extension`" -Icon `"$Icon`"") -ErrorAction SilentlyContinue } else { - Write-Error -Message ($Localization.RestartFunction -f "Set-Association -ProgramPath $ProgramPath -Extension $Extension") -ErrorAction SilentlyContinue + Write-Error -Message ($Localization.RestartFunction -f "Set-Association -ProgramPath `"$ProgramPath`" -Extension `"$Extension`"") -ErrorAction SilentlyContinue } return @@ -9732,7 +9732,7 @@ public static void Refresh() Export-Associations .NOTES - Associations will be exported as AppAssoc.json file in script root folder + Associations will be exported as Application_Associations.json file in script root folder .NOTES Import exported JSON file after a clean installation. You have to install all apps according to an exported JSON file to restore all associations @@ -9742,14 +9742,14 @@ public static void Refresh() #> function Export-Associations { - Dism.exe /Online /Export-DefaultAppAssociations:"$env:TEMP\AppAssoc.xml" + Dism.exe /Online /Export-DefaultAppAssociations:"$env:TEMP\Application_Associations.xml" Clear-Variable -Name AllJSON, ProgramPath, Icon -ErrorAction Ignore $AllJSON = @() $AppxProgIds = @((Get-ChildItem -Path "Registry::HKEY_CLASSES_ROOT\Local Settings\Software\Microsoft\Windows\CurrentVersion\AppModel\PackageRepository\Extensions\ProgIDs").PSChildName) - [xml]$XML = Get-Content -Path "$env:TEMP\AppAssoc.xml" -Encoding UTF8 -Force + [xml]$XML = Get-Content -Path "$env:TEMP\Application_Associations.xml" -Encoding UTF8 -Force $XML.DefaultAssociations.Association | ForEach-Object -Process { if ($AppxProgIds -contains $_.ProgId) { @@ -9883,9 +9883,9 @@ function Export-Associations $AllJSON += $JSON } - $AllJSON | ConvertTo-Json | Set-Content -Path "$PSScriptRoot\..\AppAssoc.json" -Force -Encoding utf8 + $AllJSON | ConvertTo-Json | Set-Content -Path "$PSScriptRoot\..\Application_Associations.json" -Force -Encoding utf8 - Remove-Item -Path "$env:TEMP\AppAssoc.xml" -Force + Remove-Item -Path "$env:TEMP\Application_Associations.xml" -Force } <# @@ -9920,19 +9920,29 @@ function Import-Associations { $AppxProgIds = @((Get-ChildItem -Path "Registry::HKEY_CLASSES_ROOT\Local Settings\Software\Microsoft\Windows\CurrentVersion\AppModel\PackageRepository\Extensions\ProgIDs").PSChildName) - $JSON = Get-Content -Path $OpenFileDialog.FileName -Encoding UTF8 -Force | ConvertFrom-JSON + try + { + $JSON = Get-Content -Path $OpenFileDialog.FileName -Encoding UTF8 -Force | ConvertFrom-JSON + } + catch [System.Exception] + { + Write-Error -Message ($Localization.RestartFunction -f $MyInvocation.Line.Trim()) -ErrorAction SilentlyContinue + + return + } + $JSON | ForEach-Object -Process { if ($AppxProgIds -contains $_.ProgId) { Write-Information -MessageData "" -InformationAction Continue - Write-Verbose -Message ([string]($_.ProgId, '|', $_.Extension)) -Verbose + Write-Verbose -Message ([string]($_.ProgId, "|", $_.Extension)) -Verbose Set-Association -ProgramPath $_.ProgId -Extension $_.Extension } else { Write-Information -MessageData "" -InformationAction Continue - Write-Verbose -Message ([string]($_.ProgrammPath, '|', $_.Extension, '|', $_.Icon)) -Verbose + Write-Verbose -Message ([string]($_.ProgrammPath, "|", $_.Extension, "|", $_.Icon)) -Verbose Set-Association -ProgramPath $_.ProgrammPath -Extension $_.Extension -Icon $_.Icon } diff --git a/src/Sophia_Script_for_Windows_10_PowerShell_7/Sophia.ps1 b/src/Sophia_Script_for_Windows_10_PowerShell_7/Sophia.ps1 index 21334969..d862f055 100644 --- a/src/Sophia_Script_for_Windows_10_PowerShell_7/Sophia.ps1 +++ b/src/Sophia_Script_for_Windows_10_PowerShell_7/Sophia.ps1 @@ -968,13 +968,13 @@ ActiveHours -Automatically # Set-Association -ProgramPath "%ProgramFiles%\Notepad++\notepad++.exe" -Extension .txt -Icon "%ProgramFiles%\Notepad++\notepad++.exe,0" <# - Export all Windows associations. Associations will be exported as AppAssoc.json file in script root folder + Export all Windows associations. Associations will be exported as Application_Associations.json file in script root folder Import exported JSON file after a clean installation. You have to install all apps according to an exported JSON file to restore all associations #> -Export-Associations +# Export-Associations # Import all Windows associations from a JSON file. You have to install all apps according to an exported JSON file to restore all associations -Import-Associations +# Import-Associations <# Uninstall the "PC Health Check" app and prevent it from installing in the future diff --git a/src/Sophia_Script_for_Windows_11/Module/Sophia.psm1 b/src/Sophia_Script_for_Windows_11/Module/Sophia.psm1 index 37586f05..aff9a688 100644 --- a/src/Sophia_Script_for_Windows_11/Module/Sophia.psm1 +++ b/src/Sophia_Script_for_Windows_11/Module/Sophia.psm1 @@ -8611,13 +8611,13 @@ function Set-Association if (-not (Test-Path -Path $ProgramPath)) { # We cannot call here $MyInvocation.Line.Trim() to print function with error - ($Icon) + if ($Icon) { - Write-Error -Message ($Localization.RestartFunction -f "Set-Association -ProgramPath $ProgramPath -Extension $Extension -Icon $Icon") -ErrorAction SilentlyContinue + Write-Error -Message ($Localization.RestartFunction -f "Set-Association -ProgramPath `"$ProgramPath`" -Extension $Extension -Icon `"$Icon`"") -ErrorAction SilentlyContinue } else { - Write-Error -Message ($Localization.RestartFunction -f "Set-Association -ProgramPath $ProgramPath -Extension $Extension") -ErrorAction SilentlyContinue + Write-Error -Message ($Localization.RestartFunction -f "Set-Association -ProgramPath `"$ProgramPath`" -Extension $Extension") -ErrorAction SilentlyContinue } return @@ -8629,13 +8629,13 @@ function Set-Association if (-not (Test-Path -Path "Registry::HKEY_CLASSES_ROOT\$ProgramPath")) { # We cannot call here $MyInvocation.Line.Trim() to print function with error - ($Icon) + if ($Icon) { - Write-Error -Message ($Localization.RestartFunction -f "Set-Association -ProgramPath $ProgramPath -Extension $Extension -Icon $Icon") -ErrorAction SilentlyContinue + Write-Error -Message ($Localization.RestartFunction -f "Set-Association -ProgramPath `"$ProgramPath`" -Extension `"$Extension`" -Icon `"$Icon`"") -ErrorAction SilentlyContinue } else { - Write-Error -Message ($Localization.RestartFunction -f "Set-Association -ProgramPath $ProgramPath -Extension $Extension") -ErrorAction SilentlyContinue + Write-Error -Message ($Localization.RestartFunction -f "Set-Association -ProgramPath `"$ProgramPath`" -Extension `"$Extension`"") -ErrorAction SilentlyContinue } return @@ -9404,7 +9404,7 @@ public static void Refresh() Export-Associations .NOTES - Associations will be exported as AppAssoc.json file in script root folder + Associations will be exported as Application_Associations.json file in script root folder .NOTES Import exported JSON file after a clean installation. You have to install all apps according to an exported JSON file to restore all associations @@ -9414,14 +9414,14 @@ public static void Refresh() #> function Export-Associations { - Dism.exe /Online /Export-DefaultAppAssociations:"$env:TEMP\AppAssoc.xml" + Dism.exe /Online /Export-DefaultAppAssociations:"$env:TEMP\Application_Associations.xml" Clear-Variable -Name AllJSON, ProgramPath, Icon -ErrorAction Ignore $AllJSON = @() $AppxProgIds = @((Get-ChildItem -Path "Registry::HKEY_CLASSES_ROOT\Local Settings\Software\Microsoft\Windows\CurrentVersion\AppModel\PackageRepository\Extensions\ProgIDs").PSChildName) - [xml]$XML = Get-Content -Path "$env:TEMP\AppAssoc.xml" -Encoding UTF8 -Force + [xml]$XML = Get-Content -Path "$env:TEMP\Application_Associations.xml" -Encoding UTF8 -Force $XML.DefaultAssociations.Association | ForEach-Object -Process { if ($AppxProgIds -contains $_.ProgId) { @@ -9555,9 +9555,9 @@ function Export-Associations $AllJSON += $JSON } - $AllJSON | ConvertTo-Json | Set-Content -Path "$PSScriptRoot\..\AppAssoc.json" -Force -Encoding utf8 + $AllJSON | ConvertTo-Json | Set-Content -Path "$PSScriptRoot\..\Application_Associations.json" -Force -Encoding utf8 - Remove-Item -Path "$env:TEMP\AppAssoc.xml" -Force + Remove-Item -Path "$env:TEMP\Application_Associations.xml" -Force } <# @@ -9592,19 +9592,29 @@ function Import-Associations { $AppxProgIds = @((Get-ChildItem -Path "Registry::HKEY_CLASSES_ROOT\Local Settings\Software\Microsoft\Windows\CurrentVersion\AppModel\PackageRepository\Extensions\ProgIDs").PSChildName) - $JSON = Get-Content -Path $OpenFileDialog.FileName -Encoding UTF8 -Force | ConvertFrom-JSON + try + { + $JSON = Get-Content -Path $OpenFileDialog.FileName -Encoding UTF8 -Force | ConvertFrom-JSON + } + catch [System.Exception] + { + Write-Error -Message ($Localization.RestartFunction -f $MyInvocation.Line.Trim()) -ErrorAction SilentlyContinue + + return + } + $JSON | ForEach-Object -Process { if ($AppxProgIds -contains $_.ProgId) { Write-Information -MessageData "" -InformationAction Continue - Write-Verbose -Message ([string]($_.ProgId, '|', $_.Extension)) -Verbose + Write-Verbose -Message ([string]($_.ProgId, "|", $_.Extension)) -Verbose Set-Association -ProgramPath $_.ProgId -Extension $_.Extension } else { Write-Information -MessageData "" -InformationAction Continue - Write-Verbose -Message ([string]($_.ProgrammPath, '|', $_.Extension, '|', $_.Icon)) -Verbose + Write-Verbose -Message ([string]($_.ProgrammPath, "|", $_.Extension, "|", $_.Icon)) -Verbose Set-Association -ProgramPath $_.ProgrammPath -Extension $_.Extension -Icon $_.Icon } diff --git a/src/Sophia_Script_for_Windows_11/Sophia.ps1 b/src/Sophia_Script_for_Windows_11/Sophia.ps1 index b1766b56..6396fb65 100644 --- a/src/Sophia_Script_for_Windows_11/Sophia.ps1 +++ b/src/Sophia_Script_for_Windows_11/Sophia.ps1 @@ -914,13 +914,13 @@ WindowsLatestUpdate -Disable # Set-Association -ProgramPath "%ProgramFiles%\Notepad++\notepad++.exe" -Extension .txt -Icon "%ProgramFiles%\Notepad++\notepad++.exe,0" <# - Export all Windows associations. Associations will be exported as AppAssoc.json file in script root folder + Export all Windows associations. Associations will be exported as Application_Associations.json file in script root folder Import exported JSON file after a clean installation. You have to install all apps according to an exported JSON file to restore all associations #> -Export-Associations +# Export-Associations # Import all Windows associations from a JSON file. You have to install all apps according to an exported JSON file to restore all associations -Import-Associations +# Import-Associations # Set Windows Terminal as default terminal app to host the user interface for command-line applications # Установить Windows Terminal как приложение терминала по умолчанию для размещения пользовательского интерфейса для приложений командной строки diff --git a/src/Sophia_Script_for_Windows_11_PowerShell_7/Module/Sophia.psm1 b/src/Sophia_Script_for_Windows_11_PowerShell_7/Module/Sophia.psm1 index eb831207..f8a93818 100644 --- a/src/Sophia_Script_for_Windows_11_PowerShell_7/Module/Sophia.psm1 +++ b/src/Sophia_Script_for_Windows_11_PowerShell_7/Module/Sophia.psm1 @@ -8616,13 +8616,13 @@ function Set-Association if (-not (Test-Path -Path $ProgramPath)) { # We cannot call here $MyInvocation.Line.Trim() to print function with error - ($Icon) + if ($Icon) { - Write-Error -Message ($Localization.RestartFunction -f "Set-Association -ProgramPath $ProgramPath -Extension $Extension -Icon $Icon") -ErrorAction SilentlyContinue + Write-Error -Message ($Localization.RestartFunction -f "Set-Association -ProgramPath `"$ProgramPath`" -Extension $Extension -Icon `"$Icon`"") -ErrorAction SilentlyContinue } else { - Write-Error -Message ($Localization.RestartFunction -f "Set-Association -ProgramPath $ProgramPath -Extension $Extension") -ErrorAction SilentlyContinue + Write-Error -Message ($Localization.RestartFunction -f "Set-Association -ProgramPath `"$ProgramPath`" -Extension $Extension") -ErrorAction SilentlyContinue } return @@ -8634,13 +8634,13 @@ function Set-Association if (-not (Test-Path -Path "Registry::HKEY_CLASSES_ROOT\$ProgramPath")) { # We cannot call here $MyInvocation.Line.Trim() to print function with error - ($Icon) + if ($Icon) { - Write-Error -Message ($Localization.RestartFunction -f "Set-Association -ProgramPath $ProgramPath -Extension $Extension -Icon $Icon") -ErrorAction SilentlyContinue + Write-Error -Message ($Localization.RestartFunction -f "Set-Association -ProgramPath `"$ProgramPath`" -Extension `"$Extension`" -Icon `"$Icon`"") -ErrorAction SilentlyContinue } else { - Write-Error -Message ($Localization.RestartFunction -f "Set-Association -ProgramPath $ProgramPath -Extension $Extension") -ErrorAction SilentlyContinue + Write-Error -Message ($Localization.RestartFunction -f "Set-Association -ProgramPath `"$ProgramPath`" -Extension `"$Extension`"") -ErrorAction SilentlyContinue } return @@ -9409,7 +9409,7 @@ public static void Refresh() Export-Associations .NOTES - Associations will be exported as AppAssoc.json file in script root folder + Associations will be exported as Application_Associations.json file in script root folder .NOTES Import exported JSON file after a clean installation. You have to install all apps according to an exported JSON file to restore all associations @@ -9419,14 +9419,14 @@ public static void Refresh() #> function Export-Associations { - Dism.exe /Online /Export-DefaultAppAssociations:"$env:TEMP\AppAssoc.xml" + Dism.exe /Online /Export-DefaultAppAssociations:"$env:TEMP\Application_Associations.xml" Clear-Variable -Name AllJSON, ProgramPath, Icon -ErrorAction Ignore $AllJSON = @() $AppxProgIds = @((Get-ChildItem -Path "Registry::HKEY_CLASSES_ROOT\Local Settings\Software\Microsoft\Windows\CurrentVersion\AppModel\PackageRepository\Extensions\ProgIDs").PSChildName) - [xml]$XML = Get-Content -Path "$env:TEMP\AppAssoc.xml" -Encoding UTF8 -Force + [xml]$XML = Get-Content -Path "$env:TEMP\Application_Associations.xml" -Encoding UTF8 -Force $XML.DefaultAssociations.Association | ForEach-Object -Process { if ($AppxProgIds -contains $_.ProgId) { @@ -9560,9 +9560,9 @@ function Export-Associations $AllJSON += $JSON } - $AllJSON | ConvertTo-Json | Set-Content -Path "$PSScriptRoot\..\AppAssoc.json" -Force -Encoding utf8 + $AllJSON | ConvertTo-Json | Set-Content -Path "$PSScriptRoot\..\Application_Associations.json" -Force -Encoding utf8 - Remove-Item -Path "$env:TEMP\AppAssoc.xml" -Force + Remove-Item -Path "$env:TEMP\Application_Associations.xml" -Force } <# @@ -9597,19 +9597,29 @@ function Import-Associations { $AppxProgIds = @((Get-ChildItem -Path "Registry::HKEY_CLASSES_ROOT\Local Settings\Software\Microsoft\Windows\CurrentVersion\AppModel\PackageRepository\Extensions\ProgIDs").PSChildName) - $JSON = Get-Content -Path $OpenFileDialog.FileName -Encoding UTF8 -Force | ConvertFrom-JSON + try + { + $JSON = Get-Content -Path $OpenFileDialog.FileName -Encoding UTF8 -Force | ConvertFrom-JSON + } + catch [System.Exception] + { + Write-Error -Message ($Localization.RestartFunction -f $MyInvocation.Line.Trim()) -ErrorAction SilentlyContinue + + return + } + $JSON | ForEach-Object -Process { if ($AppxProgIds -contains $_.ProgId) { Write-Information -MessageData "" -InformationAction Continue - Write-Verbose -Message ([string]($_.ProgId, '|', $_.Extension)) -Verbose + Write-Verbose -Message ([string]($_.ProgId, "|", $_.Extension)) -Verbose Set-Association -ProgramPath $_.ProgId -Extension $_.Extension } else { Write-Information -MessageData "" -InformationAction Continue - Write-Verbose -Message ([string]($_.ProgrammPath, '|', $_.Extension, '|', $_.Icon)) -Verbose + Write-Verbose -Message ([string]($_.ProgrammPath, "|", $_.Extension, "|", $_.Icon)) -Verbose Set-Association -ProgramPath $_.ProgrammPath -Extension $_.Extension -Icon $_.Icon } diff --git a/src/Sophia_Script_for_Windows_11_PowerShell_7/Sophia.ps1 b/src/Sophia_Script_for_Windows_11_PowerShell_7/Sophia.ps1 index 8ef2409b..b96e50df 100644 --- a/src/Sophia_Script_for_Windows_11_PowerShell_7/Sophia.ps1 +++ b/src/Sophia_Script_for_Windows_11_PowerShell_7/Sophia.ps1 @@ -915,13 +915,13 @@ NetworkDiscovery -Enable # Set-Association -ProgramPath "%ProgramFiles%\Notepad++\notepad++.exe" -Extension .txt -Icon "%ProgramFiles%\Notepad++\notepad++.exe,0" <# - Export all Windows associations. Associations will be exported as AppAssoc.json file in script root folder + Export all Windows associations. Associations will be exported as Application_Associations.json file in script root folder Import exported JSON file after a clean installation. You have to install all apps according to an exported JSON file to restore all associations #> -Export-Associations +# Export-Associations # Import all Windows associations from a JSON file. You have to install all apps according to an exported JSON file to restore all associations -Import-Associations +# Import-Associations # Set Windows Terminal as default terminal app to host the user interface for command-line applications # Установить Windows Terminal как приложение терминала по умолчанию для размещения пользовательского интерфейса для приложений командной строки