Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add an option for user-provided .cmd file for libretroMAME #13216

Merged
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -454,9 +454,18 @@ def generateMAMEConfigs(playersControllers: ControllerMapping, system: Emulator,

# Write command line file
cmdFilename = cmdPath / f"{romDrivername}.cmd"
cmdFile = cmdFilename.open("w")
cmdFile.write(' '.join(str(item) for item in commandLine))
cmdFile.close()
# Check to see whether user provided a custom cmd file, at either a default location, or specified in batocera.conf
defaultCustomCmdFilepath = f'{rom}.cmd'
Copy link
Contributor

@bryanforbes bryanforbes Jan 15, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If use rom.with_suffix(f'{rom.suffix}.cmd'), you'll get a path object and won't need to use Path() on the next line

Copy link
Contributor Author

@tsankuanglee tsankuanglee Jan 16, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The filename variable is used again in line 460 when copying. If we use that, we'll have to construct the filename again for line 460, no?

That said, I condensed this section for brevity.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, my bad. I see your point now. Will fix.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lol. too late. I have other stuff to push and will include this.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@bryanforbes

To me, the current version

if Path(defaultCustomCmdFilepath := f"{rom}.cmd").is_file():

is slightly easier to understand than:

if (defaultCustomCmdFilepath := rom.with_suffix(f"{rom.suffix}.cmd")).is_file():

I did look into pathlib's source code and saw that a new construction is fairly cheap so the performance isn't really an issue.

I see you have another PR about using the Path object throughout. I think I'll leave this one for you to decide.

if Path(defaultCustomCmdFilepath).is_file():
shutil.copyfile(defaultCustomCmdFilepath, cmdFilename)
elif system.isOptSet("cmdfile"):
# User specified where to find the custom .cmd file in batocera.conf
shutil.copyfile(system.config["cmdfile"], cmdFilename)
else:
# User did not provide a custom .cmd file. Use the logic above to create a new .cmd file
cmdFile = cmdFilename.open("w")
cmdFile.write(' '.join(str(item) for item in commandLine))
cmdFile.close()

# Call Controller Config
if messMode == -1:
Expand Down