| 1 | param([Parameter(Mandatory=$true)][string]$Root, [Parameter(Mandatory=$true)][string]$CloneHost) |
| 2 | Set-StrictMode -Version Latest |
| 3 | $ErrorActionPreference = 'Stop' |
| 4 | & "$PSScriptRoot\cold-current.ps1" -Root $Root -CloneHost $CloneHost |
| 5 | $app = New-Object -ComObject OneNote.Application |
| 6 | $notebook = '' |
| 7 | try { |
| 8 | $app.OpenHierarchy((Join-Path $Root 'notebook'), '', [ref]$notebook, 0) |
| 9 | $section = '' |
| 10 | $app.OpenHierarchy('Lifecycle.one', $notebook, [ref]$section, 0) |
| 11 | $page = '' |
| 12 | $app.CreateNewPage($section, [ref]$page, 2) |
| 13 | $title = 'Native after Rust removal ' + [char]::ConvertFromUtf32(0x1F98B) + ' e' + [char]0x0301 |
| 14 | $xml = '<one:Page xmlns:one="http://schemas.microsoft.com/office/onenote/2010/onenote" ID="' + $page + '"><one:Title><one:OE><one:T><![CDATA[' + $title + ']]></one:T></one:OE></one:Title><one:Outline><one:OEChildren><one:OE><one:T><![CDATA[<b>Native body after Rust removal.</b>]]></one:T></one:OE></one:OEChildren></one:Outline></one:Page>' |
| 15 | $app.UpdatePageContent($xml, [DateTime]::MinValue, 1, $false) |
| 16 | $app.SyncHierarchy($notebook) |
| 17 | [IO.File]::WriteAllText("$Root\native-title.txt", $title, [Text.Encoding]::UTF8) |
| 18 | } finally { |
| 19 | try { if ($notebook) { $app.CloseNotebook($notebook, $false) } } |
| 20 | finally { |
| 21 | [void][Runtime.InteropServices.Marshal]::FinalReleaseComObject($app) |
| 22 | $app = $null |
| 23 | [GC]::Collect() |
| 24 | [GC]::WaitForPendingFinalizers() |
| 25 | Get-Process ONENOTE -ErrorAction SilentlyContinue | Wait-Process -Timeout 120 -ErrorAction SilentlyContinue |
| 26 | } |
| 27 | } |