diff --git a/packages/notepadplusplus.vm/notepadplusplus.vm.nuspec b/packages/notepadplusplus.vm/notepadplusplus.vm.nuspec index 421ccdc85..87da31f3a 100644 --- a/packages/notepadplusplus.vm/notepadplusplus.vm.nuspec +++ b/packages/notepadplusplus.vm/notepadplusplus.vm.nuspec @@ -2,7 +2,7 @@ notepadplusplus.vm - 8.4.7 + 8.4.7.20221129 Wrapper for Notepad++ Don Ho diff --git a/packages/notepadplusplus.vm/tools/chocolateyinstall.ps1 b/packages/notepadplusplus.vm/tools/chocolateyinstall.ps1 index 3861bb9a2..f3b1745c8 100644 --- a/packages/notepadplusplus.vm/tools/chocolateyinstall.ps1 +++ b/packages/notepadplusplus.vm/tools/chocolateyinstall.ps1 @@ -2,31 +2,45 @@ $ErrorActionPreference = 'Stop' Import-Module vm.common -Force -DisableNameChecking try { - # Path to Notepad++'s configuration file - $configFile = Join-Path ${Env:APPDATA} "Notepad++\config.xml" + # Path to Notepad++'s configuration file + $configFile = Join-Path ${Env:APPDATA} "Notepad++\config.xml" - if (-Not (Test-Path -Path $configFile)) { - # Launch Notepad++ - Start-Process "notepad++" - Start-Sleep -Seconds 2 + if (-Not (Test-Path -Path $configFile)) { + # Launch Notepad++ + Start-Process "notepad++" - # Try to gracefully close it so that it can create it's config.xml - # Give it a little time in case it's slow - foreach ($item in "0", "1") { - $notepad = Get-Process -Name "notepad++" -ErrorAction SilentlyContinue - if ($null -ne $notepad) { - $notepad | ForEach-Object {$_.CloseMainWindow() | Out-Null} - } - Start-Sleep -Seconds 2 + # Wait for notepad++ to appear + while ((Get-Process | Where-Object { $_.mainWindowTitle -and $_.name -eq "notepad++" }).Count -eq 0) { + Start-Sleep -Seconds 1 + } + + # Try to gracefully close it so that it can create it's config.xml + # Give it a little time in case it's slow + foreach ($item in "0", "1") { + $notepad = Get-Process -Name "notepad++" -ErrorAction SilentlyContinue + if ($null -ne $notepad) { + $notepad | ForEach-Object {$_.CloseMainWindow() | Out-Null} + } + Start-Sleep -Seconds 2 + } + } + + # Wait for config.xml to exist after notepad++ exits + $count = 0 + while (-Not (Test-Path -Path $configFile)) { + Start-Sleep -Seconds 1 + if ($count++ -eq 10) { + break + } } - } - if (-Not (Test-Path -Path $configFile)) { - VM-Write-Log "WARN" "Can't find config.xml to modify" - } else { - # Update the config file and disable auto-updates - (Get-Content -Path $configFile) -Replace '("noUpdate".*?">)no', '$1yes' | Set-Content -Path $configFile -Force | Out-Null - } + if (-Not (Test-Path -Path $configFile)) { + VM-Write-Log "WARN" "Can't find Notepad++'s config.xml to disable auto-updates, skipping..." + } else { + # Update the config file and disable auto-updates + (Get-Content -Path $configFile) -Replace '("noUpdate".*?">)no', '$1yes' | Set-Content -Path $configFile -Force | Out-Null + } } catch { - VM-Write-Log-Exception $_ + VM-Write-Log-Exception $_ } +