Jump to content
LaunchBox Community Forums

Auto Hotkey Scripts


Lordmonkus

Recommended Posts

Ok, I've been looking at this problem for a bit, I asked if anyone could help but no one responded which is all good. Best to try and figure out things yourself, so I have had an attempt and failed miserably. My xbox roms are zipped up, I'm trying to find the file default.xbe in the directory it extracts to and rename it to the name of the rom that LB sends to CXBX-R. Here is what I've got:

currGame := Microsoft Xboxxml.Read(Title, "currGame",,,1)
romName := "I:\LaunchBox\ThirdParty\7-Zip\Temp\%currGame%\default.xbe"

if FileExist(romName)
{
   FileMove, romName, currGame, 1    
}

 

It seems to run, doesn't error out but when I look at the directory it doesn't change the name from default.xbe and then says it can't be found in CXBX-R and exits the emulator.

Any help would be greatly appreciated and also a way to have a relative path to the extracted rom instead of the full path.

 

Edited by Monyet
Spelling
Link to comment
Share on other sites

Your best bet might be to create an AHK script that is the emulator.  Something similar to 

; %1% = "I:\LaunchBox\Games\XBox\my_game.zip"
MsgBox, %1%

SplitPath, %1%,,,,romName
; romName = my_game
MsgBox, %romName%

RunWait, "I:\LaunchBox\ThirdParty\7-Zip\7z.exe" x -y -o"I:\LaunchBox\ThirdParty\7-Zip\Temp\%romName%" "%1%",,hide
if FileExist("I:\LaunchBox\ThirdParty\7-Zip\Temp\default.xbe")
{
   MsgBox, It exists
   FileMove, "I:\LaunchBox\ThirdParty\7-Zip\Temp\default.xbe", "I:\LaunchBox\ThirdParty\7-Zip\Temp\%romName%.xbe", 1    
}

RunWait, "I:\LaunchBox\Emulators\CXBX\CXBX.exe" "I:\LaunchBox\ThirdParty\7-Zip\Temp\%romName%.xbe", 1

FileRemoveDir, "I:\LaunchBox\ThirdParty\7-Zip\Temp\%romName%"

The MsgBox's are for testing.  I've never used CXBX, so don't know if it looks for an xbe file or something else (adjust accordingly)

"my_game" needs to be named whatever it is CXBX is looking for (minus the extension).

Save the above script somewhere (i.e. I:\myScripts\CXBX.ahk)

For the "new emulator", set the Emulator Application Path to "ThirdParty\AutoHotkey\AutoHotkey.exe" (relative path works)

Set the Default Command-Line Parameters to the full path of you created .ahk script [above], all inside quotes.   ("I:\myScripts\CXBX.ahk")

Leave all boxes unchecked. 

The Sample Command will look something like

AutoHotkey.exe "I:\myScripts\CXBX.ahk" "FULL\PATH\TO\ROM\FILE"

Now set your games to use this "emulator".

This isn't tested and probably needs some adjustments but should give you a good idea of how to make what you're after, work.

Link to comment
Share on other sites

Thanks for helping mate. Here is what I've got now:

; %1% = "I:\LaunchBox\Games\Microsoft Xbox\my_game.zip"
MsgBox, %1%

SplitPath, %1%,,,,romName
; romName = my_game
MsgBox, %romName%

RunWait, "I:\LaunchBox\ThirdParty\7-Zip\7z.exe" x -y -o "I:\LaunchBox\ThirdParty\7-Zip\Temp\%romName%\" "%1%",,hide
if FileExist("I:\LaunchBox\ThirdParty\7-Zip\Temp\%romName%\default.xbe")
{
   MsgBox, It exists
   FileMove, "I:\LaunchBox\ThirdParty\7-Zip\Temp\%romName%\default.xbe", "I:\LaunchBox\ThirdParty\7-Zip\Temp\%romName%\%romName%.xbe", 1    
}

RunWait, "I:\LaunchBox\Emulators\CXBX-R\CXBX.exe" "I:\LaunchBox\ThirdParty\7-Zip\Temp\%romName%\%romName%.xbe", 1

;FileRemoveDir, "I:\LaunchBox\ThirdParty\7-Zip\Temp\%romName%"

So far I get an error on the line with SplitPath, saying there is an illegal character so I looked up that command and I don't know what the illegal character is. I commented that line out to see what happens after and it looks like 7zip didn't extract anything but the rest of the script did send to cxbx to load nothing.xbe, where nothing is literally nothing, just .xbe. I'm assuming this is probably because of not running the SplitPath command. Thanks again for your help.

Link to comment
Share on other sites

Thanks, I have slimmed down the script with no need to rename the xbe and I know what the problem is, just not how to fix it.

fullPath = %1%
SplitPath, fullPath,,,,romName

RunWait, "I:\LaunchBox\ThirdParty\7-Zip\7z.exe" x -y -o"I:\LaunchBox\ThirdParty\7-Zip\Temp\" "%1%",,hide

