fix: Windows one-liner script (irm | iex) now works

- Handle null $MyInvocation.MyCommand.Path when running via irm | iex
- Download GFK scripts from GitHub when local files not available
- Fixes #26
This commit is contained in:
SamNet-dev
2026-02-05 08:24:36 -06:00
parent 2c69164faa
commit 4382dbfd45

View File

@@ -59,9 +59,10 @@ $NpcapVersion = "1.80"
$NpcapUrl = "https://npcap.com/dist/npcap-$NpcapVersion.exe" $NpcapUrl = "https://npcap.com/dist/npcap-$NpcapVersion.exe"
$NpcapInstaller = "$env:TEMP\npcap-$NpcapVersion.exe" $NpcapInstaller = "$env:TEMP\npcap-$NpcapVersion.exe"
# GFK scripts - bundled locally for faster setup # GFK scripts - bundled locally for faster setup (only works when running from downloaded repo)
$ScriptDir = Split-Path -Parent $MyInvocation.MyCommand.Path # When running via "irm | iex", $MyInvocation.MyCommand.Path is null
$GfkLocalDir = "$ScriptDir\..\gfk\client" $ScriptDir = if ($MyInvocation.MyCommand.Path) { Split-Path -Parent $MyInvocation.MyCommand.Path } else { $null }
$GfkLocalDir = if ($ScriptDir) { "$ScriptDir\..\gfk\client" } else { $null }
$GfkFiles = @("mainclient.py", "quic_client.py", "vio_client.py") # parameters.py is generated $GfkFiles = @("mainclient.py", "quic_client.py", "vio_client.py") # parameters.py is generated
# Colors # Colors
@@ -462,17 +463,27 @@ function Install-Gfk {
New-Item -ItemType Directory -Path $GfkDir -Force | Out-Null New-Item -ItemType Directory -Path $GfkDir -Force | Out-Null
} }
# Copy bundled GFK scripts (faster than downloading) # Copy bundled GFK scripts or download from GitHub
Write-Info "Copying GFW-knocker scripts..." Write-Info "Setting up GFW-knocker scripts..."
$GfkGitHubBase = "https://raw.githubusercontent.com/SamNet-dev/paqctl/main/gfk/client"
foreach ($file in $GfkFiles) { foreach ($file in $GfkFiles) {
$src = "$GfkLocalDir\$file"
$dest = "$GfkDir\$file" $dest = "$GfkDir\$file"
if (Test-Path $src) { $src = if ($GfkLocalDir) { "$GfkLocalDir\$file" } else { $null }
if ($src -and (Test-Path $src)) {
# Copy from local bundled files (faster)
Copy-Item -Path $src -Destination $dest -Force Copy-Item -Path $src -Destination $dest -Force
Write-Info " Copied $file" Write-Info " Copied $file"
} else { } else {
Write-Err "Missing bundled file: $src" # Download from GitHub (for one-liner installation)
return $false Write-Info " Downloading $file..."
try {
Invoke-WebRequest -Uri "$GfkGitHubBase/$file" -OutFile $dest -UseBasicParsing
Write-Info " Downloaded $file"
} catch {
Write-Err "Failed to download $file from GitHub"
return $false
}
} }
} }