Skip to content

Commit

Permalink
ui: Call out to Python to get data dir if it can't be found otherwise
Browse files Browse the repository at this point in the history
  • Loading branch information
Vicki Pfau committed Oct 15, 2018
1 parent 1869d57 commit 4f6c60d
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 13 deletions.
4 changes: 4 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Changelog

## 0.6.1

* integration UI searches for current Python's Gym Retro data directory

## 0.6.0

* add cores for GB/C, GBA, GG, NES, SMS, SNES, TurboGrafx
Expand Down
47 changes: 35 additions & 12 deletions src/ui/EmulatorController.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,17 @@
#include <QJsonObject>
#include <QKeyEvent>
#include <QMap>
#include <QProcess>
#include <QSettings>

#include "coreinfo.h"
#include "movie-bk2.h"

#include "zlib.h"

QSettings EmulatorController::s_settings;
QString EmulatorController::s_path;

EmulatorController::EmulatorController(QObject* parent)
: QObject(parent) {
initCorePath();
Expand Down Expand Up @@ -74,10 +78,10 @@ bool EmulatorController::loadGame(const QString& path) {
m_keybinds[p].append(-1);
}
}
m_settings.beginGroup(QString("bindings/%2").arg(platform()));
const auto& keys = m_settings.childKeys();
s_settings.beginGroup(QString("bindings/%2").arg(platform()));
const auto& keys = s_settings.childKeys();
for (const auto& key : keys) {
QVariant value = m_settings.value(key);
QVariant value = s_settings.value(key);
if (value.isNull()) {
continue;
}
Expand All @@ -90,7 +94,7 @@ bool EmulatorController::loadGame(const QString& path) {
setKeyBind(keyparts[0], value.toInt(), player);
}
}
m_settings.endGroup();
s_settings.endGroup();

QDir dir = info.dir();

Expand Down Expand Up @@ -156,12 +160,12 @@ void EmulatorController::setKeyBind(const QString& key, int binding, unsigned pl
if (iter != bindings.end()) {
m_keybinds[player][iter - bindings.begin()] = binding;
if (player > 0) {
m_settings.setValue(QString("bindings/%1/%2-%3").arg(platform()).arg(key).arg(player + 1), binding);
s_settings.setValue(QString("bindings/%1/%2-%3").arg(platform()).arg(key).arg(player + 1), binding);
} else {
m_settings.setValue(QString("bindings/%1/%2").arg(platform()).arg(key), binding);
s_settings.setValue(QString("bindings/%1/%2").arg(platform()).arg(key), binding);
}
}
m_settings.sync();
s_settings.sync();
}

Retro::GameData* EmulatorController::data() {
Expand Down Expand Up @@ -322,12 +326,31 @@ QString EmulatorController::coreForFile(const QString& path) {
}

QString EmulatorController::dataPath() {
QVariant path = QSettings().value("paths/data");
if (path.isNull()) {
return QString::fromStdString(Retro::GameData::dataPath());
} else {
return path.toString();
if (s_path.isNull() || !QDir(s_path).exists()) {
s_path = s_settings.value("paths/data").toString();
}
if (s_path.isNull() || !QDir(s_path).exists()) {
s_path = QString::fromStdString(Retro::GameData::dataPath());
}
if (s_path.isNull() || !QDir(s_path).exists()) {
QProcess* subproc = new QProcess;
connect(subproc, static_cast<void (QProcess::*)(int, QProcess::ExitStatus)>(&QProcess::finished), subproc, [subproc](int, QProcess::ExitStatus) {
subproc->deleteLater();
});
subproc->start("python3", {"-c", "import retro; print(retro.data.path())"});
subproc->waitForStarted();
while (subproc->state() != QProcess::NotRunning) {
subproc->waitForFinished(10);
if (subproc->canReadLine()) {
s_path = QString::fromUtf8(subproc->readLine()).trimmed();
break;
}
}
if (s_path.isEmpty() || subproc->exitStatus() != QProcess::NormalExit || subproc->exitCode() != 0) {
s_path = QString();
}
}
return s_path;
}

QList<Cheat> EmulatorController::cheats() const {
Expand Down
3 changes: 2 additions & 1 deletion src/ui/EmulatorController.h
Original file line number Diff line number Diff line change
Expand Up @@ -126,5 +126,6 @@ private slots:
bool m_autosaveScen = false;
bool m_autosaveSearches = false;

QSettings m_settings;
static QSettings s_settings;
static QString s_path;
};

0 comments on commit 4f6c60d

Please sign in to comment.