# CCS PDF Editor — Windows WebView2 shell

Thin **WinForms + WebView2** host around the same static `app/` frontend used by the browser pack.

| Feature | Behavior |
|---------|----------|
| **Open** | Loads `app/index.html` via virtual host `https://app.local/` (not `file://`) |
| **`.ccspdf`** | Register as **default** handler (double-click) |
| **`.pdf`** | Register under **Open with** only (does not steal Edge/Acrobat default) |
| **Single instance** | Second launch hands files to the running window (named pipe) |
| **Large files** | Copied to a temp folder mapped as `https://ccs-open.local/` and fetched by the page |

Linux/macOS are out of scope here; use the browser pack or PWA.

## Build

From repo root (requires .NET 8+ SDK, Windows):

```powershell
powershell -ExecutionPolicy Bypass -File scripts\build-windows.ps1
```

The packager embeds **`deploy_windows/CcsPdfEditor.Shell/app.ico`** into `CcsPdfEditor.exe` (`ApplicationIcon`).  
`build-windows.ps1` rebuilds that ICO from `CCSPDF-Edit_PRO192.png` (16–256px) before publish so Explorer / taskbar / file associations show the brand icon.

Options:

```powershell
# Larger EXE, no .NET runtime required on target PCs
powershell -File scripts\build-windows.ps1 -SelfContained

# App only, no docs
powershell -File scripts\build-windows.ps1 -SkipDocs
```

Output:

- Framework-dependent: `dist/CCS-PDF-Editor-Windows-<version>/` (+ `.zip`)
- Self-contained: `dist/CCS-PDF-Editor-Windows-<version>-SelfContained/` (+ `.zip`)

## Develop (without full pack)

```powershell
# Stage app next to a debug build, or run from repo with path discovery:
dotnet run --project deploy_windows\CcsPdfEditor.Shell
```

The shell looks for `app\index.html` beside the EXE, then falls back to the repo root for local debug.

## Install on a workstation

**IT procedure (short SOP):** [docs/WINDOWS-INSTALL-SOP.md](../docs/WINDOWS-INSTALL-SOP.md)

1. Unzip the Windows package.
2. Run **`CcsPdfEditor.exe`** once (confirms WebView2 works).
3. (Optional) **`tools\Create Desktop Shortcut.bat`** — Desktop icon (no admin).
4. (Recommended) **`tools\Register File Types.bat`** (HKCU, no admin).
5. Double-click a `.ccspdf`, or right-click a `.pdf` → Open with → CCS PDF Editor.

Package root stays calm; helpers live under **`tools\`**:

```
CCS-PDF-Editor-Windows-x.y.z\
  CcsPdfEditor.exe
  app\
  docs\
  START-HERE.txt
  tools\
    Create Desktop Shortcut.bat
    Register File Types.bat
    Unregister File Types.bat
    Extract Project Audit.bat   <- IT / IR (drag .ccspdf)
    scripts\                    <- PowerShell (called by the bats)
      create-desktop-shortcut.ps1
      register-file-types.ps1
      unregister-file-types.ps1
      extract-ccspdf-audit.ps1
```

| Helper | Purpose |
|--------|---------|
| **tools\Create Desktop Shortcut.bat** | `CCS PDF Editor.lnk` on Desktop + copy in package folder |
| **tools\Register File Types.bat** | `.ccspdf` default + `.pdf` Open with |
| **tools\Unregister File Types.bat** | Remove associations only (does not delete the app) |
| **tools\Extract Project Audit.bat** | Decode rolling audit + trailer from a `.ccspdf` (incident investigation) |

Shortcut and registration are independent — icon without associations is fine.

## Requirements

- Windows 10/11  
- [WebView2 Runtime](https://developer.microsoft.com/microsoft-edge/webview2/) (ships with Edge on most PCs)  
- Framework-dependent build: [.NET Desktop Runtime 8+](https://dotnet.microsoft.com/download)  
- Or use `-SelfContained` when packaging  

## How open-with reaches the UI

1. Shell receives `"%1"` path(s) on the command line.  
2. Bytes are copied into a private temp folder mapped as `ccs-open.local`.  
3. Shell posts `{ type: "open-files", files: [{ name, url }] }` to the page.  
4. `js/core/host-bridge.js` `fetch`es the URL, builds a `File`, calls `processPdfFiles` (same path as drag/drop / PWA).
