Jump to content
LaunchBox Community Forums

Additional Apps Variables


Dexll

Recommended Posts

I am trying to use the Additional Apps feature to execute a PowerShell script to download the game from my file server before running. The script must be executed from the game directory to work.

The problem I am having is passing the game directory location to the "Application Command-Line Parameters" section.  Is it possible?

 

 

Screenshot 2023-05-06 205435.png

Edited by Dexll
Link to comment
Share on other sites

8 hours ago, Dexll said:

The problem I am having is passing the game directory location to the "Application Command-Line Parameters" section.  Is it possible?

In short, no.  You can't pass variables to Additional Apps.

 

One possible solution is to create a new emulator in LaunchBox that points to a batch file.  Use this emulator as the default.

The Application Path for your emulator would point to this .bat file.

The Default Command-Line Parameters could/would be 

%romlocation%

This will send to the batch file parameter %1 = "C:\Path\To\Rom\" (aka %PathToGame%).   Parameter %2 will depend on the boxes you check (or don't check).  Remove quotes and also Remove file extension and folder path.  But you'll probably want to at least keep Remove Quotes un-checked.  %2 will be the ROM_file.  Either "full\path\to\ROM_file.ext" or "ROM_file" (without the path and file extension).

In the batch file, start the ps1 script using a /w for "wait for exit" and use %1 in its parameters.

set PathToGame=%1
set ROM=%2
start "" /w "C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe" -file "%PathToGame%/Get-Game.ps1"

On the next line, start the actual emulator with any of its parameters and %2 (actually %ROM%) for the ROM.  You should use /w here as well so the games Shutdown Screen will work correctly and also if you want to remove the downloaded game after it exits [on another line].

 

Or if, unlike me, you're PowerShell savvy, you can do all this in a single ps1 script rather than a batch file calling a ps1 script.  

 

If you do go this route, to make the scripts 'less visible' when executed... for the batch file, create a shortcut to it, right click the shortcut, select Properties, next to "Run", choose "Minimized" and click OK to save. Then point to the shortcut in LaunchBox.  For PowerShell, right before "-file", add in "-WindowStyle hidden" (without quotes).

Link to comment
Share on other sites

That is an interesting idea.  Definitly food for thought.  Like set the emulator = cmd.exe, parameters = /c, and path/to/game = the batch file.  If the batch file was in a folder with the game name, it could detect the game name and launch it appropriatly after.

A goal I have is to make one script that will work for every game.  Though I think in the end I will have to settle on two.  One for single file games (roms/isos) and one for folder based games (bin+cue/windows).

To get around the PowerShell problem I inititally posted about, I instead create a .bat to do the same thing.

if exist "%~dp0.\CopyComplete.txt" (
    goto eof
) 

FOR %%A IN ("%~dp0.") DO SET parent=%%~dpA

if exist "%parent%GamesSource.txt" (
    set /p GameSource=<"%parent%\GamesSource.txt"
) else (
    cls
    echo %parent%GamesSource.txt does not exist.
    echo This file must exist at the root of games directory.
    echo It must contain the path where the games are stored on your network.
    echo The path must end with a \.
    pause
    Goto eof
)

for /f "delims=" %%A in ('cd') do (
    set FolderName=%%~nxA
)

if exist "%GameSource%%FolderName%" (
    robocopy "%GameSource%%FolderName%" "%~dp0." /e
    echo Copy Completed. > "%~dp0.\CopyComplete.txt"
    echo Game Launching...

) else (
    cls
    echo The directory "%GameSource%%FolderName%" does not exist.
    echo If the path above is not correct, check %parent%GamesSource.txt.
    echo This file must exist at the root of games directory.
    echo It must contain the path where the games are stored on your network.
    echo The path must end with a \.
    pause
)

:eof

Problem I am having now, the "Wait for Exit" seems to have a timeout.

image.png.e09c6c44c69f1eb6e15eeb34781594f4.png

