1
0
mirror of https://github.com/Melon-Bread/RetroUFO synced 2024-11-25 00:38:33 -05:00

Initial macOS support (and small refactor)

This commit is contained in:
Rain Clark 2019-03-04 20:55:30 -05:00
parent 487df92020
commit 7a5bbe4183

47
RetroUFO_GUI.py Normal file → Executable file
View File

@ -23,8 +23,9 @@ URL = 'https://buildbot.libretro.com/nightly'
# These are the default core locations with normal RetroArch installs based off of 'retroarch.default.cfg` # These are the default core locations with normal RetroArch installs based off of 'retroarch.default.cfg`
CORE_LOCATION = { CORE_LOCATION = {
'linux': '{}/.config/retroarch/cores'.format(Path.home()), 'linux': '{}/.config/retroarch/cores'.format(os.path.expanduser('~')),
'windows': '{}/AppData/Roaming/RetroArch/cores'.format(Path.home()) 'apple/osx': '{}/Library/Applications/RetroArch.app/Contents/Resources/cores'.format(os.path.expanduser('~')), # macOS
'windows': '{}/AppData/Roaming/RetroArch/cores'.format(os.path.expanduser('~'))
} }
@ -42,6 +43,7 @@ class Form(QDialog):
self.cmbboxPlatform.setEnabled(False) self.cmbboxPlatform.setEnabled(False)
self.cmbboxPlatform.setEditable(False) self.cmbboxPlatform.setEditable(False)
self.cmbboxPlatform.addItem('Linux') self.cmbboxPlatform.addItem('Linux')
self.cmbboxPlatform.addItem('macOS')
self.cmbboxPlatform.addItem('Windows') self.cmbboxPlatform.addItem('Windows')
self.cmbboxArchitecture = QComboBox() self.cmbboxArchitecture = QComboBox()
@ -103,19 +105,17 @@ class Form(QDialog):
def choose_location(self): def choose_location(self):
directory = QFileDialog.getExistingDirectory( directory = QFileDialog.getExistingDirectory(
self, 'Choose Target Location', '/home') self, 'Choose Target Location', os.path.expanduser('~'))
self.leditCoreLocation.insert(directory) self.leditCoreLocation.insert(directory)
def grab_cores(self): def grab_cores(self):
self.teditLog.insertPlainText('Starting UFO Grabber\n') self.teditLog.insertPlainText('~Starting UFO Grabber~\n')
""" Where the magic happens """ """ Where the magic happens """
# If a platform and/or architecture is not supplied it is grabbed automatically # If a platform and/or architecture is not supplied it is grabbed automatically
platform = self.cmbboxPlatform.currentText().lower() if not self.chkboxPlatformDetect.isChecked() \ platform = self.get_platform() # TODO: rename this var to prevent conflict
else self.get_platform() # TODO: rename this var to prevent conflict architecture = self.get_architecture()
architecture = self.cmbboxArchitecture.currentText().lower() if not self.chkboxPlatformDetect.isChecked() \
else self.get_architecture()
location = self.leditCoreLocation.text() if not self.chkboxLocationDetect.isChecked() \ location = self.leditCoreLocation.text() if not self.chkboxLocationDetect.isChecked() \
else CORE_LOCATION[platform] else CORE_LOCATION[platform]
@ -128,15 +128,22 @@ class Form(QDialog):
def get_platform(self): def get_platform(self):
""" Gets the Platform and Architecture if not supplied """ """ Gets the Platform and Architecture if not supplied """
if platform.system() == 'Linux': if not self.chkboxPlatformDetect.isChecked():
return 'linux' if self.cmbboxPlatform.currentText() == 'macOS':
return 'apple/osx' # macOS
elif platform.system() == 'Windows' or 'MSYS_NT' in platform.system(): # Checks for MSYS environment as well else:
return 'windows' return self.cmbboxPlatform.currentText().lower()
else: else:
msgBox = QMessageBox.warning(self, 'Error', 'Platform not found or supported!', QMessageBox.Ok) if platform.system() == 'Linux':
msgBox.exec_() return 'linux'
sys.exit(0) elif platform.system() == 'Darwin': # macOS
return 'apple/osx'
elif platform.system() == 'Windows' or 'MSYS_NT' in platform.system(): # Checks for MSYS environment as well
return 'windows'
else:
msgBox = QMessageBox.warning(self, 'Error', 'Platform not found or supported!', QMessageBox.Ok)
msgBox.exec_()
sys.exit(0)
def get_architecture(self): def get_architecture(self):
""" Gets the Platform and Architecture if not supplied """ """ Gets the Platform and Architecture if not supplied """
@ -164,7 +171,7 @@ class Form(QDialog):
urlretrieve( urlretrieve(
'{}/{}/{}/latest/.index-extended'.format( '{}/{}/{}/latest/.index-extended'.format(
URL, _platform, _architecture), 'cores/index') URL, _platform, _architecture), 'cores/index')
self.teditLog.insertPlainText('Obtained core index!') self.teditLog.insertPlainText('\nObtained core index!')
# Adds all the core's file names to a list # Adds all the core's file names to a list
core_index = open('cores/index') core_index = open('cores/index')
@ -180,19 +187,19 @@ class Form(QDialog):
urlretrieve( urlretrieve(
'{}/{}/{}/latest/{}'.format(URL, _platform, _architecture, '{}/{}/{}/latest/{}'.format(URL, _platform, _architecture,
core), 'cores/{}'.format(core)) core), 'cores/{}'.format(core))
print('Downloaded {} ...'.format(core)) self.teditLog.insertPlainText('\nDownloaded {} ...'.format(core))
# Removes index file for easier extraction # Removes index file for easier extraction
os.remove('cores/index') os.remove('cores/index')
def extract_cores(self, _location): def extract_cores(self, _location):
""" Extracts each downloaded core to the RA core directory """ """ Extracts each downloaded core to the RA core directory """
print('Extracting all cores to: {}'.format(_location)) self.teditLog.insertPlainText('\nExtracting all cores to: {}'.format(_location))
for file in os.listdir('cores'): for file in os.listdir('cores'):
archive = zipfile.ZipFile('cores/{}'.format(file)) archive = zipfile.ZipFile('cores/{}'.format(file))
archive.extractall(_location) archive.extractall(_location)
print('Extracted {} ...'.format(file)) self.teditLog.insertPlainText('\nExtracted {} ...'.format(file))
def clean_up(self): def clean_up(self):
""" Removes all the downloaded files """ """ Removes all the downloaded files """