Weird powershell error crash running from batch file

Viewed 36

This is my first stackoverflow question, I created a batch file called "Stormworks Workshop Downloader"

Here's the code :

@echo off
setlocal enableextensions enabledelayedexpansion
cd /d %~dp0
echo Stormworks Workshop Downloader log >latest.log
echo This log is for debug purpose only >>latest.log
echo. >>latest.log
echo --- SteamCMD Downloader section ---
title Steam Workshop Downloader
echo Checking and downloading SteamCMD...
if not exist "%~dp0\SteamCMD\steamcmd.exe" bitsadmin /transfer SteamCMD /download /priority normal "https://steamcdn-a.akamaihd.net/client/installer/steamcmd.zip" "%~dp0\SteamCMD.zip" >>latest.log 2>&1
if not exist "%~dp0\SteamCMD\steamcmd.exe" set firstRun=1
if not exist "%~dp0\SteamCMD\steamcmd.exe" powershell -command "& {Expand-Archive -Force '%cd%\SteamCMD.zip' '%cd%\SteamCMD\'}" >>latest.log 2>&1
echo Deleting previous downloaded files...
rmdir /s /q SteamCMD\steamapps\workshop\content\573090 2>nul
echo --- Main section --- >>latest.log 2>&1
cls
echo Welcome to 5UP3R_D1N's Stormworks workshop downloader v1.7.0.1 [Pre-release]
echo.
echo Changes in this version :
echo Added experimental microcontroller downloader!
echo.
echo asking information... >>latest.log 2>&1
echo Note : This downloader does not support mission downloading.
set /p id="Enter file id : "
echo File ID : %id% >>latest.log 2>&1
set /p name="Enter desired vehicle/mc name : "
echo Vehicle name : %name% >>latest.log 2>&1
echo Downloading using SteamCMD...
echo Starting SteamCMD... >>latest.log 2>&1
echo --- SteamCMD Log --- >>latest.log 2>&1
echo SteamCMD might update itself, May take up to 5 minutes.
SteamCMD\steamcmd "+login anonymous" "+workshop_download_item 573090 %id%" "+exit" >>latest.log 2>&1
echo Moving vehicle to stormworks files...
echo --- Moving file section --- >>latest.log 2>&1
where /r "%~dp0\SteamCMD\steamapps\workshop\content\573090" * >list.txt
echo List of detected files :>>latest.log 2>&1
type list.txt >>latest.log 2>&1
set /p xml=< list.txt
echo XML File : %xml%>>latest.log 2>&1
echo Detecting type...>>latest.log 2>&1
Powershell -noprofile -command "@('%xml%') | %{[System.Text.RegularExpressions.Regex]::Match($_, '^.*\\content\\573090\\.*\\(.+)\.xml').Groups[1].Value}">type.txt 2>>latest.log
set /p type=<type.txt
del /f /q type.txt>>latest.log 2>&1
echo Item is %type%>>latest.log
ren "%xml%" vehicle.xmltmp >>latest.log 2>&1
move /Y "%xml%tmp" "%appdata%\Stormworks\data\%type%s" >>latest.log 2>&1
ren "%appdata%\Stormworks\data\vehicles\vehicle.xmltmp" "%name%.xml" >>latest.log 2>&1
echo Moving thumbnail to stormworks file...
echo Filtering workshop preview file...>>latest.log
powershell -NoProfile -Command "Get-Content -Path .\list.txt | Select-Object -Skip 1" > preview.txt
echo Workshop preview file :>>latest.log 2>&1
type preview.txt>>latest.log 2>&1
set /p xml=< preview.txt
ren "%xml%" workshop_preview.pngtmp >>latest.log 2>&1
move /Y "%xml%tmp" "%appdata%\Stormworks\data\%type%s" >>latest.log 2>&1
ren "%appdata%\Stormworks\data\vehicles\workshop_preview.pngtmp" "%name%.png" >>latest.log 2>&1
echo Clearing temporary file...
del /f /q list.txt>>latest.log 2>&1
del /f /q preview.txt>>latest.log 2>&1
echo Done. Thx for using my downloader
set /p nul="Press any key to close..."

this line :

Powershell -noprofile -command "@('%xml%') | %{[System.Text.RegularExpressions.Regex]::Match($_, '^.\content\573090\.\(.+).xml').Groups[1].Value}">type.txt 2>>latest.log

It gave me this error :

At line:1 char:161
+ ...  | :Match($_, '^.*\\content\\573090\\.*\\(.+)\.xml').Groups[1].Value}
+                                                                         ~
Unexpected token '}' in expression or statement.
    + CategoryInfo          : ParserError: (:) [], ParentContainsErrorRecordException
    + FullyQualifiedErrorId : UnexpectedToken

This line is used to detect which type of item is that, steam will return vehicle.xml if it is a vehicle and microcontroller.xml if it is a microcontroller, in this case I want it to get the filename without extension and put it in %type% all the file is listed at list.txt which I coded it to do that

[Edit /]

Also, Here's the log :

Stormworks Workshop Downloader log 
This log is for debug purpose only 
 
--- Main section --- 
asking information... 
File ID : 2655687303 
Vehicle name : AirNav 
Starting SteamCMD... 
--- SteamCMD Log --- 
Steam Console Client (c) Valve Corporation - version 1660762488
-- type 'quit' to exit --
Loading Steam API...OK

Connecting anonymously to Steam Public...OK
Waiting for client config...OK
Waiting for user info...OK
Downloading item 2655687303 ...
Success. Downloaded item 2655687303 to "E:\Stormworks\SteamCMD\steamapps\workshop\content\573090\2655687303" (135925 bytes) Redirecting stderr to 'E:\Stormworks\SteamCMD\logs\stderr.txt'
[  0%] Checking for available updates...
[----] Verifying installation...
--- Moving file section --- 
List of detected files :
E:\Stormworks\SteamCMD\steamapps\workshop\content\573090\2655687303\microcontroller.xml
E:\Stormworks\SteamCMD\steamapps\workshop\content\573090\2655687303\workshop_preview.png
XML File : E:\Stormworks\SteamCMD\steamapps\workshop\content\573090\2655687303\microcontroller.xml
Detecting type...
At line:1 char:161
+ ...  | :Match($_, '^.*\\content\\573090\\.*\\(.+)\.xml').Groups[1].Value}
+                                                                         ~
Unexpected token '}' in expression or statement.
    + CategoryInfo          : ParserError: (:) [], ParentContainsErrorRecordException
    + FullyQualifiedErrorId : UnexpectedToken
 
Item is 
The system cannot find the file specified.
The system cannot find the file specified.
Filtering workshop preview file...
Workshop preview file :
E:\Stormworks\SteamCMD\steamapps\workshop\content\573090\2655687303\workshop_preview.png
        1 file(s) moved.
The system cannot find the file specified.
0 Answers
Related