-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathInstall.ps1
More file actions
70 lines (62 loc) · 4.03 KB
/
Copy pathInstall.ps1
File metadata and controls
70 lines (62 loc) · 4.03 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
# OutlookExportMarkdown — Install Script
# Run this script once to install the add-in permanently.
# To uninstall, run: Uninstall.ps1
$installDir = "$env:APPDATA\OutlookExportMarkdown"
$sourceDir = "$PSScriptRoot\OutlookExportMarkdown\bin\Release"
$progId = "OutlookExportMarkdown"
# ── 1. Build Release ─────────────────────────────────────────────────────────
Write-Host "Building Release..." -ForegroundColor Cyan
$msbuild = Get-ChildItem "C:\Program Files\Microsoft Visual Studio" -Recurse -Filter "MSBuild.exe" -ErrorAction SilentlyContinue |
Where-Object { $_.FullName -match "Current\\Bin" } | Select-Object -First 1 FullName
if (-not $msbuild) { Write-Error "MSBuild not found. Install Visual Studio."; exit 1 }
& $msbuild.FullName "$PSScriptRoot\OutlookExportMarkdown\OutlookExportMarkdown.csproj" /p:Configuration=Release /verbosity:minimal
if ($LASTEXITCODE -ne 0) { Write-Error "Build failed."; exit 1 }
Write-Host "Build OK" -ForegroundColor Green
# ── 2. Copy files to install folder ──────────────────────────────────────────
Write-Host "Installing to $installDir ..." -ForegroundColor Cyan
if (-not (Test-Path $installDir)) { New-Item -ItemType Directory -Path $installDir | Out-Null }
$files = @(
"OutlookExportMarkdown.dll",
"OutlookExportMarkdown.dll.manifest",
"OutlookExportMarkdown.vsto",
"HtmlAgilityPack.dll",
"ReverseMarkdown.dll",
"Microsoft.Office.Tools.Common.v4.0.Utilities.dll",
"Microsoft.Office.Tools.Outlook.v4.0.Utilities.dll"
)
foreach ($f in $files) {
$src = Join-Path $sourceDir $f
if (Test-Path $src) { Copy-Item $src $installDir -Force }
}
Write-Host "Files copied" -ForegroundColor Green
# ── 3. Register add-in in Outlook ────────────────────────────────────────────
Write-Host "Registering add-in..." -ForegroundColor Cyan
$vstoPath = "file:///$($installDir.Replace('\','/'))/$($progId).vsto|vstolocal"
$regPath = "HKCU:\SOFTWARE\Microsoft\Office\Outlook\Addins\$progId"
if (-not (Test-Path $regPath)) { New-Item -Path $regPath -Force | Out-Null }
Set-ItemProperty $regPath -Name "Description" -Value "Exports Outlook email threads to Markdown files"
Set-ItemProperty $regPath -Name "FriendlyName" -Value "Outlook Export Markdown"
Set-ItemProperty $regPath -Name "LoadBehavior" -Value 3 -Type DWord
Set-ItemProperty $regPath -Name "Manifest" -Value $vstoPath
Write-Host "Registry OK" -ForegroundColor Green
# ── 4. Add VSTO trust entry ───────────────────────────────────────────────────
Write-Host "Adding VSTO trust..." -ForegroundColor Cyan
$trustRoot = "HKCU:\SOFTWARE\Microsoft\VSTO\Security\Inclusion"
if (-not (Test-Path $trustRoot)) { New-Item -Path $trustRoot -Force | Out-Null }
# Find existing entry for this manifest or create a new GUID key
$vstoUrl = "file:///$($installDir.Replace('\','/'))/OutlookExportMarkdown.vsto"
$existingKey = Get-ChildItem $trustRoot -ErrorAction SilentlyContinue |
Where-Object { (Get-ItemProperty $_.PSPath).Url -eq $vstoUrl } |
Select-Object -First 1
if (-not $existingKey) {
$guid = [System.Guid]::NewGuid().ToString("B").ToUpper()
$trustKey = "$trustRoot\$guid"
New-Item -Path $trustKey -Force | Out-Null
Set-ItemProperty $trustKey -Name "Url" -Value $vstoUrl
Set-ItemProperty $trustKey -Name "PublicKeyToken" -Value ""
}
Write-Host "Trust OK" -ForegroundColor Green
# ── Done ──────────────────────────────────────────────────────────────────────
Write-Host ""
Write-Host "Installation complete." -ForegroundColor Green
Write-Host "Restart Outlook to activate the add-in."