Skip to content

Commit

Permalink
file path was being expanded , now use literalpath
Browse files Browse the repository at this point in the history
  • Loading branch information
d3nd3 committed Jun 1, 2023
1 parent 2e1d6e2 commit f359977
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 18 deletions.
32 changes: 15 additions & 17 deletions http_listener.ps1
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@

if ( $args -contains "disappear" ) {

$arguments = $args[1..($args.Length - 1)]
$ErrorActionPreference = 'Stop'
# $ErrorActionPreference = 'Continue'

$HttpFile = ''
$AFile = 'user\sofplus\data\http_tmp'
$HttpServer = 'https://raw.githubusercontent.com/plowsof/sof1maps/main/'

# Delete existing http file if it exists
If (Test-Path $AFile) {
Remove-Item $AFile
If (Test-Path "$AFile") {
Remove-Item "$AFile"
Write-Host 'Deleting existing http file.'
}

Expand All @@ -23,54 +25,50 @@ $gameProcess = Start-Process -PassThru -FilePath 'SoF.exe' -ArgumentList $argume
While ($true) {
If (Test-Path $AFile) {
# Read the last line of the mapname file
$HttpFile = Get-Content $AFile | Select-Object -Last 1
$HttpFile = Get-Content "$AFile" | Select-Object -Last 1

$HttpFile = $HttpFile.Split('"')[3]
Write-Host "Map name: $HttpFile"

# Remove .bsp extension and add .zip extension
$HttpFile = $HttpFile -replace '\.bsp$', '.zip'
$HttpFile = "$HttpFile" -replace '\.bsp$', '.zip'

# Download the file from the http server
$DestFile = Join-Path 'user\maps' $HttpFile

# Create the directory if it doesn't exist
$directory = Split-Path -Path $DestFile -Parent
if (!(Test-Path -Path $directory -PathType Container)) {
New-Item -Path $directory -ItemType Directory | Out-Null
$directory = Split-Path -LiteralPath "$DestFile"
if (!(Test-Path -LiteralPath "$directory" -PathType Container)) {
New-Item -Path "$directory" -ItemType Directory | Out-Null
}

# Download the file using Invoke-WebRequest
Write-Host "NEUTRAL: Trying to download ""$HttpServer$HttpFile"" to ""$DestFile""."

try {
$ProgressPreference = 'SilentlyContinue'
$encodedUri = [System.Uri]::EscapeUriString("$HttpServer$HttpFile")
$webClient = New-Object System.Net.WebClient
$webClient.DownloadFile($encodedUri, $DestFile)
$webClient.DownloadFile("$encodedUri", "$DestFile")
Write-Host "SUCCESS: ""$HttpFile"" downloaded to ""$DestFile""."

# Read-Host -Prompt "Press Enter to continue..."

# Extract the zip file
Expand-Archive -LiteralPath $DestFile -DestinationPath 'user' -Force
Expand-Archive -LiteralPath "$DestFile" -DestinationPath 'user' -Force

# Delete the zip file
Remove-Item $DestFile
Remove-Item -LiteralPath "$DestFile"

} catch {
# 404 error catch
Write-Host "ERROR: $($_.Exception.Message)"
}
# Delete the http file
Remove-Item $AFile
Remove-Item -LiteralPath "$AFile"
}
# Wait for 2 seconds and check again
Start-Sleep -Seconds 2

if ($gameProcess.HasExited) {
exit
}

}
} else {
# $arguments = "-ExecutionPolicy Bypass", "-File `"$PSCommandPath`"", "disappear"
Expand Down
2 changes: 1 addition & 1 deletion user/sofplus/addons/http2.func
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ function http2_init()

function http2_init_print()
{
echo "[HTTP] Version v1.9 Loaded"
echo "[HTTP] Version v2.0 Loaded"
}

//2 -> 4 -> 7 -> 8
Expand Down

0 comments on commit f359977

Please sign in to comment.