| 1 | param([Parameter(Mandatory=$true)][string]$Root, [string]$CloneHost = '') |
| 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') { |
| 6 | throw 'Choose a run directly below C:\one-tests\runs.' |
| 7 | } |
| 8 | if (Get-Process ONENOTE -ErrorAction SilentlyContinue) { throw 'Close OneNote before resetting its test cache.' } |
| 9 | $key = 'HKCU:\Software\Microsoft\Office\14.0\OneNote' |
| 10 | if ($CloneHost) { |
| 11 | if ($CloneHost -notmatch '^ONE-[A-Z0-9-]+$' -or [Environment]::MachineName -ne $CloneHost) { |
| 12 | throw 'The disposable clone hostname does not match this machine.' |
| 13 | } |
| 14 | New-Item "$key\Options\Paths" -Force | Out-Null |
| 15 | New-ItemProperty "$key\Options\Paths" -Name UnfiledNotesSection -PropertyType ExpandString -Value 'C:\one-tests\Loose.one' -Force | Out-Null |
| 16 | } elseif ((Get-ItemProperty "$key\Options\Paths").UnfiledNotesSection -ne 'C:\one-tests\Loose.one' -or |
| 17 | -not (Test-Path 'C:\one-tests\profile-original-cache')) { |
| 18 | throw 'Park the personal OneNote profile before resetting the test cache.' |
| 19 | } |
| 20 | $cache = Join-Path $env:LOCALAPPDATA 'Microsoft\OneNote\14.0' |
| 21 | $parked = Join-Path 'C:\one-tests\caches' ([IO.Path]::GetFileName($root)) |
| 22 | if (Test-Path $parked) { throw 'Choose a new run; its parked cache already exists.' } |
| 23 | New-Item -ItemType Directory -Path 'C:\one-tests\caches' -Force | Out-Null |
| 24 | if (Test-Path $cache) { Move-Item -LiteralPath $cache -Destination $parked } |
| 25 | if (Test-Path "$key\OpenNotebooks") { Remove-Item "$key\OpenNotebooks" -Recurse } |
| 26 | New-Item "$key\OpenNotebooks" | Out-Null |
| 27 | New-ItemProperty "$key\OpenNotebooks" -Name '1' -PropertyType String -Value "$root\notebook" | Out-Null |