Skip to content

Commit

Permalink
Update notepadplusplus to wait on config file (#123)
Browse files Browse the repository at this point in the history
  • Loading branch information
MalwareMechanic authored Nov 29, 2022
1 parent 45e5f8c commit f27baca
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 23 deletions.
2 changes: 1 addition & 1 deletion packages/notepadplusplus.vm/notepadplusplus.vm.nuspec
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<package xmlns="http://schemas.microsoft.com/packaging/2015/06/nuspec.xsd">
<metadata>
<id>notepadplusplus.vm</id>
<version>8.4.7</version>
<version>8.4.7.20221129</version>
<description>Wrapper for Notepad++</description>
<authors>Don Ho</authors>
<dependencies>
Expand Down
58 changes: 36 additions & 22 deletions packages/notepadplusplus.vm/tools/chocolateyinstall.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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 $_
}

0 comments on commit f27baca

Please sign in to comment.