0

I have a list of mods in a launcher.bat server command line variable, separated by semicolon:

set Antistasi2=-mod=%ModPath%@CBA_A3;%ModPath%@Antistasi;%ModPath%@CAC_AE1.4;%ModPath%@AWR;%ModPath%@RealEngine;%ModPath%@ace;%ModPath%@EnhancedMovement;%ModPath%@EnhancedMovementRework;%ModPath%@MfHealAbort;%ModPath%@VET_Unflipping;%ModPath%@AdvancedRappelling;%ModPath%@AdvancedUrbanRappelling;%ModPath%@Blastcore`

And I have a simple mod checker (modchecker.bat which is called from within the launcher.bat, checks for existing folders with predefined mod name and types the missing mod folder names (mods):

if not exist %ModPath%"@CBA_A3" echo @CBA_A3 NOT FOUND

if not exist %ModPath%"@Antistasi" echo @Antistasi NOT FOUND
...
if not exist %ModPath%"@Blastcore" echo @Blastcore NOT FOUND

But there is more predefined mod folder names than the mods currently used in the command line.

What I would want to is not to use a predefined mod folder list, but instead use the command line to populate the mod checker and create if not exist %ModPath%"@modxxx" echo @modxxx NOT FOUND line in the mod checker for each mod used in the command line.

To put it another way I would need to get the mod folder names from the command line array (-Mod= inside an %Antistasi2% variable (those would be: @CBA_A3, @Antistasi, etc. all the way to @Blastcore) and integrate them automatically into the mod checker so that the mod list from the command line auto populates the missing mod search in mod checker, so it does not have to be predefined manually.

And I have no clue how to do it. Please help.

Thanks in advance.

1 Answers1

0
@ECHO OFF
SETLOCAL

SET "ModPath=q:\somewhere\or\other\"

SET "list= %* CBA_A3 Antistasi CAC_AE1.4 AWR RealEngine ace EnhancedMovement EnhancedMovementRework MfHealAbort VET_Unflipping AdvancedRappelling AdvancedUrbanRappelling Blastcore"
SET "missing="
FOR %%e IN (%list%) DO IF NOT EXIST %ModPath%@%%e ECHO %%e missing&SET "missing=y"
rem IF DEFINED missing pause&GOTO :eof
SET "list=%list:  = %"
CALL SET "Antistasi2=%%list: =;%ModPath%@%%"
SET "Antistasi2=-mod=%Antistasi2:~1%"
SET anti

GOTO :EOF

I'm assuming that the set {CBA_A3..Blastcore} will always be required and some extra modules may be specified, so

thisbatch extra something hello

would add extra, something and hello to those standard items.

I've also assumed that each module required is prefixed by @.

I've established a dummy modpath for testing. You would need to change this.

list prepends the arguments from the command line to the standard list. Note that the leading space is important.

I've remarked-out what happens should a module be missing. Just remove the rem to activate the pause and goto :eof (which should cook dinner and terminate the batch if activated)

Next. replace all double-spaces in list with single spaces.

Next, replace all spaces in list with ;%modpath%@ (note that the value of modpath will be substituted) and assign to Antistasi2

Then remove the first character of Antistasi2 and prefix it with -mod=

Note: Use set "var=value" for setting string values - this avoids problems caused by trailing spaces. Don't assign " or a terminal backslash or Space. Build pathnames from the elements - counterintuitively, it is likely to make the process easier. If the syntax set var="value" is used, then the quotes become part of the value assigned.

If you remove the \ as advised, you would need to insert it before the @ in the if not exist statement and the call set statement.

Magoo
  • 77,302
  • 8
  • 62
  • 84
  • Thank you for your response. In the mean time I decided to try ChatGPT skills and it managed to generate the script that does exactly what is needed. The original script is gone, and the new script uses variable names like `set "varname2=Antistasi2"` and is modular so multiple varnames can be added. Then it extracts the value of the specified variable from launcher.bat `for /f "tokens=1,* delims== " %%a in ('type "%_path%" ^| findstr /c:"set !varname!="') do set "varvalue=%%b"` Removes -mod prefix from the variable value with `set "varvalue=!varvalue:-mod =!"` – Batch N00b Apr 15 '23 at 09:26
  • Replaces %ModPath% with the actual path in the variable value `set "varvalue=!varvalue:%%ModPath%%=!"` And extracts the mod names from the variable value with `set "missing_mods=" for %%m in (!varvalue!) do ( if /i "%%~m" neq "!varname!" if /i "%%~m" neq "-mod" ( REM Check if the mod folder exists in %ModPath% if not exist "%ModPath%\%%~m" ( set "missing_mods=!missing_mods!%%~m " ) ) )` – Batch N00b Apr 15 '23 at 09:30
  • Finally it prints the list of missing mods vertically using a for loop `if defined missing_mods ( echo Missing mods for !varname! server: for %%m in (!missing_mods!) do echo %%m echo. ) else ( echo No missing mods for !varname! server. ) echo. )` – Batch N00b Apr 15 '23 at 09:30
  • Forgot to mention that it loops through all the variable names with: `for %%v in ("%varname1%" "%varname2%" "%varname3%" "%varname4%") do ( set "varname=%%~v"` – Batch N00b Apr 15 '23 at 09:34