11if ( $args -contains " disappear" ) {
22
3+ $arguments = $args [1 .. ($args.Length - 1 )]
34$ErrorActionPreference = ' Stop'
45
56$HttpFile = ' '
@@ -8,68 +9,69 @@ $HttpServer = 'https://raw.githubusercontent.com/plowsof/sof1maps/main/'
89
910# Delete existing http file if it exists
1011If (Test-Path $AFile ) {
11- Remove-Item $AFile
12- Write-Host ' Deleting existing http file.'
12+ Remove-Item $AFile
13+ Write-Host ' Deleting existing http file.'
1314}
1415
1516Write-Host ' Welcome to SoF1 HTTP Auto Map Downloader.'
1617Write-Host ' Keep this window open so that it can detect map change.'
1718Write-Host ' SoF should open automatically now.'
1819
19- # Launch SoF
20- $gameProcess = Start-Process - PassThru - FilePath ' SoF.exe' - ArgumentList " +set console 1 "
20+ # Launch SoF - PassThru required to kill later.
21+ $gameProcess = Start-Process - PassThru - FilePath ' SoF.exe' - ArgumentList $arguments
2122
2223While ($true ) {
23- If (Test-Path $AFile ) {
24- # Read the last line of the mapname file
25- $HttpFile = Get-Content $AFile | Select-Object - Last 1
26-
27- $HttpFile = $HttpFile.Split (' "' )[3 ]
28- Write-Host " Map name: $HttpFile "
29-
30- # Remove .bsp extension and add .zip extension
31- $HttpFile = $HttpFile -replace ' \.bsp$' , ' .zip'
24+ If (Test-Path $AFile ) {
25+ # Read the last line of the mapname file
26+ $HttpFile = Get-Content $AFile | Select-Object - Last 1
27+
28+ $HttpFile = $HttpFile.Split (' "' )[3 ]
29+ Write-Host " Map name: $HttpFile "
30+
31+ # Remove .bsp extension and add .zip extension
32+ $HttpFile = $HttpFile -replace ' \.bsp$' , ' .zip'
3233
33- # Download the file from the http server
34- $DestFile = Join-Path ' user\maps' $HttpFile
34+ # Download the file from the http server
35+ $DestFile = Join-Path ' user\maps' $HttpFile
3536
36- # Create the directory if it doesn't exist
37- $directory = Split-Path - Path $DestFile - Parent
38- if (! (Test-Path - Path $directory - PathType Container)) {
39- New-Item - Path $directory - ItemType Directory | Out-Null
40- }
41- # Download the file using Invoke-WebRequest
42- Write-Host " NEUTRAL: Trying to download "" $HttpServer$HttpFile "" to "" $DestFile "" ."
37+ # Create the directory if it doesn't exist
38+ $directory = Split-Path - Path $DestFile - Parent
39+ if (! (Test-Path - Path $directory - PathType Container)) {
40+ New-Item - Path $directory - ItemType Directory | Out-Null
41+ }
42+ # Download the file using Invoke-WebRequest
43+ Write-Host " NEUTRAL: Trying to download "" $HttpServer$HttpFile "" to "" $DestFile "" ."
4344
44- try {
45- $ProgressPreference = ' SilentlyContinue'
46- Invoke-WebRequest - Uri " $HttpServer$HttpFile " - OutFile $DestFile - ErrorAction Stop
47- Write-Host " SUCCESS: "" $HttpFile "" downloaded to "" $DestFile "" ."
45+ try {
46+ $ProgressPreference = ' SilentlyContinue'
47+ Invoke-WebRequest - Uri " $HttpServer$HttpFile " - OutFile $DestFile - ErrorAction Stop
48+ Write-Host " SUCCESS: "" $HttpFile "" downloaded to "" $DestFile "" ."
4849
49- # Read-Host -Prompt "Press Enter to continue..."
50+ # Read-Host -Prompt "Press Enter to continue..."
5051
51- # Extract the zip file
52- Expand-Archive - LiteralPath $DestFile - DestinationPath ' user' - Force
52+ # Extract the zip file
53+ Expand-Archive - LiteralPath $DestFile - DestinationPath ' user' - Force
5354
54- # Delete the zip file
55- Remove-Item $DestFile
56-
57- } catch {
58- # 404 error catch
59- Write-Host " ERROR: $ ( $_.Exception.Message ) "
60- }
61- # Delete the http file
62- Remove-Item $AFile
63- }
64- # Wait for 2 seconds and check again
65- Start-Sleep - Seconds 2
55+ # Delete the zip file
56+ Remove-Item $DestFile
57+
58+ } catch {
59+ # 404 error catch
60+ Write-Host " ERROR: $ ( $_.Exception.Message ) "
61+ }
62+ # Delete the http file
63+ Remove-Item $AFile
64+ }
65+ # Wait for 2 seconds and check again
66+ Start-Sleep - Seconds 2
6667
67- if ($gameProcess.HasExited ) {
68- exit
69- }
68+ if ($gameProcess.HasExited ) {
69+ exit
70+ }
7071
7172}
7273} else {
73- $arguments = " -WindowStyle Hidden" , " -File" , $PSCommandPath , " disappear"
74- Start-Process " powershell.exe" - ArgumentList $arguments
74+ # $arguments = "-ExecutionPolicy Bypass", "-File `"$PSCommandPath`"", "disappear", "$args"
75+ $arguments = " -WindowStyle Hidden" , " -ExecutionPolicy Bypass" , " -File `" $PSCommandPath `" " , " disappear" , " $args "
76+ Start-Process " powershell.exe" - ArgumentList $arguments
7577}
0 commit comments