Dexll Posted May 7, 2023 Share Posted May 7, 2023 (edited) 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? Edited May 7, 2023 by Dexll Quote Link to comment Share on other sites More sharing options...
JoeViking245 Posted May 7, 2023 Share Posted May 7, 2023 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). Quote Link to comment Share on other sites More sharing options...
Dexll Posted May 7, 2023 Author Share Posted May 7, 2023 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. 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? Quote Link to comment Share on other sites More sharing options...
JoeViking245 Posted May 7, 2023 Share Posted May 7, 2023 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. 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% Quote Link to comment Share on other sites More sharing options...
Dexll Posted May 8, 2023 Author Share Posted May 8, 2023 Thanks I will play around with it. Not sure on the less-than sign thing. I'll give it a go without it. Most of whats there is just scavanged from around the web. Quote Link to comment Share on other sites More sharing options...
JoeViking245 Posted May 8, 2023 Share Posted May 8, 2023 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. 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? Quote Link to comment Share on other sites More sharing options...
Dexll Posted May 9, 2023 Author Share Posted May 9, 2023 Dang. I was beginning to think your 'batch file as an emulator' idea was going to work. New road block is, LaunchBox seems to do a file check before launching the emulator. Quote Link to comment Share on other sites More sharing options...
JoeViking245 Posted May 9, 2023 Share Posted May 9, 2023 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. Quote Link to comment Share on other sites More sharing options...
Dexll Posted May 9, 2023 Author Share Posted May 9, 2023 (edited) 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 May 9, 2023 by Dexll Quote Link to comment Share on other sites More sharing options...
JoeViking245 Posted May 9, 2023 Share Posted May 9, 2023 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\ Then, launching the game with the [batch file] Emulator (like the one I posted earlier), 2 parameters get passed to the batch file. The 1st one is the %romlocation% parameter and the 2nd one is the full path to the ROM file (or .exe in your case). 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 Quote Link to comment Share on other sites More sharing options...
Dexll Posted May 21, 2023 Author Share Posted May 21, 2023 (edited) Sorry havn't had time to look at this till now. Still isn't working. Now trying with SNES today. Launching: Emulation: Emulator: Get-Game v2.bat (test) Result: If the ROM is there: Result if Extract ROM Archives before running is enabled. If the ROM is there: Result if Extract ROM Archives before running is disabled. Appreciate the help. Edited May 21, 2023 by Dexll Quote Link to comment Share on other sites More sharing options...
JoeViking245 Posted May 21, 2023 Share Posted May 21, 2023 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. Quote Link to comment Share on other sites More sharing options...
Dexll Posted May 22, 2023 Author Share Posted May 22, 2023 (edited) 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 May 22, 2023 by Dexll Quote Link to comment Share on other sites More sharing options...
JoeViking245 Posted May 22, 2023 Share Posted May 22, 2023 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. Quote Link to comment Share on other sites More sharing options...
Dexll Posted May 23, 2023 Author Share Posted May 23, 2023 (edited) 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. Edited May 23, 2023 by Dexll Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.