diff --git a/package.json b/package.json index c8fa45b..3def37c 100644 --- a/package.json +++ b/package.json @@ -45,6 +45,7 @@ "files": [ "src/**/*", "assets/**/*", + "scripts/**/*", "node_modules/**/*", "package.json" ], @@ -72,6 +73,14 @@ "target": "nsis", "icon": "assets/icon.ico" }, + "nsis": { + "oneClick": false, + "allowToChangeInstallationDirectory": true, + "createDesktopShortcut": true, + "createStartMenuShortcut": true, + "shortcutName": "PanConverter", + "include": "scripts/nsis-installer.nsh" + }, "linux": { "target": [ "deb", diff --git a/scripts/README.md b/scripts/README.md new file mode 100644 index 0000000..b0c8c1c --- /dev/null +++ b/scripts/README.md @@ -0,0 +1,116 @@ +# PanConverter Windows Explorer Context Menu Integration + +This directory contains scripts to add PanConverter to the Windows Explorer context menu, allowing you to right-click on files and convert them directly without opening the full application. + +## Features + +### Context Menu Options +- **Convert with PanConverter**: Shows a format selection dialog for any supported file +- **PanConverter > Convert to...**: Direct conversion options (for Markdown files) + - PDF + - HTML + - DOCX + - LaTeX + - PowerPoint + +### Supported File Types +- **Markdown**: `.md`, `.markdown` +- **HTML**: `.html`, `.htm` +- **Documents**: `.docx`, `.odt`, `.rtf` +- **LaTeX**: `.tex` +- **PDF**: `.pdf` +- **Presentations**: `.pptx`, `.ppt`, `.odp` + +## Installation Methods + +### Method 1: Automatic (During PanConverter Installation) +When installing PanConverter using the Windows installer, you'll be prompted to install context menu integration automatically. + +### Method 2: Manual Installation + +#### Using PowerShell (Recommended) +1. Right-click on `install-context-menu.ps1` +2. Select "Run with PowerShell" +3. Follow the prompts (will request administrator privileges) + +#### Using Batch File +1. Right-click on `install-context-menu.bat` +2. Select "Run as administrator" +3. Follow the prompts + +#### Using Registry File Directly +1. Right-click on `install-context-menu.reg` +2. Select "Merge" +3. Confirm the registry modification + +## Uninstallation + +### Using PowerShell +```powershell +.\install-context-menu.ps1 -Uninstall +``` + +### Using Batch File +Run `uninstall-context-menu.bat` as administrator + +### Using Registry File +Run `uninstall-context-menu.reg` + +## How It Works + +### Command Line Interface +The context menu integration works by passing command line arguments to PanConverter: + +- `--convert `: Shows conversion dialog for the specified file +- `--convert-to `: Directly converts to the specified format + +### Examples +```batch +# Show conversion dialog +PanConverter.exe --convert "document.md" + +# Direct conversion to PDF +PanConverter.exe --convert-to pdf "document.md" +``` + +### Conversion Process +1. PanConverter reads the input file +2. Creates a temporary file if needed +3. Uses Pandoc to convert to the target format +4. Saves the output in the same directory as the input file +5. Shows a Windows notification when complete + +## Requirements + +- PanConverter must be installed in the default location: `%LOCALAPPDATA%\Programs\PanConverter\` +- Pandoc must be installed and accessible from the command line +- Administrator privileges required for registry modifications + +## Troubleshooting + +### Context Menu Not Appearing +1. Ensure you ran the installation script as administrator +2. Try logging out and back in, or restart Windows Explorer +3. Check if PanConverter is installed in the expected location + +### Conversion Failures +1. Verify Pandoc is installed: `pandoc --version` +2. Check if the input file is not corrupted or locked +3. Ensure you have write permissions in the output directory + +### Permission Errors +- The installation scripts require administrator privileges to modify the registry +- If you get permission errors, right-click and "Run as administrator" + +## File Descriptions + +- `install-context-menu.reg`: Registry entries for context menu +- `uninstall-context-menu.reg`: Registry entries removal +- `install-context-menu.ps1`: PowerShell installation script +- `install-context-menu.bat`: Batch installation script +- `uninstall-context-menu.bat`: Batch uninstallation script +- `nsis-installer.nsh`: NSIS installer integration script + +## Security Note + +The scripts modify the Windows registry to add context menu entries. Only run these scripts if you trust the source and understand the changes being made to your system. \ No newline at end of file diff --git a/scripts/install-context-menu.bat b/scripts/install-context-menu.bat new file mode 100644 index 0000000..3526c34 --- /dev/null +++ b/scripts/install-context-menu.bat @@ -0,0 +1,48 @@ +@echo off +echo PanConverter Context Menu Installation +echo ===================================== +echo. + +REM Check for administrator privileges +net session >nul 2>&1 +if %errorLevel% == 0 ( + echo Running with administrator privileges... +) else ( + echo This script requires administrator privileges. + echo Please right-click and select "Run as administrator" + echo. + pause + exit /b 1 +) + +REM Check if PanConverter is installed +if not exist "%LOCALAPPDATA%\Programs\PanConverter\PanConverter.exe" ( + echo Warning: PanConverter not found at the expected location. + echo Please ensure PanConverter is installed before continuing. + echo Expected location: %LOCALAPPDATA%\Programs\PanConverter\PanConverter.exe + echo. + set /p continue="Continue anyway? (y/N): " + if /i not "%continue%"=="y" exit /b 1 +) + +echo Installing context menu entries... +reg import "%~dp0install-context-menu.reg" + +if %errorLevel% == 0 ( + echo. + echo Context menu integration installed successfully! + echo. + echo You can now right-click on supported files and select: + echo • "Convert with PanConverter" - Shows conversion dialog + echo • "PanConverter > Convert to..." - Direct conversion ^(for Markdown^) + echo. + echo Supported file types: + echo .md .markdown .html .htm .docx .odt .rtf .tex .pdf .pptx .ppt .odp +) else ( + echo. + echo Failed to install context menu entries. + echo Please check that the registry file exists and try again. +) + +echo. +pause \ No newline at end of file diff --git a/scripts/install-context-menu.ps1 b/scripts/install-context-menu.ps1 new file mode 100644 index 0000000..c067f3a --- /dev/null +++ b/scripts/install-context-menu.ps1 @@ -0,0 +1,67 @@ +# PanConverter Context Menu Installation Script +# This script installs PanConverter context menu integration for Windows Explorer + +param( + [switch]$Uninstall = $false +) + +# Check if running as administrator +if (-NOT ([Security.Principal.WindowsPrincipal] [Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole] "Administrator")) { + Write-Host "This script requires Administrator privileges. Restarting with elevated permissions..." -ForegroundColor Yellow + Start-Process PowerShell -Verb RunAs "-File `"$PSCommandPath`" $(if ($Uninstall) { '-Uninstall' })" + exit +} + +$scriptDir = Split-Path -Parent $MyInvocation.MyCommand.Path +$appPath = "${env:LOCALAPPDATA}\Programs\PanConverter\PanConverter.exe" + +if ($Uninstall) { + Write-Host "Uninstalling PanConverter context menu integration..." -ForegroundColor Yellow + $regFile = Join-Path $scriptDir "uninstall-context-menu.reg" + + if (Test-Path $regFile) { + reg import $regFile + if ($LASTEXITCODE -eq 0) { + Write-Host "PanConverter context menu has been successfully removed!" -ForegroundColor Green + } else { + Write-Host "Failed to remove context menu entries." -ForegroundColor Red + } + } else { + Write-Host "Uninstall registry file not found: $regFile" -ForegroundColor Red + } +} else { + Write-Host "Installing PanConverter context menu integration..." -ForegroundColor Yellow + + # Check if PanConverter is installed + if (-not (Test-Path $appPath)) { + Write-Host "Warning: PanConverter executable not found at: $appPath" -ForegroundColor Yellow + Write-Host "Please make sure PanConverter is installed before running this script." -ForegroundColor Yellow + $continue = Read-Host "Continue anyway? (y/N)" + if ($continue -ne 'y' -and $continue -ne 'Y') { + exit + } + } + + $regFile = Join-Path $scriptDir "install-context-menu.reg" + + if (Test-Path $regFile) { + reg import $regFile + if ($LASTEXITCODE -eq 0) { + Write-Host "PanConverter context menu has been successfully installed!" -ForegroundColor Green + Write-Host "" + Write-Host "You can now right-click on supported files (MD, HTML, DOCX, PDF, etc.) and select:" -ForegroundColor Cyan + Write-Host "• 'Convert with PanConverter' - Shows conversion dialog" -ForegroundColor Cyan + Write-Host "• 'PanConverter > Convert to...' - Direct conversion options (for Markdown files)" -ForegroundColor Cyan + Write-Host "" + Write-Host "Supported file types: .md, .markdown, .html, .htm, .docx, .odt, .rtf, .tex, .pdf, .pptx, .ppt, .odp" -ForegroundColor Gray + } else { + Write-Host "Failed to install context menu entries." -ForegroundColor Red + } + } else { + Write-Host "Install registry file not found: $regFile" -ForegroundColor Red + } +} + +Write-Host "" +Write-Host "Press any key to exit..." +$null = $Host.UI.RawUI.ReadKey("NoEcho,IncludeKeyDown") \ No newline at end of file diff --git a/scripts/install-context-menu.reg b/scripts/install-context-menu.reg new file mode 100644 index 0000000..6da6c84 --- /dev/null +++ b/scripts/install-context-menu.reg @@ -0,0 +1,134 @@ +Windows Registry Editor Version 5.00 + +; PanConverter Context Menu Integration +; This registry file adds context menu options for converting files using PanConverter + +; Add context menu for Markdown files (.md, .markdown) +[HKEY_CLASSES_ROOT\.md\shell\PanConverter] +@="Convert with PanConverter" +"Icon"="\"%LOCALAPPDATA%\\Programs\\PanConverter\\PanConverter.exe\"" + +[HKEY_CLASSES_ROOT\.md\shell\PanConverter\command] +@="\"%LOCALAPPDATA%\\Programs\\PanConverter\\PanConverter.exe\" --convert \"%1\"" + +[HKEY_CLASSES_ROOT\.markdown\shell\PanConverter] +@="Convert with PanConverter" +"Icon"="\"%LOCALAPPDATA%\\Programs\\PanConverter\\PanConverter.exe\"" + +[HKEY_CLASSES_ROOT\.markdown\shell\PanConverter\command] +@="\"%LOCALAPPDATA%\\Programs\\PanConverter\\PanConverter.exe\" --convert \"%1\"" + +; Add context menu for HTML files +[HKEY_CLASSES_ROOT\.html\shell\PanConverter] +@="Convert with PanConverter" +"Icon"="\"%LOCALAPPDATA%\\Programs\\PanConverter\\PanConverter.exe\"" + +[HKEY_CLASSES_ROOT\.html\shell\PanConverter\command] +@="\"%LOCALAPPDATA%\\Programs\\PanConverter\\PanConverter.exe\" --convert \"%1\"" + +[HKEY_CLASSES_ROOT\.htm\shell\PanConverter] +@="Convert with PanConverter" +"Icon"="\"%LOCALAPPDATA%\\Programs\\PanConverter\\PanConverter.exe\"" + +[HKEY_CLASSES_ROOT\.htm\shell\PanConverter\command] +@="\"%LOCALAPPDATA%\\Programs\\PanConverter\\PanConverter.exe\" --convert \"%1\"" + +; Add context menu for DOCX files +[HKEY_CLASSES_ROOT\.docx\shell\PanConverter] +@="Convert with PanConverter" +"Icon"="\"%LOCALAPPDATA%\\Programs\\PanConverter\\PanConverter.exe\"" + +[HKEY_CLASSES_ROOT\.docx\shell\PanConverter\command] +@="\"%LOCALAPPDATA%\\Programs\\PanConverter\\PanConverter.exe\" --convert \"%1\"" + +; Add context menu for ODT files +[HKEY_CLASSES_ROOT\.odt\shell\PanConverter] +@="Convert with PanConverter" +"Icon"="\"%LOCALAPPDATA%\\Programs\\PanConverter\\PanConverter.exe\"" + +[HKEY_CLASSES_ROOT\.odt\shell\PanConverter\command] +@="\"%LOCALAPPDATA%\\Programs\\PanConverter\\PanConverter.exe\" --convert \"%1\"" + +; Add context menu for RTF files +[HKEY_CLASSES_ROOT\.rtf\shell\PanConverter] +@="Convert with PanConverter" +"Icon"="\"%LOCALAPPDATA%\\Programs\\PanConverter\\PanConverter.exe\"" + +[HKEY_CLASSES_ROOT\.rtf\shell\PanConverter\command] +@="\"%LOCALAPPDATA%\\Programs\\PanConverter\\PanConverter.exe\" --convert \"%1\"" + +; Add context menu for LaTeX files +[HKEY_CLASSES_ROOT\.tex\shell\PanConverter] +@="Convert with PanConverter" +"Icon"="\"%LOCALAPPDATA%\\Programs\\PanConverter\\PanConverter.exe\"" + +[HKEY_CLASSES_ROOT\.tex\shell\PanConverter\command] +@="\"%LOCALAPPDATA%\\Programs\\PanConverter\\PanConverter.exe\" --convert \"%1\"" + +; Add context menu for PDF files +[HKEY_CLASSES_ROOT\.pdf\shell\PanConverter] +@="Convert with PanConverter" +"Icon"="\"%LOCALAPPDATA%\\Programs\\PanConverter\\PanConverter.exe\"" + +[HKEY_CLASSES_ROOT\.pdf\shell\PanConverter\command] +@="\"%LOCALAPPDATA%\\Programs\\PanConverter\\PanConverter.exe\" --convert \"%1\"" + +; Add context menu for PowerPoint files +[HKEY_CLASSES_ROOT\.pptx\shell\PanConverter] +@="Convert with PanConverter" +"Icon"="\"%LOCALAPPDATA%\\Programs\\PanConverter\\PanConverter.exe\"" + +[HKEY_CLASSES_ROOT\.pptx\shell\PanConverter\command] +@="\"%LOCALAPPDATA%\\Programs\\PanConverter\\PanConverter.exe\" --convert \"%1\"" + +[HKEY_CLASSES_ROOT\.ppt\shell\PanConverter] +@="Convert with PanConverter" +"Icon"="\"%LOCALAPPDATA%\\Programs\\PanConverter\\PanConverter.exe\"" + +[HKEY_CLASSES_ROOT\.ppt\shell\PanConverter\command] +@="\"%LOCALAPPDATA%\\Programs\\PanConverter\\PanConverter.exe\" --convert \"%1\"" + +; Add context menu for OpenDocument Presentation files +[HKEY_CLASSES_ROOT\.odp\shell\PanConverter] +@="Convert with PanConverter" +"Icon"="\"%LOCALAPPDATA%\\Programs\\PanConverter\\PanConverter.exe\"" + +[HKEY_CLASSES_ROOT\.odp\shell\PanConverter\command] +@="\"%LOCALAPPDATA%\\Programs\\PanConverter\\PanConverter.exe\" --convert \"%1\"" + +; Add submenu with specific conversion options for Markdown files +[HKEY_CLASSES_ROOT\.md\shell\PanConverterMenu] +@="PanConverter" +"MUIVerb"="Convert to..." +"Icon"="\"%LOCALAPPDATA%\\Programs\\PanConverter\\PanConverter.exe\"" +"SubCommands"="" + +[HKEY_CLASSES_ROOT\.md\shell\PanConverterMenu\shell\PDF] +@="PDF" + +[HKEY_CLASSES_ROOT\.md\shell\PanConverterMenu\shell\PDF\command] +@="\"%LOCALAPPDATA%\\Programs\\PanConverter\\PanConverter.exe\" --convert-to pdf \"%1\"" + +[HKEY_CLASSES_ROOT\.md\shell\PanConverterMenu\shell\HTML] +@="HTML" + +[HKEY_CLASSES_ROOT\.md\shell\PanConverterMenu\shell\HTML\command] +@="\"%LOCALAPPDATA%\\Programs\\PanConverter\\PanConverter.exe\" --convert-to html \"%1\"" + +[HKEY_CLASSES_ROOT\.md\shell\PanConverterMenu\shell\DOCX] +@="DOCX" + +[HKEY_CLASSES_ROOT\.md\shell\PanConverterMenu\shell\DOCX\command] +@="\"%LOCALAPPDATA%\\Programs\\PanConverter\\PanConverter.exe\" --convert-to docx \"%1\"" + +[HKEY_CLASSES_ROOT\.md\shell\PanConverterMenu\shell\LaTeX] +@="LaTeX" + +[HKEY_CLASSES_ROOT\.md\shell\PanConverterMenu\shell\LaTeX\command] +@="\"%LOCALAPPDATA%\\Programs\\PanConverter\\PanConverter.exe\" --convert-to latex \"%1\"" + +[HKEY_CLASSES_ROOT\.md\shell\PanConverterMenu\shell\PPTX] +@="PowerPoint" + +[HKEY_CLASSES_ROOT\.md\shell\PanConverterMenu\shell\PPTX\command] +@="\"%LOCALAPPDATA%\\Programs\\PanConverter\\PanConverter.exe\" --convert-to pptx \"%1\"" \ No newline at end of file diff --git a/scripts/nsis-installer.nsh b/scripts/nsis-installer.nsh new file mode 100644 index 0000000..d5bb91d --- /dev/null +++ b/scripts/nsis-installer.nsh @@ -0,0 +1,144 @@ +; PanConverter NSIS Installer Include File +; Handles context menu installation and uninstallation + +!include "LogicLib.nsh" + +; Custom installation page for context menu option +Var ContextMenuCheckbox +Var ContextMenuState + +Function ContextMenuPage + !insertmacro MUI_HEADER_TEXT "Additional Options" "Choose additional installation options" + + nsDialogs::Create 1018 + Pop $0 + + ${If} $0 == error + Abort + ${EndIf} + + ${NSD_CreateLabel} 0 0 100% 20u "Select additional features to install:" + Pop $0 + + ${NSD_CreateCheckbox} 20u 30u 280u 15u "Add PanConverter to Windows Explorer context menu" + Pop $ContextMenuCheckbox + ${NSD_SetState} $ContextMenuCheckbox ${BST_CHECKED} + + ${NSD_CreateLabel} 20u 50u 280u 30u "This will allow you to right-click on supported files and convert them directly using PanConverter." + Pop $0 + + nsDialogs::Show +FunctionEnd + +Function ContextMenuPageLeave + ${NSD_GetState} $ContextMenuCheckbox $ContextMenuState +FunctionEnd + +; Install context menu entries +Function InstallContextMenu + ${If} $ContextMenuState == ${BST_CHECKED} + DetailPrint "Installing context menu integration..." + + ; Create registry entries for context menu + WriteRegStr HKCR ".md\shell\PanConverter" "" "Convert with PanConverter" + WriteRegStr HKCR ".md\shell\PanConverter" "Icon" "$INSTDIR\PanConverter.exe" + WriteRegStr HKCR ".md\shell\PanConverter\command" "" '"$INSTDIR\PanConverter.exe" --convert "%1"' + + WriteRegStr HKCR ".markdown\shell\PanConverter" "" "Convert with PanConverter" + WriteRegStr HKCR ".markdown\shell\PanConverter" "Icon" "$INSTDIR\PanConverter.exe" + WriteRegStr HKCR ".markdown\shell\PanConverter\command" "" '"$INSTDIR\PanConverter.exe" --convert "%1"' + + ; Context menu for HTML files + WriteRegStr HKCR ".html\shell\PanConverter" "" "Convert with PanConverter" + WriteRegStr HKCR ".html\shell\PanConverter" "Icon" "$INSTDIR\PanConverter.exe" + WriteRegStr HKCR ".html\shell\PanConverter\command" "" '"$INSTDIR\PanConverter.exe" --convert "%1"' + + WriteRegStr HKCR ".htm\shell\PanConverter" "" "Convert with PanConverter" + WriteRegStr HKCR ".htm\shell\PanConverter" "Icon" "$INSTDIR\PanConverter.exe" + WriteRegStr HKCR ".htm\shell\PanConverter\command" "" '"$INSTDIR\PanConverter.exe" --convert "%1"' + + ; Context menu for DOCX files + WriteRegStr HKCR ".docx\shell\PanConverter" "" "Convert with PanConverter" + WriteRegStr HKCR ".docx\shell\PanConverter" "Icon" "$INSTDIR\PanConverter.exe" + WriteRegStr HKCR ".docx\shell\PanConverter\command" "" '"$INSTDIR\PanConverter.exe" --convert "%1"' + + ; Context menu for ODT files + WriteRegStr HKCR ".odt\shell\PanConverter" "" "Convert with PanConverter" + WriteRegStr HKCR ".odt\shell\PanConverter" "Icon" "$INSTDIR\PanConverter.exe" + WriteRegStr HKCR ".odt\shell\PanConverter\command" "" '"$INSTDIR\PanConverter.exe" --convert "%1"' + + ; Context menu for RTF files + WriteRegStr HKCR ".rtf\shell\PanConverter" "" "Convert with PanConverter" + WriteRegStr HKCR ".rtf\shell\PanConverter" "Icon" "$INSTDIR\PanConverter.exe" + WriteRegStr HKCR ".rtf\shell\PanConverter\command" "" '"$INSTDIR\PanConverter.exe" --convert "%1"' + + ; Context menu for LaTeX files + WriteRegStr HKCR ".tex\shell\PanConverter" "" "Convert with PanConverter" + WriteRegStr HKCR ".tex\shell\PanConverter" "Icon" "$INSTDIR\PanConverter.exe" + WriteRegStr HKCR ".tex\shell\PanConverter\command" "" '"$INSTDIR\PanConverter.exe" --convert "%1"' + + ; Context menu for PDF files + WriteRegStr HKCR ".pdf\shell\PanConverter" "" "Convert with PanConverter" + WriteRegStr HKCR ".pdf\shell\PanConverter" "Icon" "$INSTDIR\PanConverter.exe" + WriteRegStr HKCR ".pdf\shell\PanConverter\command" "" '"$INSTDIR\PanConverter.exe" --convert "%1"' + + ; Context menu for PowerPoint files + WriteRegStr HKCR ".pptx\shell\PanConverter" "" "Convert with PanConverter" + WriteRegStr HKCR ".pptx\shell\PanConverter" "Icon" "$INSTDIR\PanConverter.exe" + WriteRegStr HKCR ".pptx\shell\PanConverter\command" "" '"$INSTDIR\PanConverter.exe" --convert "%1"' + + WriteRegStr HKCR ".ppt\shell\PanConverter" "" "Convert with PanConverter" + WriteRegStr HKCR ".ppt\shell\PanConverter" "Icon" "$INSTDIR\PanConverter.exe" + WriteRegStr HKCR ".ppt\shell\PanConverter\command" "" '"$INSTDIR\PanConverter.exe" --convert "%1"' + + ; Context menu for ODP files + WriteRegStr HKCR ".odp\shell\PanConverter" "" "Convert with PanConverter" + WriteRegStr HKCR ".odp\shell\PanConverter" "Icon" "$INSTDIR\PanConverter.exe" + WriteRegStr HKCR ".odp\shell\PanConverter\command" "" '"$INSTDIR\PanConverter.exe" --convert "%1"' + + ; Submenu for Markdown files with direct conversion options + WriteRegStr HKCR ".md\shell\PanConverterMenu" "" "PanConverter" + WriteRegStr HKCR ".md\shell\PanConverterMenu" "MUIVerb" "Convert to..." + WriteRegStr HKCR ".md\shell\PanConverterMenu" "Icon" "$INSTDIR\PanConverter.exe" + WriteRegStr HKCR ".md\shell\PanConverterMenu" "SubCommands" "" + + WriteRegStr HKCR ".md\shell\PanConverterMenu\shell\PDF" "" "PDF" + WriteRegStr HKCR ".md\shell\PanConverterMenu\shell\PDF\command" "" '"$INSTDIR\PanConverter.exe" --convert-to pdf "%1"' + + WriteRegStr HKCR ".md\shell\PanConverterMenu\shell\HTML" "" "HTML" + WriteRegStr HKCR ".md\shell\PanConverterMenu\shell\HTML\command" "" '"$INSTDIR\PanConverter.exe" --convert-to html "%1"' + + WriteRegStr HKCR ".md\shell\PanConverterMenu\shell\DOCX" "" "DOCX" + WriteRegStr HKCR ".md\shell\PanConverterMenu\shell\DOCX\command" "" '"$INSTDIR\PanConverter.exe" --convert-to docx "%1"' + + WriteRegStr HKCR ".md\shell\PanConverterMenu\shell\LaTeX" "" "LaTeX" + WriteRegStr HKCR ".md\shell\PanConverterMenu\shell\LaTeX\command" "" '"$INSTDIR\PanConverter.exe" --convert-to latex "%1"' + + WriteRegStr HKCR ".md\shell\PanConverterMenu\shell\PPTX" "" "PowerPoint" + WriteRegStr HKCR ".md\shell\PanConverterMenu\shell\PPTX\command" "" '"$INSTDIR\PanConverter.exe" --convert-to pptx "%1"' + + DetailPrint "Context menu integration installed successfully!" + ${EndIf} +FunctionEnd + +; Uninstall context menu entries +Function un.RemoveContextMenu + DetailPrint "Removing context menu integration..." + + ; Remove context menu entries for all file types + DeleteRegKey HKCR ".md\shell\PanConverter" + DeleteRegKey HKCR ".md\shell\PanConverterMenu" + DeleteRegKey HKCR ".markdown\shell\PanConverter" + DeleteRegKey HKCR ".html\shell\PanConverter" + DeleteRegKey HKCR ".htm\shell\PanConverter" + DeleteRegKey HKCR ".docx\shell\PanConverter" + DeleteRegKey HKCR ".odt\shell\PanConverter" + DeleteRegKey HKCR ".rtf\shell\PanConverter" + DeleteRegKey HKCR ".tex\shell\PanConverter" + DeleteRegKey HKCR ".pdf\shell\PanConverter" + DeleteRegKey HKCR ".pptx\shell\PanConverter" + DeleteRegKey HKCR ".ppt\shell\PanConverter" + DeleteRegKey HKCR ".odp\shell\PanConverter" + + DetailPrint "Context menu integration removed successfully!" +FunctionEnd \ No newline at end of file diff --git a/scripts/uninstall-context-menu.bat b/scripts/uninstall-context-menu.bat new file mode 100644 index 0000000..8db8e09 --- /dev/null +++ b/scripts/uninstall-context-menu.bat @@ -0,0 +1,32 @@ +@echo off +echo PanConverter Context Menu Uninstallation +echo ======================================== +echo. + +REM Check for administrator privileges +net session >nul 2>&1 +if %errorLevel% == 0 ( + echo Running with administrator privileges... +) else ( + echo This script requires administrator privileges. + echo Please right-click and select "Run as administrator" + echo. + pause + exit /b 1 +) + +echo Removing context menu entries... +reg import "%~dp0uninstall-context-menu.reg" + +if %errorLevel% == 0 ( + echo. + echo Context menu integration removed successfully! + echo PanConverter entries have been removed from the Windows Explorer context menu. +) else ( + echo. + echo Failed to remove context menu entries. + echo Please check that the registry file exists and try again. +) + +echo. +pause \ No newline at end of file diff --git a/scripts/uninstall-context-menu.reg b/scripts/uninstall-context-menu.reg new file mode 100644 index 0000000..05b0470 --- /dev/null +++ b/scripts/uninstall-context-menu.reg @@ -0,0 +1,36 @@ +Windows Registry Editor Version 5.00 + +; PanConverter Context Menu Uninstall Script +; This registry file removes PanConverter context menu entries + +; Remove context menu for Markdown files (.md, .markdown) +[-HKEY_CLASSES_ROOT\.md\shell\PanConverter] +[-HKEY_CLASSES_ROOT\.md\shell\PanConverterMenu] + +[-HKEY_CLASSES_ROOT\.markdown\shell\PanConverter] + +; Remove context menu for HTML files +[-HKEY_CLASSES_ROOT\.html\shell\PanConverter] +[-HKEY_CLASSES_ROOT\.htm\shell\PanConverter] + +; Remove context menu for DOCX files +[-HKEY_CLASSES_ROOT\.docx\shell\PanConverter] + +; Remove context menu for ODT files +[-HKEY_CLASSES_ROOT\.odt\shell\PanConverter] + +; Remove context menu for RTF files +[-HKEY_CLASSES_ROOT\.rtf\shell\PanConverter] + +; Remove context menu for LaTeX files +[-HKEY_CLASSES_ROOT\.tex\shell\PanConverter] + +; Remove context menu for PDF files +[-HKEY_CLASSES_ROOT\.pdf\shell\PanConverter] + +; Remove context menu for PowerPoint files +[-HKEY_CLASSES_ROOT\.pptx\shell\PanConverter] +[-HKEY_CLASSES_ROOT\.ppt\shell\PanConverter] + +; Remove context menu for OpenDocument Presentation files +[-HKEY_CLASSES_ROOT\.odp\shell\PanConverter] \ No newline at end of file diff --git a/src/main.js b/src/main.js index cc35f61..9ca9d85 100644 --- a/src/main.js +++ b/src/main.js @@ -581,7 +581,151 @@ function extractTablesFromMarkdown(markdown) { return tables; } +// Handle command line interface for file conversion +function handleCLIConversion(args) { + const command = args[0]; + const filePath = args[args.length - 1]; // File path is always last argument + + if (!fs.existsSync(filePath)) { + console.error(`Error: File not found: ${filePath}`); + app.quit(); + return; + } + + // Show conversion dialog for --convert command + if (command === '--convert') { + showConversionDialog(filePath); + return; + } + + // Direct conversion for --convert-to command + if (command === '--convert-to' && args.length >= 3) { + const format = args[1]; + performCLIConversion(filePath, format); + return; + } + + console.error('Usage: --convert OR --convert-to '); + app.quit(); +} + +// Show conversion dialog for CLI +function showConversionDialog(filePath) { + const { dialog } = require('electron'); + + // Create a hidden window for dialog operations + const hiddenWindow = new BrowserWindow({ + show: false, + webPreferences: { + nodeIntegration: true, + contextIsolation: false + } + }); + + const formats = [ + { name: 'PDF', value: 'pdf' }, + { name: 'HTML', value: 'html' }, + { name: 'DOCX', value: 'docx' }, + { name: 'LaTeX', value: 'latex' }, + { name: 'RTF', value: 'rtf' }, + { name: 'ODT', value: 'odt' }, + { name: 'PowerPoint', value: 'pptx' } + ]; + + // Create format selection dialog using message box + const formatButtons = formats.map(f => f.name); + formatButtons.push('Cancel'); + + dialog.showMessageBox(hiddenWindow, { + type: 'question', + title: 'PanConverter - Choose Format', + message: `Convert "${path.basename(filePath)}" to:`, + detail: 'Select the output format for conversion', + buttons: formatButtons, + defaultId: 0, + cancelId: formatButtons.length - 1 + }).then(result => { + if (result.response < formats.length) { + const selectedFormat = formats[result.response].value; + performCLIConversion(filePath, selectedFormat); + } else { + console.log('Conversion cancelled'); + app.quit(); + } + hiddenWindow.destroy(); + }); +} + +// Perform CLI conversion +function performCLIConversion(inputPath, format) { + try { + const content = fs.readFileSync(inputPath, 'utf-8'); + const outputPath = inputPath.replace(/\.[^/.]+$/, `.${format}`); + + console.log(`Converting "${path.basename(inputPath)}" to ${format.toUpperCase()}...`); + + // Use existing export functions but with CLI output + const pandocCommand = buildPandocCommand(content, format, outputPath); + + exec(pandocCommand, (error, stdout, stderr) => { + if (error) { + console.error(`Conversion failed: ${error.message}`); + if (stderr) console.error(`Details: ${stderr}`); + app.quit(); + return; + } + + console.log(`Successfully converted to: ${outputPath}`); + + // Show Windows notification + if (process.platform === 'win32') { + exec(`powershell -Command "New-BurntToastNotification -Text 'PanConverter', 'File converted to ${format.toUpperCase()}' -AppLogo '${path.join(__dirname, '../assets/icon.png')}'"`, () => {}); + } + + app.quit(); + }); + } catch (error) { + console.error(`Error reading file: ${error.message}`); + app.quit(); + } +} + +// Build Pandoc command for CLI conversion +function buildPandocCommand(content, format, outputPath) { + const inputFile = path.join(require('os').tmpdir(), `panconverter_temp_${Date.now()}.md`); + fs.writeFileSync(inputFile, content, 'utf-8'); + + let command = `pandoc "${inputFile}" -o "${outputPath}"`; + + switch (format) { + case 'pdf': + command += ' --pdf-engine=xelatex --variable geometry:margin=1in'; + break; + case 'html': + command += ' --self-contained --css'; + break; + case 'docx': + command += ' --reference-doc'; + break; + case 'latex': + command += ' --standalone'; + break; + case 'pptx': + command += ' --slide-level=2'; + break; + } + + return command; +} + app.whenReady().then(() => { + // Check for command line conversion requests + const args = process.argv.slice(2); + if (args.length >= 2 && (args[0] === '--convert' || args[0] === '--convert-to')) { + handleCLIConversion(args); + return; // Don't create window for CLI operations + } + createWindow(); // Handle file association on app startup