Preserve installed MAME settings in isolated ordinary runs
This commit is contained in:
+42
-11
@@ -5,6 +5,8 @@ from __future__ import annotations
|
||||
from dataclasses import dataclass
|
||||
import os
|
||||
from pathlib import Path
|
||||
import sys
|
||||
import xml.etree.ElementTree as ET
|
||||
|
||||
|
||||
@dataclass(frozen=True)
|
||||
@@ -77,16 +79,45 @@ def from_arguments(args) -> MameProfile:
|
||||
for name in names})
|
||||
|
||||
|
||||
KEYBOARD_TAGS = (":", ":kbd:ms_naturl")
|
||||
|
||||
|
||||
def write_keyboard_config(cfg_directory: Path) -> None:
|
||||
"""Включить обе клавиатуры Sprinter, включая прямой ввод в DSS."""
|
||||
"""Включить обе клавиатуры Sprinter, включая прямой ввод в DSS.
|
||||
|
||||
Если в каталоге уже лежит sprinter.cfg (например, скопированный из
|
||||
MAME_HOME/cfg), остальные его настройки сохраняются, а в копии
|
||||
включаются только нужные клавиатуры.
|
||||
"""
|
||||
cfg_directory.mkdir(parents=True, exist_ok=True)
|
||||
(cfg_directory / "sprinter.cfg").write_text(
|
||||
'<?xml version="1.0"?>\n'
|
||||
'<mameconfig version="10">\n'
|
||||
' <system name="sprinter">\n'
|
||||
' <input>\n'
|
||||
' <keyboard tag=":" enabled="1" />\n'
|
||||
' <keyboard tag=":kbd:ms_naturl" enabled="1" />\n'
|
||||
' </input>\n'
|
||||
' </system>\n'
|
||||
'</mameconfig>\n', encoding="utf-8")
|
||||
path = cfg_directory / "sprinter.cfg"
|
||||
root = None
|
||||
if path.is_file():
|
||||
try:
|
||||
root = ET.parse(path).getroot()
|
||||
except ET.ParseError as error:
|
||||
print(f"mame_profile: {path} не разобран ({error}), создаётся заново",
|
||||
file=sys.stderr)
|
||||
if root is None or root.tag != "mameconfig":
|
||||
root = ET.Element("mameconfig", version="10")
|
||||
system = next((item for item in root.findall("system")
|
||||
if item.get("name") == "sprinter"), None)
|
||||
if system is None:
|
||||
system = ET.SubElement(root, "system", name="sprinter")
|
||||
input_node = system.find("input")
|
||||
if input_node is None:
|
||||
input_node = ET.SubElement(system, "input")
|
||||
keyboards = {item.get("tag"): item for item in input_node.findall("keyboard")}
|
||||
for tag in KEYBOARD_TAGS:
|
||||
keyboard = keyboards.get(tag)
|
||||
if keyboard is None:
|
||||
keyboard = ET.Element("keyboard", tag=tag)
|
||||
# MAME ожидает keyboard перед port внутри input.
|
||||
position = sum(1 for item in input_node if item.tag == "keyboard")
|
||||
input_node.insert(position, keyboard)
|
||||
keyboard.set("enabled", "1")
|
||||
tree = ET.ElementTree(root)
|
||||
ET.indent(tree, space=" ")
|
||||
tree.write(path, encoding="utf-8", xml_declaration=True)
|
||||
with path.open("a", encoding="utf-8") as stream:
|
||||
stream.write("\n")
|
||||
|
||||
@@ -4,6 +4,7 @@ from __future__ import annotations
|
||||
|
||||
import argparse
|
||||
from pathlib import Path
|
||||
import shutil
|
||||
import subprocess
|
||||
import sys
|
||||
import tempfile
|
||||
@@ -43,13 +44,21 @@ def main() -> int:
|
||||
state = Path(directory)
|
||||
for name in ("cfg", "nvram", "diff", "snapshot"):
|
||||
(state / name).mkdir()
|
||||
# Настройки и NVRAM установленной среды берутся копией: MAME
|
||||
# перезаписывает их при выходе, а MAME_HOME должен остаться нетронутым.
|
||||
for name in ("cfg", "nvram"):
|
||||
source = profile.home / name if profile.home else None
|
||||
if source and source.is_dir():
|
||||
shutil.copytree(source, state / name, dirs_exist_ok=True)
|
||||
snapshots = Path(args.snapshot_dir).resolve() if args.snapshot_dir else state / "snapshot"
|
||||
snapshots.mkdir(parents=True, exist_ok=True)
|
||||
write_keyboard_config(state / "cfg")
|
||||
command = [str(profile.binary), "sprinter", "-noreadconfig",
|
||||
"-rompath", str(profile.rompath), "-bios", profile.bios,
|
||||
"-kbd", "ms_naturl,bios=sp2k", "-video", args.video,
|
||||
"-window", "-skip_gameinfo", "-beta:wd179x:0", "35hd",
|
||||
"-window", "-skip_gameinfo",
|
||||
"-beta:wd179x:0", "35hd",
|
||||
"-beta:wd179x:1", "35hd",
|
||||
"-flop2", str(profile.dss_image),
|
||||
"-hard1", str(profile.system_hdd_image)]
|
||||
if "floppy" in media:
|
||||
|
||||
Reference in New Issue
Block a user