RunWait, "I:\LaunchBox\Emulators\CXBX-R\CXBX.exe" "I:\LaunchBox\ThirdParty\7-Zip\Temp\%romName%\default.xbe", 1

;FileRemoveDir, "I:\LaunchBox\ThirdParty\7-Zip\Temp\%romName%"

So basically the issue is that the rom file, for examples sake, is called "Futurama [!].7z" but the folder inside the archive doesn't contain the [!] on the end, it's just Futurama. So if in between those two RunWait commands if I can tell the script to delete the [!] from directory name, or just use the extracted directory name instead of %romName%, I think it should work. Any idea how I can accomplish  that?

Edited by Monyet
Link to comment
Share on other sites

If it's safe to say, that after extracting "Futurama[!].7z", of all the folders, subfolders and files that are extracted from it, no matter how many there are, there is ONLY ONE file that is named "default.xbe"...  then this should work.

 

fullPath = %1%
SplitPath, fullPath,,,,romName

RunWait, "I:\LaunchBox\ThirdParty\7-Zip\7z.exe" x -y -o"I:\LaunchBox\ThirdParty\7-Zip\Temp\%romName%" "%1%",,hide

xbeFile = I:\LaunchBox\ThirdParty\7-Zip\Temp\%romName%\default.xbe
Loop, Files, %xbeFile%, FR
xbeFilePath .= A_LoopFilePath

RunWait, "I:\LaunchBox\Emulators\CXBX-R\CXBX.exe" %xbeFilePath%, 1

;FileRemoveDir, "I:\LaunchBox\ThirdParty\7-Zip\Temp\%romName%"

Note: The 1st RunWait line was modified.   If all goes well, xbeFilePath should equal 

I:\LaunchBox\ThirdParty\7-Zip\Temp\Futurama[!]\Futurama\default.xbe

 

Link to comment
Share on other sites

35 minutes ago, JoeViking245 said:

If it's safe to say, that after extracting "Futurama[!].7z", of all the folders, subfolders and files that are extracted from it, no matter how many there are, there is ONLY ONE file that is named "default.xbe"...  then this should work.

 


fullPath = %1%
SplitPath, fullPath,,,,romName

RunWait, "I:\LaunchBox\ThirdParty\7-Zip\7z.exe" x -y -o"I:\LaunchBox\ThirdParty\7-Zip\Temp\%romName%" "%1%",,hide

xbeFile = I:\LaunchBox\ThirdParty\7-Zip\Temp\%romName%\default.xbe
Loop, Files, %xbeFile%, FR
xbeFilePath .= A_LoopFilePath

RunWait, "I:\LaunchBox\Emulators\CXBX-R\CXBX.exe" %xbeFilePath%, 1

;FileRemoveDir, "I:\LaunchBox\ThirdParty\7-Zip\Temp\%romName%"

Note: The 1st RunWait line was modified.   If all goes well, xbeFilePath should equal 


I:\LaunchBox\ThirdParty\7-Zip\Temp\Futurama[!]\Futurama\default.xbe

 

Unfortunately, this seems to just open the emulator but not open the xbe, it doesn't throw up any errors either. There is only the one defualt.xbe in this example, some things I then tried:

I tried changing FR to DFR, and that made no difference.

I thought that maybe xbeFilePath .= should have been := and changed that but it made no difference either.

I tried changing A_LoopFilePath to A_LoopFileDir with the same result.

I added this line above the xbeFile line: SetWorkingDir, I:\LaunchBox\ThirdParty\7-Zip\Temp\%romName%\ with no change either.

I then changed all those things back to what you had. I was looking at this line: "xbeFile = I:\LaunchBox\ThirdParty\7-Zip\Temp\%romName%\default.xbe" and wondering if it needs to have the other directory in there after %romname% which is the crux of the issue anyway. Someone on the AHK discord said I could use a WatchDirectory script to get the name of the folder, but I like the idea of just searching for the default.xbe because 99.9% of disc images are like that I think.

Edited by Monyet
Spellin, grammar
Link to comment
Share on other sites

After the xbeFilePath line add in          MsgBox, %xbeFilePath%    ;See what it's finding. If anything.

18 minutes ago, Monyet said:

wondering if it needs to have the other directory in there

The "R" on the Loop line... "R = Recurse into subdirectories (subfolders)"  So basically it will drill down through the subfolders looking for the specified "F"ile ('default.xbe').

May need to add quotes.?.?. (just a guess)

RunWait, "I:\LaunchBox\Emulators\CXBX-R\CXBX.exe" "%xbeFilePath%", 1

 

Edited by JoeViking245
Link to comment
Share on other sites

12 minutes ago, JoeViking245 said:

After the xbeFilePath line add in          MsgBox, %xbeFilePath%    ;See what it's finding. If anything.

