23 lines
1.2 KiB
PowerShell
23 lines
1.2 KiB
PowerShell
$f = "E:\GitHub\blog\bot\tray.ps1"
|
|||
|
|
$s = [System.IO.File]::ReadAllText($f, [System.Text.Encoding]::UTF8)
|
||
|
|
# Find the MessageBox catch and replace it
|
||
|
|
$old = ' [System.Windows.Forms.MessageBox]::Show(' + [char]10 + ' "Node.js' + [char]0x672A + [char]0x5B89 + [char]0x88C5 + [char]0x6216 + [char]0x65E0 + [char]0x6CD5 + [char]0x542F + [char]0x52A8' + [char]0x3002 + '"`n`n$_",'
|
||
|
|
Write-Host "searching..."
|
||
|
|
$idx = $s.IndexOf("catch {`n [System.Windows.Forms.MessageBox]")
|
||
|
|
if ($idx -lt 0) { $idx = $s.IndexOf("MessageBox") }
|
||
|
|
Write-Host "idx: $idx"
|
||
|
|
if ($idx -gt 0) {
|
||
|
|
$before = $s.Substring(0, $idx)
|
||
|
|
$afterMarker = " exit 1`n}`n`n|notifyIcon"
|
||
|
|
# find the closing } after the MessageBox catch
|
||
|
|
$afterIdx = $idx + 200
|
||
|
|
$remaining = $s.Substring($afterIdx)
|
||
|
|
$closePos = $remaining.IndexOf("exit 1") + 7
|
||
|
|
$after = $s.Substring($afterIdx + $closePos)
|
||
|
|
$replacement = "} catch {`n `$log = Join-Path `$BotDir `".tray-error.log`"`n `"tray.ps1 failed: `$_`" | Out-File `$log -Encoding UTF8`n `$notifyIcon.Visible = `$false`n exit 1`n}`n"
|
||
|
|
$s = $before + $replacement + $after
|
||
|
|
[System.IO.File]::WriteAllText($f, $s, [System.Text.UTF8Encoding]::new($true))
|
||
|
|
Write-Host "PATCHED"
|
||
|
|
} else {
|
||
|
|
Write-Host "NOT FOUND"
|
||
|
|
}
|