It does add a wait but doesn't wait till the applicaiton closes.  I timed it and seems to only wait 40 seconds before it tries launching the game.  So if the game takes longer to download, an error appears.  Not the end of the world, just an extra click and have to launch it again after it finishes downloading. 

Any way to make it actually wait for exit?

Link to comment
Share on other sites

1 hour ago, Dexll said:

Any way to make it actually wait for exit?

Yes.  Get your stuff to process in less that 40 seconds. ;)  Didn't realize there was a 40-second 'safety net' for Additional Apps.  But makes good sense.  Well, except for your unique circumstance.

I think this puts you back to creating a new emulator.  You wouldn't have to use cmd.exe.  Just point to the batch file.

image.png.78b7833461ceab1179879d367f42cd7f.png

But you would have to create one for each emulator you need to do this 'download' process for.

 

This might work for something like PCSX2.. and you can put this batch file anywhere.  It doesn't rely on where it is located.  Not tested but looks good in print. :) 

Note: parameter %1 and %2 both include quotes.  You'll see where I removed them at the beginning for %1 (path).  And on the last line, did not put quotes around the path to Rom because %2 (fullPathToRom) already includes them.

May need to modify eof to either start the game or just completely exit the script.

oh... where you set the GameSource, is that less-than symbol supposed to be there?    set /p GameSource=<"%parent%\GamesSource.txt"

@echo off
set path=%1
set fullPathToRom=%2

rem remove quotes
set path=%path:"=%

if exist "%path%\CopyComplete.txt" (
    goto eof
) 

FOR %%A IN ("%path%\..") DO SET "parent=%%~fA"

if exist "%parent%GamesSource.txt" (
    set /p GameSource=<"%parent%\GamesSource.txt"
) else (
    cls
    echo %parent%GamesSource.txt does not exist.
    echo This file must exist at the root of games directory.
    echo It must contain the path where the games are stored on your network.
    echo The path must end with a \.
    pause
    Goto eof
)

for /f "delims=" %%A in ('cd') do (
    set FolderName=%%~nxA
)

if exist "%GameSource%%FolderName%" (
    robocopy "%GameSource%%FolderName%" "%~dp0." /e
    echo Copy Completed. > "%~dp0.\CopyComplete.txt"
    echo Game Launching...

) else (
    cls
    echo The directory "%GameSource%%FolderName%" does not exist.
    echo If the path above is not correct, check %parent%GamesSource.txt.
    echo This file must exist at the root of games directory.
    echo It must contain the path where the games are stored on your network.
    echo The path must end with a \.
    pause
)

:eof
start "" /w "D:\LaunchBox\Emulators\pcsx2.exe" %fullPathToRom%

 

Link to comment
Share on other sites

10 minutes ago, Dexll said:

Not sure on the less-than sign thing.  I'll give it a go without it. 

Well, if it ain't broke, don't "fix" it. :D  It may very well be valid.  I've just never seen it in a set parameter.  Though I've never used /p in there either. So may be a part of that?  

Link to comment
Share on other sites

What ROM are you passing to the Emulator (batch file)?  The ROM shouldn't have changed any.  Thus it exists.  Just the Emulator you're passing the ROM to changed.  

I did forget to mention (remind you) to associate the new emulator to the platform.  You can set it as default, or leave that unchecked and right click the game and choose Launch With, then select the original emulator or the new one.

This [has and] will work.  If it's still causing issues, share screen shots of your new Emulators Details section and the Associated Platforms section.  Then also, the game you're trying to launch, its Launching section and Emulation section.

Link to comment
Share on other sites

The rom is not there.  The whole point of this exercize is for the batch file to fetch it before it launches.

In this instance the rom is an .exe because I am foucusing on Windows Games first, but either way the point is that its not there before you launch the game.  I do want to apply this technique to rom's and iso's next.

I did the emulator/platform association thing.  I will share screenshot when I get home tonight.

Edited by Dexll
Link to comment
Share on other sites

1 hour ago, Dexll said:

The whole point of this exercize is for the batch file to fetch it before it launches.

But the batch file needs some information 1st to make it dynamic (aka universal to many ROMs). 