The "R" on the Loop line... "R = Recurse into subdirectories (subfolders)"  So basically it will drill down through the subfolders looking for the specified "F"ile ('default.xbe').

May need to add quotes.?.?. (just a guess)


RunWait, "I:\LaunchBox\Emulators\CXBX-R\CXBX.exe" "%xbeFilePath%", 1

 

The MsgBox comes up with nothing, then CXBX starts but no loading of xbe's or errors. I think it must come down to the way CXBX handles the command line, I read somewhere that it needs absolute paths to load. What I noticed was that if I put anything infront of %xbeFilePath%, for example I put a - , that CXBX would throw up an error saying it couldn't load - so I think it must be ignoring %xbeFilePath%. I'll have to look in to how it handles paths.

Link to comment
Share on other sites

Hey! I just figured it out, because it was talking about Absolute paths I used the command A_LoopFileLongPath and it parsed the right thing to the emulator. It also needed "" around the Xbe path so here's the final code:

fullPath = %1%
SplitPath, fullPath,,,,romName

RunWait, "I:\LaunchBox\ThirdParty\7-Zip\7z.exe" x -y -o"I:\LaunchBox\ThirdParty\7-Zip\Temp\%romName%" "%1%",,hide

xbeFile = I:\LaunchBox\ThirdParty\7-Zip\Temp\%romName%\default.xbe
Loop, Files, %xbeFile%, FR
xbeFilePath .= A_LoopFileLongPath

RunWait, "I:\LaunchBox\Emulators\CXBX-R\CXBX.exe" "%xbeFilePath%", 1

FileRemoveDir, "I:\LaunchBox\ThirdParty\7-Zip\Temp\%romName%"

Thank you so much for your help, I'm a complete muppet at this stuff but you gave me the guidance to figure it out.

Edited by Monyet
  • Game On 1
Link to comment
Share on other sites

I have a big external hard drive that has most of my PC games and emulators on it that I load through Launchbox but it disconnects randomly sometimes it shows back up instantly sometimes I have to reboot my computer. I first tried power and sleep settings in Windows 10 but it didn't help.  Would anyone have a script that can check for the drive's letter at certain intervals and automatically reconnect the drive if it's disconnected? That would be a great help.

 

thanks

Edited by Jayinem
Link to comment
Share on other sites

On 2/5/2021 at 12:43 AM, JoeViking245 said:

Speaking of "quotes"... Looks like they need to be REMOVED from the last line (FileRemoveDir.....).   And since it's also creating the subfolder, you'll need to set recurse to "true".


FileRemoveDir, I:\LaunchBox\ThirdParty\7-Zip\Temp\%romName%, 1

 

Yes, that line doesn't actually delete the files with and without the quotemarks. I tried putting it as the exit script but that didn't make a difference either.

Link to comment
Share on other sites

So, I am here hoping one of y'all may know of an easy script or bat file that I can run from any directory that will do the following:

  • scan the directory for roms and folders and create a .cfg folder/rom with said rom's name.
  • then with each .cfg it will contain the same text as below except where "gb.png" is, it will be changed to whatever the name of the .cfg file is. ie: if the .cfg is named "file.cfg" then the 3rd line of text would read "overlay0_overlay = file.png" 
    overlays = 1
    
    overlay0_overlay = gb.png
    
    overlay0_full_screen = true
    
    overlay0_descs = 0

I am trying to come up with a less redundant way of adding bezels to Retroarch for select platforms without using "The Bezel Project" as those are too generic and cartoony for my liking.

I am cross posting this in this thread as well as AHK forums. 

I am tired so IDK if I am conveying it clearly. It seems as though it may be easy...but for me...it is not. 

Link to comment
Share on other sites

12 hours ago, Monyet said:

that line doesn't actually delete the files

Hmmm... it worked here on my tests. 

CXBX may be launching a sub process, so from the main script, RunWait 'quits' right a way but the files will still be locked so FileRemoveDir can't touch them.  Though if that were the case, you'd probably also see "Thanks For Playing" right away as well.

Try putting in a Sleep timer before deleting the files.  Giving CXBX a chance to release the files.

Link to comment
Share on other sites

15 hours ago, Jayinem said:

I have a big external hard drive that has most of my PC games and emulators on it that I load through Launchbox but it disconnects randomly

You could probably write a script to check it (and possibly reconnect it).  But you'd be much better off fixing the underlying issue.image.thumb.png.cf34a9a0c40f519ed25b723d32771142.png 

  • Game On 1
Link to comment
Share on other sites

3 hours ago, Retro808 said:

@CtinD Please refrain from posting the same question in multiple threads. It is best practice to either find the most appropriate ongoing thread or if none exists start a new one.

This thread would have been more appropriate versus the other thread you posted it in.

I think there's a bit of confusion. I only posted that here and no other place on this site. I then went over to the main AutoHotKey forums site and asked there. It is super cringe for me creating new threads and double posting, so I avoid it at all costs. 

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...