Files
2025-10-28 19:17:52 +01:00

161 lines
5.9 KiB
PowerShell

# PC Server Installer for Windows 10/11
# This script installs all dependencies for the 3DS Webcam Bridge PC server
param(
[int]$Port = 9000,
[switch]$SkipFirewall,
[switch]$Force
)
$ErrorActionPreference = "Stop"
$ScriptDir = Split-Path -Parent $MyInvocation.MyCommand.Path
$ProjectRoot = Split-Path -Parent (Split-Path -Parent $ScriptDir)
$HelpersModule = Join-Path $ScriptDir "helpers.psm1"
# Import helpers
Import-Module $HelpersModule -Force
Write-Host "======================================" -ForegroundColor Cyan
Write-Host "3DS Webcam Bridge - PC Server Installer" -ForegroundColor Cyan
Write-Host "Windows 10/11" -ForegroundColor Cyan
Write-Host "======================================" -ForegroundColor Cyan
Write-Host ""
# Check for admin privileges (required for some operations)
$isAdmin = Test-IsAdmin
if (-not $isAdmin) {
Write-Warning "Not running as Administrator. Some features may require admin privileges."
Write-Warning "To enable firewall rules and ensure full functionality, run as Administrator."
Write-Host ""
$response = Read-Host "Continue anyway? (y/n)"
if ($response -ne 'y') {
exit 1
}
}
# Check for winget
Write-Host "Checking for winget..." -ForegroundColor Cyan
if (-not (Test-WingetInstalled)) {
Write-Host ""
Write-Host "ERROR: winget is not installed!" -ForegroundColor Red
Write-Host ""
Write-Host "winget is required to install dependencies automatically."
Write-Host "Please install 'App Installer' from the Microsoft Store, or"
Write-Host "download it from:"
Write-Host " https://github.com/microsoft/winget-cli/releases"
Write-Host ""
exit 1
}
Write-Host "winget found!" -ForegroundColor Green
Write-Host ""
# Install Python 3
Write-Host "Checking for Python 3..." -ForegroundColor Cyan
if (-not (Test-CommandInstalled python) -and -not (Test-CommandInstalled python3)) {
Write-Host "Python 3 not found. Installing..." -ForegroundColor Yellow
Install-WithWinget -PackageId "Python.Python.3.11" -Name "Python 3.11"
# Refresh PATH
$env:Path = [System.Environment]::GetEnvironmentVariable("Path","Machine") + ";" + [System.Environment]::GetEnvironmentVariable("Path","User")
Write-Host ""
Write-Host "NOTE: You may need to restart your terminal for Python to be available in PATH" -ForegroundColor Yellow
Write-Host ""
} else {
Write-Host "Python 3 is already installed!" -ForegroundColor Green
$pythonVersion = python --version 2>&1
Write-Host " $pythonVersion" -ForegroundColor Gray
}
Write-Host ""
# Install OBS Studio (for Virtual Camera)
Write-Host "Checking for OBS Studio..." -ForegroundColor Cyan
$obsInstalled = Test-Path "C:\Program Files\obs-studio\bin\64bit\obs64.exe"
if (-not $obsInstalled -or $Force) {
Write-Host "OBS Studio not found. Installing..." -ForegroundColor Yellow
Write-Host ""
Write-Host "OBS Studio provides the Virtual Camera that pyvirtualcam uses on Windows." -ForegroundColor Yellow
Write-Host ""
Install-WithWinget -PackageId "OBSProject.OBSStudio" -Name "OBS Studio"
Write-Host ""
} else {
Write-Host "OBS Studio is already installed!" -ForegroundColor Green
}
Write-Host ""
# Create virtual environment
$VenvDir = Join-Path $ProjectRoot ".venv"
Write-Host "Setting up Python virtual environment..." -ForegroundColor Cyan
if (Test-Path $VenvDir) {
if ($Force) {
Write-Host "Removing existing virtual environment..." -ForegroundColor Yellow
Remove-Item -Recurse -Force $VenvDir
} else {
Write-Host "Virtual environment already exists. Updating..." -ForegroundColor Yellow
}
}
if (-not (Test-Path $VenvDir)) {
Write-Host "Creating virtual environment..." -ForegroundColor Cyan
python -m venv $VenvDir
}
# Activate virtual environment and install packages
$ActivateScript = Join-Path $VenvDir "Scripts\Activate.ps1"
Write-Host "Installing Python packages..." -ForegroundColor Cyan
& $ActivateScript
$RequirementsFile = Join-Path $ProjectRoot "pc-server\requirements.txt"
python -m pip install --upgrade pip
python -m pip install -r $RequirementsFile
Write-Host "Python packages installed successfully!" -ForegroundColor Green
Write-Host ""
# Add firewall rule
if (-not $SkipFirewall -and $isAdmin) {
Add-FirewallRule -Port $Port
Write-Host ""
}
Write-Host "======================================" -ForegroundColor Green
Write-Host "Installation Complete!" -ForegroundColor Green
Write-Host "======================================" -ForegroundColor Green
Write-Host ""
Write-Host "Next Steps:" -ForegroundColor Cyan
Write-Host ""
Write-Host "1. Start OBS Studio at least once to initialize the Virtual Camera:" -ForegroundColor White
Write-Host " - Open OBS Studio" -ForegroundColor Gray
Write-Host " - Go to Tools -> VirtualCam -> Start" -ForegroundColor Gray
Write-Host " - You can close OBS after this" -ForegroundColor Gray
Write-Host ""
Write-Host "2. Run the server:" -ForegroundColor White
Write-Host " .\pc-server\run_server.ps1 -Port $Port" -ForegroundColor Gray
Write-Host ""
Write-Host "3. For stereo side-by-side mode:" -ForegroundColor White
Write-Host " .\pc-server\run_server.ps1 -StereoMode sbs -Width 400 -Height 240" -ForegroundColor Gray
Write-Host ""
Write-Host "4. To specify a device:" -ForegroundColor White
Write-Host " .\pc-server\run_server.ps1 -Device `"OBS Virtual Camera`"" -ForegroundColor Gray
Write-Host ""
Write-Host "5. For dual devices (if you have multiple virtual cameras set up):" -ForegroundColor White
Write-Host " .\pc-server\run_server.ps1 -StereoMode dual -DualDevices `"OBS Virtual Camera,OBS Virtual Camera 2`"" -ForegroundColor Gray
Write-Host ""
if (-not $SkipFirewall -and -not $isAdmin) {
Write-Warning "Firewall rule was not added (requires admin privileges)."
Write-Warning "If you have connection issues, manually allow TCP port $Port in Windows Defender Firewall."
}
Write-Host ""
Write-Host "For more information, see README.md" -ForegroundColor Cyan
Write-Host ""