Upload files to ''
This commit is contained in:
parent
4dd80382ce
commit
a66446d519
94
config_editor.py
Normal file
94
config_editor.py
Normal file
@ -0,0 +1,94 @@
|
||||
import os
|
||||
from PyQt5 import QtCore, QtGui, QtWidgets
|
||||
import configparser
|
||||
|
||||
# Load configuration from file
|
||||
config = configparser.ConfigParser()
|
||||
config.read('dbgr.conf')
|
||||
|
||||
class ConfigEditor(QtWidgets.QMainWindow):
|
||||
def __init__(self, parent=None):
|
||||
super().__init__(parent)
|
||||
self.setGeometry(100, 100, 600, 150) # Set window size to 600x150 pixels
|
||||
self.create_widgets()
|
||||
|
||||
def create_widgets(self):
|
||||
central_widget = QtWidgets.QWidget(self)
|
||||
self.setCentralWidget(central_widget)
|
||||
|
||||
# Create labels and entry fields for each config variable
|
||||
dosbox_path_label = QtWidgets.QLabel('DOSBox Path', central_widget)
|
||||
self.dosbox_path_entry = QtWidgets.QLineEdit(central_widget)
|
||||
self.dosbox_path_entry.setText(config['DEFAULT']['dosbox_path'])
|
||||
|
||||
game_path_label = QtWidgets.QLabel('Game Path', central_widget)
|
||||
self.game_path_entry = QtWidgets.QLineEdit(central_widget)
|
||||
self.game_path_entry.setText(config['DEFAULT']['game_path'])
|
||||
self.browse_button = QtWidgets.QPushButton('Browse', central_widget)
|
||||
self.browse_button.clicked.connect(self.browse_game_path)
|
||||
|
||||
working_directory_label = QtWidgets.QLabel('Working Directory', central_widget)
|
||||
self.working_directory_entry = QtWidgets.QLineEdit(central_widget)
|
||||
self.working_directory_entry.setText(config['DEFAULT']['working_directory'])
|
||||
|
||||
cycles_label = QtWidgets.QLabel('Cycles', central_widget)
|
||||
self.cycles_entry = QtWidgets.QLineEdit(central_widget)
|
||||
self.cycles_entry.setText(config['DEFAULT']['-cycles'])
|
||||
|
||||
memsize_label = QtWidgets.QLabel('Memsize', central_widget)
|
||||
self.memsize_entry = QtWidgets.QLineEdit(central_widget)
|
||||
self.memsize_entry.setText(config['DEFAULT']['-memsize'])
|
||||
|
||||
# Create save button
|
||||
save_button = QtWidgets.QPushButton('Save', central_widget)
|
||||
save_button.clicked.connect(self.save_config)
|
||||
|
||||
# Set layout
|
||||
layout = QtWidgets.QGridLayout(central_widget)
|
||||
layout.addWidget(dosbox_path_label, 0, 0)
|
||||
layout.addWidget(self.dosbox_path_entry, 0, 1)
|
||||
layout.addWidget(game_path_label, 1, 0)
|
||||
layout.addWidget(self.game_path_entry, 1, 1)
|
||||
layout.addWidget(self.browse_button, 1, 2)
|
||||
layout.addWidget(working_directory_label, 2, 0)
|
||||
layout.addWidget(self.working_directory_entry, 2, 1)
|
||||
layout.addWidget(cycles_label, 3, 0)
|
||||
layout.addWidget(self.cycles_entry, 3, 1)
|
||||
layout.addWidget(memsize_label, 4, 0)
|
||||
layout.addWidget(self.memsize_entry, 4, 1)
|
||||
layout.addWidget(save_button, 5, 0, 1, 2)
|
||||
|
||||
def browse_game_path(self):
|
||||
# Set initial directory to script directory
|
||||
initial_dir = os.path.dirname(__file__)
|
||||
|
||||
# Open file dialog to select game file
|
||||
filetypes = [('All files', '*.*')]
|
||||
game_file, _ = QtWidgets.QFileDialog.getOpenFileName(self, 'Select game file', initial_dir, ';;'.join(['{} (*.{})'.format(ft.upper(), ft) for ft in ['exe', 'com', 'bat']]))
|
||||
if game_file:
|
||||
self.game_path_entry.setText(game_file)
|
||||
self.working_directory_entry.setText(os.path.dirname(game_file))
|
||||
|
||||
def save_config(self):
|
||||
# Update configuration with values from entry fields
|
||||
config['DEFAULT']['dosbox_path'] = self.dosbox_path_entry.text()
|
||||
config['DEFAULT']['game_path'] = self.game_path_entry.text()
|
||||
config['DEFAULT']['working_directory'] = self.working_directory_entry.text()
|
||||
config['DEFAULT']['-cycles'] = self.cycles_entry.text()
|
||||
config['DEFAULT']['-memsize'] = self.memsize_entry.text()
|
||||
|
||||
# Write updated configuration to file
|
||||
with open('dbgr.conf', 'w') as configfile:
|
||||
config.write(configfile)
|
||||
|
||||
# Close GUI window
|
||||
self.close()
|
||||
|
||||
# Create and run GUI application
|
||||
if __name__ == '__main__':
|
||||
import sys
|
||||
app = QtWidgets.QApplication(sys.argv)
|
||||
editor = ConfigEditor()
|
||||
editor.show()
|
||||
sys.exit(app.exec_())
|
||||
|
93
dbgr.py
Normal file
93
dbgr.py
Normal file
@ -0,0 +1,93 @@
|
||||
#!/usr/bin/env python3
|
||||
|
||||
import os
|
||||
import configparser
|
||||
import logging
|
||||
import subprocess
|
||||
|
||||
# Set up logging
|
||||
logging.basicConfig(filename='dbgr.log', level=logging.DEBUG)
|
||||
|
||||
# Call config editor GUI application
|
||||
subprocess.run(['python', 'config_editor.py'])
|
||||
|
||||
# Load configuration from file
|
||||
config = configparser.ConfigParser()
|
||||
if not os.path.exists('dbgr.conf'):
|
||||
# Create config file with default values
|
||||
config['DEFAULT'] = {
|
||||
'dosbox_path': '',
|
||||
'game_path': '',
|
||||
'working_directory': '',
|
||||
'-noconsole': '',
|
||||
'-conf': 'dbgr.conf',
|
||||
'-cycles': 'auto',
|
||||
'-cputype': 'auto',
|
||||
'-memsize': '16',
|
||||
'-sblaster': 'sb16',
|
||||
'-sbbase': '220',
|
||||
'-irq': '7',
|
||||
'-dma': '1',
|
||||
'-ultradir': 'c:\\ultra',
|
||||
'-mididevice': 'default',
|
||||
'-mpu401': 'intelligent',
|
||||
'-uart': '16550A',
|
||||
'-midi': 'mpu-401',
|
||||
'-cdrom': '',
|
||||
'-ioctl': '',
|
||||
'-serial': 'nullmodem',
|
||||
'-ipx': 'true',
|
||||
'-net': 'nic',
|
||||
'ms_dos_exe': '',
|
||||
}
|
||||
with open('dbgr.conf', 'w') as configfile:
|
||||
config.write(configfile)
|
||||
else:
|
||||
config.read('dbgr.conf')
|
||||
|
||||
# Detect DOSBox path if not specified in config
|
||||
if not config['DEFAULT']['dosbox_path']:
|
||||
dosbox_paths = ['/usr/local/bin/dosbox', '/usr/bin/dosbox', '/usr/bin/dosbox-staging']
|
||||
for path in dosbox_paths:
|
||||
if os.path.exists(path):
|
||||
config['DEFAULT']['dosbox_path'] = path
|
||||
break
|
||||
|
||||
# Set game path and working directory from config
|
||||
game_path = config['DEFAULT']['game_path']
|
||||
working_directory = config['DEFAULT']['working_directory']
|
||||
|
||||
# Set DOSBox options from config, overriding any defaults set in the script
|
||||
for switch, value in config['DEFAULT'].items():
|
||||
if switch.startswith('-') and value:
|
||||
os.environ[switch] = value
|
||||
|
||||
# Set audio and video options with sane defaults
|
||||
if 'audio' not in config:
|
||||
config['audio'] = {
|
||||
'sbtype': 'sb16',
|
||||
'sbbase': '220',
|
||||
'irq': '7',
|
||||
'dma': '1'
|
||||
}
|
||||
|
||||
if 'video' not in config:
|
||||
config['video'] = {
|
||||
'output': 'sdl',
|
||||
'aspect': 'false',
|
||||
'scaler': 'normal2x',
|
||||
'fullresolution': 'desktop',
|
||||
'window_mode': 'true'
|
||||
}
|
||||
|
||||
# Write updated configuration to file
|
||||
with open('dbgr.conf', 'w') as configfile:
|
||||
config.write(configfile)
|
||||
|
||||
# Run DOSBox with specified game and options
|
||||
if not os.path.exists(game_path):
|
||||
raise Exception(f"Game path '{game_path}' does not exist.")
|
||||
|
||||
os.chdir(working_directory)
|
||||
os.system(f'"{config["DEFAULT"]["dosbox_path"]}" -conf dbgr.conf "{game_path}"')
|
||||
|
Loading…
x
Reference in New Issue
Block a user