# Functional workflow of "Peugeot Update" ## Screens (Angular) 1. **Welcome** (`welcome`), can be hidden (`hideWelcome`). 2. **Vehicles** (`vehicles`, `vehicle-editor`): list, add (VIN + name), delete, link to the PDF guide (`wave` → i18n key → localised PDF URL). 3. **Updates** (`available-updates`): firmware and/or map, check boxes. 4. **Download folder** (`path-selector`): refused when it is on a USB stick, or when the free space is below (remaining size × 1.1). 5. **Download** (`download-file`): progress bar, pause/resume/cancel, estimated time. 6. **USB stick** (`usb-selector`): only mounted USB drives larger than needed are listed; formatting must be confirmed. 7. **Copy** (`copy-progress`), then **Finish**, with installation instructions for the vehicle. ## State machine (download-manager) ``` SelectUpdates └─ names resolved sequentially: fw → license (if fw) → map → lastDownload = {state: download, vin, fw/cartoUpdateSelected, versions, names} ChooseFolder └─ checks: folder not on USB, free space > needed × 1.1 Download ├─ if fw: license (simple) → firmware (Range) └─ then map (Range) → lastDownload.state = usb PrepareUsb ├─ size = Σ(fw + license + map sizes) × 1.1; minimum stick = 2 GB × 2^n ≥ needed (base 10^9) ├─ confirmation → FAT32 formatting (label = the stick's current label, sanitised, default NEW) ├─ if fw: copy license → /license/ ├─ extract the fw tar → / (skipping any file named UpdateInfo.xml) ├─ extract the map tar → / ├─ delete the downloaded files; lastDownload reset └─ eject (Windows) Finish ``` On an invalid tar (`Invalid tar header` / `unsupported type`), the tar is deleted and the user goes back to the vehicle list (the file has to be downloaded again). ## Persistence (`%APPDATA%\Peugeot Update`) - `config.json`: `language`, `hideWelcome`, `downloadPath`, `lastDownload{state(0=none,…), vin, fwUpdateSelected, cartoUpdateSelected, fwLastVersion, cartoLastVersion, fwFileName, cartoFileName, licenseFileName}` - `vehicles.json`: `{ "": {name, type, wave, undeletedFiles?{fw,carto,license}} }` - `downloadPath.txt`, `log.log` (electron-log) At startup, when `lastDownload.state != none`, the application offers to resume the download or to delete the files. ## Quirks and defects observed (not to reproduce) - `wmic` is used to read the stick label, but it was removed from Windows 11. - `xcopy` fails when the target is a drive root; it falls back to `robocopy`. - A license name seen before and then deleted is reused: ENOENT until the application restarts. - The temporary `toUsbContent` folder is not always deleted (ENOTEMPTY). - Sorting updates by date has no effect (see API.md).