|
| 1 | +# MD Editor - Windows Install Script |
| 2 | +# Run as Administrator: Right-click > Run with PowerShell |
| 3 | +# This script creates file associations for .md files |
| 4 | + |
| 5 | +param( |
| 6 | + [string]$InstallDir = "$env:LOCALAPPDATA\MD Editor" |
| 7 | +) |
| 8 | + |
| 9 | +$ErrorActionPreference = "Stop" |
| 10 | + |
| 11 | +Write-Host "MD Editor - Windows Installation" -ForegroundColor Cyan |
| 12 | +Write-Host "=================================" -ForegroundColor Cyan |
| 13 | +Write-Host "" |
| 14 | + |
| 15 | +# Check for admin rights (required for HKLM registry and ProgID) |
| 16 | +$isAdmin = ([Security.Principal.WindowsPrincipal] [Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator) |
| 17 | + |
| 18 | +# Source directory (where the unpacked app is) |
| 19 | +$sourceDir = Join-Path $PSScriptRoot "dist\win-unpacked" |
| 20 | +$exeName = "MD Editor.exe" |
| 21 | + |
| 22 | +if (-not (Test-Path (Join-Path $sourceDir $exeName))) { |
| 23 | + Write-Host "Error: Could not find '$exeName' in $sourceDir" -ForegroundColor Red |
| 24 | + Write-Host "Please run 'npm run pack' first to build the app." -ForegroundColor Yellow |
| 25 | + Read-Host "Press Enter to exit" |
| 26 | + exit 1 |
| 27 | +} |
| 28 | + |
| 29 | +# Copy to install directory |
| 30 | +Write-Host "Installing to: $InstallDir" -ForegroundColor Green |
| 31 | +if (Test-Path $InstallDir) { |
| 32 | + Remove-Item $InstallDir -Recurse -Force |
| 33 | +} |
| 34 | +Copy-Item $sourceDir $InstallDir -Recurse |
| 35 | +Write-Host " Files copied." -ForegroundColor Gray |
| 36 | + |
| 37 | +$exePath = Join-Path $InstallDir $exeName |
| 38 | + |
| 39 | +# Create Start Menu shortcut |
| 40 | +$startMenuDir = Join-Path $env:APPDATA "Microsoft\Windows\Start Menu\Programs" |
| 41 | +$shortcutPath = Join-Path $startMenuDir "MD Editor.lnk" |
| 42 | +$shell = New-Object -ComObject WScript.Shell |
| 43 | +$shortcut = $shell.CreateShortcut($shortcutPath) |
| 44 | +$shortcut.TargetPath = $exePath |
| 45 | +$shortcut.WorkingDirectory = $InstallDir |
| 46 | +$shortcut.Description = "Markdown Editor" |
| 47 | +$shortcut.Save() |
| 48 | +Write-Host " Start Menu shortcut created." -ForegroundColor Gray |
| 49 | + |
| 50 | +# Create Desktop shortcut |
| 51 | +$desktopShortcut = Join-Path ([Environment]::GetFolderPath("Desktop")) "MD Editor.lnk" |
| 52 | +$shortcut2 = $shell.CreateShortcut($desktopShortcut) |
| 53 | +$shortcut2.TargetPath = $exePath |
| 54 | +$shortcut2.WorkingDirectory = $InstallDir |
| 55 | +$shortcut2.Description = "Markdown Editor" |
| 56 | +$shortcut2.Save() |
| 57 | +Write-Host " Desktop shortcut created." -ForegroundColor Gray |
| 58 | + |
| 59 | +# Set up file associations |
| 60 | +$regRoot = if ($isAdmin) { "HKLM:" } else { "HKCU:" } |
| 61 | +$regPrefix = if ($isAdmin) { "HKEY_LOCAL_MACHINE" } else { "HKEY_CURRENT_USER" } |
| 62 | + |
| 63 | +Write-Host "Setting up .md file association..." -ForegroundColor Green |
| 64 | + |
| 65 | +# Register the application ProgID |
| 66 | +$progId = "MDEditor.MarkdownFile" |
| 67 | +$progIdPath = "$regRoot\SOFTWARE\Classes\$progId" |
| 68 | +New-Item -Path $progIdPath -Force | Out-Null |
| 69 | +Set-ItemProperty -Path $progIdPath -Name "(Default)" -Value "Markdown Document" |
| 70 | + |
| 71 | +# Set icon |
| 72 | +$iconPath = "$progIdPath\DefaultIcon" |
| 73 | +New-Item -Path $iconPath -Force | Out-Null |
| 74 | +Set-ItemProperty -Path $iconPath -Name "(Default)" -Value "`"$exePath`",0" |
| 75 | + |
| 76 | +# Set open command |
| 77 | +$commandPath = "$progIdPath\shell\open\command" |
| 78 | +New-Item -Path $commandPath -Force | Out-Null |
| 79 | +Set-ItemProperty -Path $commandPath -Name "(Default)" -Value "`"$exePath`" `"%1`"" |
| 80 | + |
| 81 | +# Associate .md extension |
| 82 | +$extPath = "$regRoot\SOFTWARE\Classes\.md" |
| 83 | +New-Item -Path $extPath -Force | Out-Null |
| 84 | +Set-ItemProperty -Path $extPath -Name "(Default)" -Value $progId |
| 85 | + |
| 86 | +# Associate .markdown extension |
| 87 | +$extPath2 = "$regRoot\SOFTWARE\Classes\.markdown" |
| 88 | +New-Item -Path $extPath2 -Force | Out-Null |
| 89 | +Set-ItemProperty -Path $extPath2 -Name "(Default)" -Value $progId |
| 90 | + |
| 91 | +Write-Host " .md and .markdown files associated with MD Editor." -ForegroundColor Gray |
| 92 | + |
| 93 | +# Notify Windows of the change |
| 94 | +$code = @" |
| 95 | +[System.Runtime.InteropServices.DllImport("shell32.dll")] |
| 96 | +public static extern void SHChangeNotify(int wEventId, int uFlags, System.IntPtr dwItem1, System.IntPtr dwItem2); |
| 97 | +"@ |
| 98 | +$type = Add-Type -MemberDefinition $code -Name "ShellNotify" -Namespace "Win32" -PassThru |
| 99 | +$type::SHChangeNotify(0x08000000, 0, [System.IntPtr]::Zero, [System.IntPtr]::Zero) |
| 100 | + |
| 101 | +Write-Host "" |
| 102 | +Write-Host "Installation complete!" -ForegroundColor Green |
| 103 | +Write-Host "" |
| 104 | +Write-Host "You can now:" -ForegroundColor Cyan |
| 105 | +Write-Host " - Double-click any .md file to open it in MD Editor" |
| 106 | +Write-Host " - Launch from Start Menu or Desktop shortcut" |
| 107 | +Write-Host " - Run from: $exePath" |
| 108 | +Write-Host "" |
| 109 | + |
| 110 | +if (-not $isAdmin) { |
| 111 | + Write-Host "Note: Run as Administrator for system-wide file association." -ForegroundColor Yellow |
| 112 | + Write-Host "Current installation is per-user only." -ForegroundColor Yellow |
| 113 | +} |
| 114 | + |
| 115 | +Read-Host "Press Enter to exit" |
0 commit comments