Batch to add game.exe's path into INI file

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
Holland
Posts: 2
Joined: 04 Apr 2020 11:10

Batch to add game.exe's path into INI file

#1 Post by Holland » 04 Apr 2020 12:41

I'm creating a standalone installation pack for an existing map editor, for my fellow game map makers. The map editor is called Finalsun, and it has an INI file called FinalSun.ini, inside the .ini file, it should refer to the game.exe like this:

[TS]
Exe=PathToExeFile


But there is nothing at the 'exe=' key. And most people don't know how to fix it. So it needs the path of the Game.exe that resides up one level, So I want to create a batch file that adds the user's absolute path of the game.exe at the 'Exe=' key

finalsun.ini is inside Folder1/Map editor/finalsun.ini the game.exe is inside Folder1/Game.exe (up one level of finalsun.ini)

So to clarify, I need a command for my batch file that will edit FinalSun.ini to have:

[TS]
Exe=Usersdirectories/Folder1/game.exe


The batch file i'm using for the installation is also in the Folder1. I really hope someone can help! Thank you!!
Last edited by Holland on 04 Apr 2020 13:19, edited 1 time in total.

aGerman
Expert
Posts: 4678
Joined: 22 Jan 2010 18:01
Location: Germany

Re: Batch to add game.exe's path into INI file

#2 Post by aGerman » 04 Apr 2020 12:51

Looks weird. The string in brackets is usually a section specifier in the INI file format and thus, it's usually in a separate line. Just to be sure - is this really all in the same line?

Steffen

Holland
Posts: 2
Joined: 04 Apr 2020 11:10

Re: Batch to add game.exe's path into INI file

#3 Post by Holland » 04 Apr 2020 13:20

Ah thanks, no, sorry for the mistake, its
[TS]
Exe=

aGerman
Expert
Posts: 4678
Joined: 22 Jan 2010 18:01
Location: Germany

Re: Batch to add game.exe's path into INI file

#4 Post by aGerman » 05 Apr 2020 06:12

Try something like that:

Code: Select all

@echo off &setlocal

set "ini_path=C:\somewhere\finalsun.ini"

for %%i in ("%ini_path%\..\..") do set "exe_path=%%~fi\game.exe"
set "ts_line="
for /f "delims=:" %%i in ('findstr /bnc:"[TS]" "%ini_path%"') do set /a "ts_line=%%i"
if not defined ts_line exit /b
set "exe_line="
for /f "delims=:" %%i in ('findstr /bnic:"Exe=" "%ini_path%"') do if not defined exe_line if %%i gtr %ts_line% set /a "exe_line=%%i-1"
if not defined exe_line exit /b
for /f %%i in ('type "%ini_path%"^|find /c /v ""') do set /a "end=%%i-2"

setlocal EnableDelayedExpansion
<"!ini_path!" >"!ini_path!~" (
  for /l %%i in (1 1 %exe_line%) do (
    set "ln=" & set /p "ln="
    echo(!ln!
  )
  echo(Exe=!exe_path!
  set /p "ln="
  for /l %%i in (%exe_line% 1 %end%) do (
    set "ln=" & set /p "ln="
    echo(!ln!
  )
)

move /y "!ini_path!~" "!ini_path!"
Update the ini_path variable to the real path. Don't forget to backup the ini file beforehand because it's getting overwritten without any possibility to undo.

Steffen

Post Reply