The games ROM (.exe in your initial testing) doesn't need to physically be there.  But the game does need to point to where it's going to be.

i.e.  game.exe is going to be downloaded (copied) to d:\no\where\in\particular\

image.thumb.png.117c4dc2eded9d063f52f4aa57658412.png

Then, launching the game with the [batch file] Emulator (like the one I posted earlier), 2 parameters get passed to the batch file.

image.png.ba6b27e25630e735a24812da3e7c1674.png

The 1st one is the %romlocation% parameter and the 2nd one is the full path to the ROM file (or .exe in your case).

image.thumb.png.30aaea0b09f384ca830791286e6a5b35.png

 

Now, that batch file can look for GamesSource.txt in the romlocation's parent directory (extrapolated in the 1st FOR statement).  blah blah blah and so on.

You can adjust your games Launching File Location so that it looks for GamesSource.txt in the appropriate parent folder.  And if all your game's download info is coming from the .txt file, you'll still need a fake "game.exe" in the Launching path for the above batch file (as written) to work correctly.  You can always adjust the Location path and/or batch file contents accordingly.

 

 

My Dummy.bat file (emulator) that gave the above output when launching "game.exe" looks like

@echo off
set path=%1
set fullRom=%2

echo.
echo RomLoaction: %path%
echo.
echo FullPathToRom: %fullRom%
echo.
echo.
echo The End
pause

 

Link to comment
Share on other sites

  • 2 weeks later...

Sorry havn't had time to look at this till now.

Still isn't working.  Now trying with SNES today.

Launching:

image.png.5edb38dc5cb6c315e77139cc787c5b2a.png

Emulation:

image.png.ae13ac32dd0517b974bc1fdd6bc89cb9.png

Emulator:

image.png.bd7c28f5de04cb2ad7d4bb0e7be9de16.png

Get-Game v2.bat (test)

image.png.18720bd6aa1d4294609f1869b1b94edb.png

Result:

image.png.489f2b082e64aeb8c87c2a3d608ed257.png

If the ROM is there:  Result if Extract ROM Archives before running is enabled.

image.thumb.png.f2fe64a55e97a9e51f42f1e79f71081c.png

If the ROM is there:  Result if Extract ROM Archives before running is disabled.

image.thumb.png.bfc7013158441939f93b901a61ac45c3.png

Appreciate the help.

Edited by Dexll
Link to comment
Share on other sites

Here's what I found... It works in some Platforms and not others.  Why? I have no idea.

For me it works in Arcade and in NES.  But it didn't work in SNES or Wii.

So you may want to test in a different platform, until you find one that doesn't express concern that the ROM file doesn't exist.  Then in that platform, do your full-blown testing with the proper batch file to see if it'll even work as you'd expect.  Once that all for-sure works, you can jump back to resolving the ROM file doesn't exist issue.  

Link to comment
Share on other sites

Hmmm...  That’s intriguing.  I'll flesh it out on the working platforms as you suggested.  I have solace in that I can always fall back to the Additional Apps approach.

I wonder if I can somehow spoof a NES platform into acting as a SNES platform if only by name.  Either way, it’s interesting to learn the behavior is different under the hood, especially among simple platforms.

Edited by Dexll
Link to comment
Share on other sites

2 hours ago, Dexll said:

I wonder if I can somehow spoof a NES platform into acting as a SNES platform if only by name. 

I swear NES was working for me yesterday.  But it's not working today.

However, I did find an apparent 'fix'.  (at least it's working for me, today)  Edit your emulator and change the Emulator Name: to "Get-Game MAME". Or "MAME Get-Game".  Or "Get-MAME-Game".  Or some variant that has the word "MAME" in it.  "ThisIsNotTheMAMEemulator" will also work.

Link to comment
Share on other sites

Wow!  I was not expecting that to work.  Taking it a step further, I found after applying the 'mame' name once, you can revert the name back and changes stick.  

Some interesting stuff going on under the hood of LaunchBox.  

Dialogue and dinosaurs: A critical analysis of Jurassic Park

Edited by Dexll
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...