# Fix: startup.json Still Has Wrong WebDir

## Problem
After fixing the code, `startup.json` is still created with:
```json
"WebDir": "C:/ProgramData/jellyfin/wwwroot"
```

Instead of:
```json
"WebDir": "wwwroot"
```

## Root Cause
The fix in `StartupHelpers.cs` (line 141) only affects **newly created** files. If `startup.json` already exists in one of these locations, it won't be recreated:
1. Current directory: `D:\Projects\pgsql-jellyfin\startup.json`
2. Application directory: `bin\Debug\net11.0\startup.json`
3. Config directory: `bin\Debug\net11.0\config\startup.json`

## Solutions

### **Solution 1: Delete Existing startup.json** (Quickest)

Delete the existing `startup.json` file and let Jellyfin recreate it with correct values:

```powershell
# Find and delete startup.json files
Remove-Item -Path ".\startup.json" -ErrorAction SilentlyContinue
Remove-Item -Path ".\bin\Debug\net11.0\startup.json" -ErrorAction SilentlyContinue
Remove-Item -Path ".\bin\Debug\net11.0\config\startup.json" -ErrorAction SilentlyContinue
Remove-Item -Path ".\bin\Release\net11.0\startup.json" -ErrorAction SilentlyContinue
Remove-Item -Path ".\bin\Release\net11.0\config\startup.json" -ErrorAction SilentlyContinue

Write-Host "Deleted existing startup.json files. Run Jellyfin to recreate with correct paths."
```

### **Solution 2: Edit Existing startup.json Manually**

1. Find the file: `startup.json`
2. Open in a text editor
3. Change:
   ```json
   "WebDir": "C:/ProgramData/jellyfin/wwwroot"
   ```
   To:
   ```json
   "WebDir": "wwwroot"
   ```
4. Save

### **Solution 3: PowerShell Script to Fix All Instances**

```powershell
# Fix WebDir in all startup.json files

$files = Get-ChildItem -Path . -Recurse -Filter "startup.json" -ErrorAction SilentlyContinue

foreach ($file in $files) {
    Write-Host "Checking: $($file.FullName)"
    
    $content = Get-Content $file.FullName -Raw
    
    # Check if it has the wrong path
    if ($content -match '"WebDir":\s*"C:/ProgramData/jellyfin/wwwroot"') {
        Write-Host "  -> Found incorrect WebDir, fixing..." -ForegroundColor Yellow
        
        # Backup
        Copy-Item $file.FullName "$($file.FullName).backup"
        
        # Fix it
        $newContent = $content -replace '"WebDir":\s*"C:/ProgramData/jellyfin/wwwroot"', '"WebDir": "wwwroot"'
        Set-Content -Path $file.FullName -Value $newContent
        
        Write-Host "  -> Fixed! (Backup created)" -ForegroundColor Green
    } else {
        Write-Host "  -> Already correct" -ForegroundColor Green
    }
}

Write-Host ""
Write-Host "Done! Rebuild and run Jellyfin." -ForegroundColor Cyan
```

### **Solution 4: Add Code to Auto-Fix on Startup** (Most Robust)

Add code to automatically update incorrect paths when loading the config file. This ensures old config files are fixed automatically.

I can implement this in `StartupHelpers.cs` if you want.

## Verification

After applying a fix, check your `startup.json`:

```powershell
Get-Content startup.json | Select-String "WebDir"
```

Should show:
```json
"WebDir": "wwwroot"
```

Not:
```json
"WebDir": "C:/ProgramData/jellyfin/wwwroot"
```

## Why This Matters

Using relative path `"wwwroot"` instead of absolute path:
- ✅ Makes installation portable
- ✅ Works regardless of where Jellyfin is installed
- ✅ Matches the template file `startup.json.windows`
- ✅ Consistent with other platforms

## Next Steps

1. **Choose a solution above** (I recommend Solution 1 - delete and recreate)
2. **Rebuild** the project
3. **Run** Jellyfin
4. **Verify** the new `startup.json` has `"WebDir": "wwwroot"`

Would you like me to implement Solution 4 (auto-fix code) to prevent this issue in the future?
