Skip to content

Instantly share code, notes, and snippets.

@addidotlol
Last active December 15, 2024 20:00
Show Gist options
  • Select an option

  • Save addidotlol/2a53edc55963a2c1ff46b3eebf8cb625 to your computer and use it in GitHub Desktop.

Select an option

Save addidotlol/2a53edc55963a2c1ff46b3eebf8cb625 to your computer and use it in GitHub Desktop.
dev version of car thing driver installer, testing
<#
.SYNOPSIS
Car Thing Driver Installer for Windows
.DESCRIPTION
Installs drivers for the Spotify Car Thing to enable modding.
Includes automatic detection and removal of old drivers.
.AUTHOR
Addison LeClair (https://addi.lol)
.LINK
https://terbium.app
.VERSION
1.0.2
#>
Write-Host "Car Thing Driver Installer - Thing Labs" -ForegroundColor Blue
Write-Host "v1.0.2 - with <3 from Addison (addi.lol)" -ForegroundColor Blue
Write-Host ""
# Function to remove existing driver
function Remove-ExistingDriver {
Write-Host "Checking for existing drivers..." -ForegroundColor Yellow
# Ensure we're running with admin privileges
$isAdmin = ([Security.Principal.WindowsPrincipal] [Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator)
if (-not $isAdmin) {
Write-Host "Script must be run as Administrator to remove drivers." -ForegroundColor Red
return $false
}
try {
# Search for the device using VID and PID
$existingDevices = Get-PnpDevice | Where-Object {
$_.HardwareID -match "USB\\VID_1B8E&PID_C003" -or
$_.FriendlyName -eq "WorldCup Device"
}
if ($existingDevices) {
Write-Host "Found existing driver installation(s). Attempting removal..." -ForegroundColor Yellow
foreach ($device in $existingDevices) {
Write-Host "Processing device: $($device.FriendlyName) ($($device.InstanceId))" -ForegroundColor Yellow
try {
# Try to stop any processes that might be using the device
$devicePath = (Get-PnpDeviceProperty -InstanceId $device.InstanceId -KeyName DEVPKEY_Device_LocationPaths).Data
if ($devicePath) {
Get-Process | Where-Object { $_.Path -and (Get-Item $_.Path).Directory.FullName -like "*$devicePath*" } | Stop-Process -Force
}
# Add a small delay
Start-Sleep -Seconds 1
# Attempt to disable first
Write-Host "Disabling device..." -ForegroundColor Yellow
$device | Disable-PnpDevice -Confirm:$false -ErrorAction Stop
Start-Sleep -Seconds 2
# Then remove
Write-Host "Removing device..." -ForegroundColor Yellow
$device | Remove-PnpDevice -Confirm:$false -ErrorAction Stop
Start-Sleep -Seconds 2
Write-Host "Successfully removed device." -ForegroundColor Green
}
catch {
# If standard removal fails, try using DevCon
Write-Host "Standard removal failed. Attempting alternative removal method..." -ForegroundColor Yellow
try {
$devconPath = Join-Path $env:TEMP "devcon.exe"
# Download DevCon if needed
if (-not (Test-Path $devconPath)) {
$devconUrl = "https://thingify.tools/files/blob/tSwx1EnvoGYk2bm8t43RQ/wFth0DCb6hnQwnJHnip_c/zeLV9hPQEOJLXnTEu1LsV?name=devcon.exe"
Invoke-RestMethod -Uri $devconUrl -OutFile $devconPath
}
# Use DevCon to remove the device
$hardwareID = "USB\VID_1B8E&PID_C003"
Start-Process -FilePath $devconPath -ArgumentList "remove", $hardwareID -NoNewWindow -Wait
Start-Sleep -Seconds 2
}
catch {
Write-Host "Alternative removal method also failed: $_" -ForegroundColor Red
continue
}
}
}
# Scan for hardware changes to ensure Windows recognizes the removal
Write-Host "Scanning for hardware changes..." -ForegroundColor Yellow
try {
Start-Process -FilePath $devconPath -ArgumentList "rescan" -NoNewWindow -Wait
}
catch {
Write-Host "Failed to rescan hardware: $_" -ForegroundColor Yellow
}
}
else {
Write-Host "No existing driver installation found." -ForegroundColor Green
}
return $true
}
catch {
Write-Host "Error during driver removal process: $_" -ForegroundColor Red
return $false
}
}
$originalDirectory = [System.Environment]::GetFolderPath('UserProfile')
$url = "https://thingify.tools/files/blob/tSwx1EnvoGYk2bm8t43RQ/wFth0DCb6hnQwnJHnip_c/XwqnRRHluo5Y8wxx6dqIW?name=CTDrvInst.exe"
$tempDir = Join-Path $env:TEMP "terbium-drv"
$filePath = Join-Path $tempDir "CTDrvInst.exe"
try {
if (-not (Test-Path $tempDir)) {
New-Item -Path $tempDir -ItemType Directory | Out-Null
}
} catch {
Write-Host "Failed to create a temporary directory: $_" -ForegroundColor Red
exit 1
}
Set-Location $tempDir
# Check and remove existing driver before proceeding
if (-not (Remove-ExistingDriver)) {
Write-Host "Failed to prepare system for new driver installation." -ForegroundColor Red
exit 1
}
Write-Host "Downloading..." -ForegroundColor Yellow
try {
Invoke-RestMethod -Uri $url -OutFile $filePath
if (-not (Test-Path $filePath)) {
Write-Host "Failed to download the driver installer." -ForegroundColor Red
exit 1
}
} catch {
Write-Host "Failed to download the driver installer: $_" -ForegroundColor Red
exit 1
}
$Driver = if ($env:CTDriver) { $env:CTDriver } else { "winusb" }
$drvType = switch ($Driver.ToLower()) {
"winusb" { 0 }
"winusb-libusb" { 1 }
"libusbk" { 2 }
"usbser" { 3 }
default {
Write-Host "Invalid driver type. Using default: winusb" -ForegroundColor Red
0
}
}
if ($drvType -ne 0) {
Write-Host "Using driver type: $drvType ($Driver)" -ForegroundColor Yellow
}
$wdiArgs = "-v 0x1B8E -p 0xC003 -n `"WorldCup Device`" -t $drvType -s -b"
Write-Host "Installing the driver..." -ForegroundColor Yellow
try {
$process = Start-Process -FilePath $filePath -ArgumentList $wdiArgs -Verb RunAs -WindowStyle Hidden -Wait -PassThru
if ($process.ExitCode -ne 0) {
throw "Installation failed with exit code: $($process.ExitCode)"
}
} catch {
Write-Host "Failed to install the driver: $_" -ForegroundColor Red
exit 1
}
Set-Location $originalDirectory
Write-Host "Cleaning up..." -ForegroundColor Yellow
try {
Remove-Item -Path $tempDir -Recurse -Force -ErrorAction Stop | Out-Null
} catch {
Write-Host "Failed to clean up the temporary directory: $_" -ForegroundColor Red
exit 1
}
Write-Host "Successfully installed the driver." -ForegroundColor Green
Write-Host "You can now access the Car Thing on Windows!" -ForegroundColor Green
Write-Host "Join our Discord: https://tl.mt/d" -ForegroundColor Blue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment