| 1 | param([Parameter(Mandatory=$true)][string]$Root) |
| 2 | Set-StrictMode -Version Latest |
| 3 | $ErrorActionPreference = 'Stop' |
| 4 | $root = [IO.Path]::GetFullPath($Root).TrimEnd('\') |
| 5 | if ([IO.Path]::GetDirectoryName($root) -ne 'C:\one-tests\runs') { throw 'Choose a run directly below C:\one-tests\runs.' } |
| 6 | & "$PSScriptRoot\cold-current.ps1" -Root $root |
| 7 | $app = New-Object -ComObject OneNote.Application |
| 8 | $notebook = '' |
| 9 | try { |
| 10 | $app.OpenHierarchy("$root\notebook", '', [ref]$notebook, 0) |
| 11 | $section = '' |
| 12 | $app.OpenHierarchy('synthetic.one', $notebook, [ref]$section, 0) |
| 13 | $page = '' |
| 14 | $app.CreateNewPage($section, [ref]$page, 2) |
| 15 | $xml = '<one:Page xmlns:one="http://schemas.microsoft.com/office/onenote/2010/onenote" ID="' + $page + '"><one:Outline><one:OEChildren><one:OE><one:T>Recoverable deletion marker.</one:T></one:OE></one:OEChildren></one:Outline></one:Page>' |
| 16 | $app.UpdatePageContent($xml, [DateTime]::MinValue, 1, $false) |
| 17 | $app.SyncHierarchy($notebook) |
| 18 | $app.CloseNotebook($notebook, $false) |
| 19 | Copy-Item "$root\notebook" "$root\before" -Recurse |
| 20 | $app.OpenHierarchy("$root\notebook", '', [ref]$notebook, 0) |
| 21 | $app.OpenHierarchy('synthetic.one', $notebook, [ref]$section, 0) |
| 22 | $hierarchy = '' |
| 23 | $app.GetHierarchy($section, 4, [ref]$hierarchy, 1) |
| 24 | [xml]$tree = $hierarchy |
| 25 | $target = @($tree.SelectNodes('//*[local-name()="Page"]') | Where-Object { $_.GetAttribute('name') -eq 'Recoverable deletion marker.' }) |
| 26 | if ($target.Count -ne 1) { throw 'The generated deletion page did not persist.' } |
| 27 | $app.DeleteHierarchy($target[0].GetAttribute('ID'), [DateTime]::MinValue, $false) |
| 28 | $app.SyncHierarchy($notebook) |
| 29 | } finally { |
| 30 | if ($notebook) { $app.CloseNotebook($notebook, $false) } |
| 31 | [void][Runtime.InteropServices.Marshal]::FinalReleaseComObject($app) |
| 32 | $app = $null |
| 33 | [GC]::Collect() |
| 34 | [GC]::WaitForPendingFinalizers() |
| 35 | Get-Process ONENOTE -ErrorAction SilentlyContinue | Wait-Process -Timeout 10 |
| 36 | } |