# Windows Installer Build Instructions

## Prerequisites

1. **WiX Toolset** - Download and install from https://wixtoolset.org/
   - WiX 3.x or WiX 4.x
   - Add WiX bin directory to PATH

2. **Built Binaries** - Build the Release configuration:
   ```powershell
   cmake -B build -DCMAKE_BUILD_TYPE=Release
   cmake --build build --config Release
   ```

3. **Dependencies** - Ensure all DLL dependencies are available:
   - Qt6 runtime DLLs
   - OpenSSL DLLs
   - FFmpeg DLLs
   - Boost DLLs (if dynamically linked)

## Building the Installer

### Step 1: Update installer.wxs

Replace all `PUT-GUID-HERE` placeholders with actual GUIDs. Generate GUIDs using PowerShell:

```powershell
[guid]::NewGuid()
```

Or use online GUID generators.

### Step 2: Update Paths

Edit `build_installer.ps1` and update the following paths to match your system:

```powershell
$BuildDir = "..\build\Release"          # Your build output directory
$Qt6Dir = "C:\Qt\6.x.x\msvc2022_64"     # Qt6 installation
$OpenSSLDir = "C:\OpenSSL-Win64"        # OpenSSL installation
$FFmpegDir = "C:\ffmpeg"                # FFmpeg installation
```

### Step 3: Run Build Script

```powershell
cd installer
.\build_installer.ps1
```

This will create `Scar Chat.msi` in the installer directory.

## Manual Build

If you prefer to build manually:

```powershell
cd installer

# Compile
candle.exe installer.wxs ^
    -dBuildDir=..\build\Release ^
    -dQt6Dir=C:\Qt\6.x.x\msvc2022_64 ^
    -dOpenSSLDir=C:\OpenSSL-Win64 ^
    -dFFmpegDir=C:\ffmpeg ^
    -dSourceDir=.. ^
    -ext WixUIExtension

# Link
light.exe installer.wixobj ^
    -ext WixUIExtension ^
    -out "Scar Chat.msi"
```

## Installer Features

The MSI installer includes:

- Main executable (`scarchat.exe`)
- All required Qt6 DLLs
- OpenSSL libraries
- FFmpeg libraries for video/screen capture
- Start Menu shortcut
- Standard install/uninstall functionality
- Per-machine installation

## Customization

### Add Application Icon

1. Create an `.ico` file for the application
2. Uncomment the Icon section in `installer.wxs`:
   ```xml
   <Icon Id="AppIcon" SourceFile="$(var.SourceDir)\app_icon.ico" />
   <Property Id="ARPPRODUCTICON" Value="AppIcon" />
   ```

### Additional Files

To include additional files, add new `<Component>` elements in the `ProductComponents` group:

```xml
<Component Id="MyFile" Guid="YOUR-GUID-HERE">
    <File Id="MyFileId" Source="$(var.SourceDir)\myfile.txt" />
</Component>
```

## Troubleshooting

### Missing DLLs

If the installed application fails to run due to missing DLLs:

1. Use Dependency Walker or similar tool to identify missing DLLs
2. Add them to the installer.wxs Components section
3. Rebuild the MSI

### Qt Plugins

If Qt plugins are needed (e.g., platforms, imageformats), add them:

```xml
<Directory Id="INSTALLFOLDER" Name="Scar Chat">
    <Directory Id="PlatformsFolder" Name="platforms" />
</Directory>

<Component Id="QtPlatformsPlugin" Directory="PlatformsFolder" Guid="YOUR-GUID">
    <File Source="$(var.Qt6Dir)\plugins\platforms\qwindows.dll" />
</Component>
```

## Version Updates

To create a new version:

1. Update the `Version` attribute in the `<Product>` element
2. Keep the same `UpgradeCode` to allow upgrades
3. Rebuild the MSI

The `MajorUpgrade` element will automatically handle uninstalling old versions.
