# Manual ISO Creation — HOWTO

Create a bootable DICOM viewer ISO with patient images, using `genisoimage` (or `mkisofs` / `xorriso`).

## Prerequisites

| Tool | Check | Install (Arch) |
|------|-------|----------------|
| `genisoimage` | `which genisoimage` | `pacman -S cdrtools` + symlink, or `pacman -S libisoburn` (xorriso) |
| Raw viewer files | `raw/microdicom/` | Part of this project |
| DICOM files | From PACS or unzipped archive | e.g. `unzip pasien.zip` |

## Steps

### 1. Prepare working directory

```bash
mkdir -p /tmp/build_iso/xcdrom/DICOMDIR
```

Directory structure yang akan jadi root ISO:

```
/tmp/build_iso/xcdrom/       ← root ISO
├── AUTORUN.INF
├── INDEX.PHP
├── README.TXT
├── RUN.BAT
├── MICROD/                  ← DICOM viewer
└── DICOMDIR/                ← file DICOM pasien
```

### 2. Copy microdicom viewer

```bash
cp -r /path/to/raw/microdicom/* /tmp/build_iso/xcdrom/
```

Hasil:
```
/tmp/build_iso/xcdrom/AUTORUN.INF
/tmp/build_iso/xcdrom/INDEX.PHP
/tmp/build_iso/xcdrom/README.TXT
/tmp/build_iso/xcdrom/RUN.BAT
/tmp/build_iso/xcdrom/MICROD/
```

### 3. Copy DICOM files pasien

**Flat** (semua file langsung di DICOMDIR):

```bash
cp /path/to/dicom/files/* /tmp/build_iso/xcdrom/DICOMDIR/
```

**Dari unzip dengan subfolder** (misal hasil unzip `EF76D893/...`):

```bash
find EF76D893 -type f -exec cp {} /tmp/build_iso/xcdrom/DICOMDIR/ \;
```

**Verifikasi**:

```bash
find /tmp/build_iso/xcdrom -type f | sort
```

### 4. Build ISO

```bash
genisoimage \
  -iso-level 4 \
  -r \
  -allow-multidot \
  -allow-lowercase \
  -allow-leading-dots \
  -V DICOM \
  -o /tmp/output.iso \
  /tmp/build_iso/xcdrom
```

| Flag | Fungsi |
|------|--------|
| `-iso-level 4` | Mengizinkan direktori >8 level |
| `-r` | Rock Ridge (long filename, Unix permissions) |
| `-allow-multidot` | Mengizinkan multiple dots dalam filename |
| `-allow-lowercase` | Lowercase filename |
| `-allow-leading-dots` | File dimulai dengan titik (.) |
| `-V DICOM` | Volume label = `DICOM` |
| `-o output.iso` | File ISO tujuan |

### 5. Verify ISO

```bash
# Cek ukuran
ls -lh /tmp/output.iso

# Cek struktur isi
isoinfo -l -i /tmp/output.iso

# Cek format
file /tmp/output.iso
# Output: ISO 9660 CD-ROM filesystem data 'DICOM'

# Mount & inspect (optional)
mkdir -p /tmp/mnt_iso
sudo mount -o loop /tmp/output.iso /tmp/mnt_iso
find /tmp/mnt_iso -type f -ls
sudo umount /tmp/mnt_iso
rmdir /tmp/mnt_iso
```

## Shortcut (one-liner)

Gabung semua step dalam satu script:

```bash
#!/bin/bash
ISO_NAME="${1:-output}"
SRC_DIR="/tmp/build_iso/xcdrom"
ISO_FILE="/tmp/${ISO_NAME}.iso"

mkdir -p "$SRC_DIR/DICOMDIR"
cp -r /path/to/raw/microdicom/* "$SRC_DIR/"
cp /path/to/dicom/files/* "$SRC_DIR/DICOMDIR/"

genisoimage \
  -iso-level 4 -r \
  -allow-multidot -allow-lowercase -allow-leading-dots \
  -V DICOM \
  -o "$ISO_FILE" \
  "$SRC_DIR"

echo "ISO created: $ISO_FILE ($(du -h "$ISO_FILE" | cut -f1))"
```

## Alternative: xorriso

If you have `xorriso` instead of `genisoimage`:

```bash
xorriso -as mkisofs \
  -iso-level 4 \
  -r \
  -V DICOM \
  -o /tmp/output.iso \
  /tmp/build_iso/xcdrom
```

## Output Structure Reference

```
output.iso
└── xcdrom/                    ← root ISO
    ├── AUTORUN.INF            ← auto-play CD (Windows)
    ├── INDEX.PHP              ← halaman web viewer
    ├── README.TXT             ← petunjuk penggunaan
    ├── RUN.BAT                ← batch file untuk jalanin viewer
    ├── MICROD/                ← MicroDicom executable viewer
    │   ├── MDICOM.EXE         ← main executable
    │   ├── MDICOM.CHM         ← help file
    │   ├── MFC120U.DLL        ← Visual C++ runtime
    │   ├── MSVCP120.DLL       ← Visual C++ runtime
    │   ├── MSVCR120.DLL       ← Visual C++ runtime
    │   ├── INDEX.PHP
    │   └── SETTINGS/          ← konfigurasi viewer
    │       ├── APPLICAT.XML
    │       ├── ANIMATIO.XML
    │       ├── ANNOTATI.XML
    │       ├── EXPORTDI.XML
    │       ├── EXPORTIM.XML
    │       ├── EXPORTVI.XML
    │       ├── OVERLAY.XML
    │       ├── OVERLAY_.XML
    │       ├── PRINT.XML
    │       └── WINDOWLE.XML
    └── DICOMDIR/              ← file DICOM pasien
        ├── 26811B9D           ← contoh file DICOM
        └── 601182D5           ← contoh file DICOM
```
