Qt: Add e-Card passing to the command line (closes #2474)

This commit is contained in:
Vicki Pfau 2022-04-21 19:22:29 -07:00
parent 4556d4b121
commit ce7e53d53d
6 changed files with 70 additions and 3 deletions

View File

@ -69,6 +69,7 @@ Misc:
- Qt: Enable -b for Boot BIOS menu option (fixes mgba.io/i/2074) - Qt: Enable -b for Boot BIOS menu option (fixes mgba.io/i/2074)
- Qt: Add tile range selection to tile viewer (closes mgba.io/i/2455) - Qt: Add tile range selection to tile viewer (closes mgba.io/i/2455)
- Qt: Show warning if XQ audio is toggled while loaded (fixes mgba.io/i/2295) - Qt: Show warning if XQ audio is toggled while loaded (fixes mgba.io/i/2295)
- Qt: Add e-Card passing to the command line (closes mgba.io/i/2474)
- Windows: Attach to console if present - Windows: Attach to console if present
- Vita: Add bilinear filtering option (closes mgba.io/i/344) - Vita: Add bilinear filtering option (closes mgba.io/i/344)

View File

@ -125,6 +125,28 @@ ConfigController::ConfigController(QObject* parent)
mCoreConfigSetDefaultIntValue(&m_config, "sgb.borders", 1); mCoreConfigSetDefaultIntValue(&m_config, "sgb.borders", 1);
mCoreConfigSetDefaultIntValue(&m_config, "useCgbColors", 1); mCoreConfigSetDefaultIntValue(&m_config, "useCgbColors", 1);
mCoreConfigMap(&m_config, &m_opts); mCoreConfigMap(&m_config, &m_opts);
mSubParserGraphicsInit(&m_subparsers[0], &m_graphicsOpts);
m_subparsers[1].usage = "Frontend options:\n"
" --ecard FILENAME Scan an e-Reader card in the first loaded game\n"
" Can be paassed multiple times for multiple cards";
m_subparsers[1].parse = nullptr;
m_subparsers[1].parseLong = [](struct mSubParser* parser, const char* option, const char* arg) {
if (option == QLatin1String("ecard")) {
QStringList* eCards = static_cast<QStringList*>(parser->opts);
eCards->append(QString::fromUtf8(arg));
return true;
}
return false;
};
m_subparsers[1].apply = nullptr;
m_subparsers[1].extraOptions = nullptr;
m_subparsers[1].longOptions = (const mOption[]) {
{ "ecard", true, '\0' },
{ 0 }
};
m_subparsers[1].opts = &m_eCards;
} }
ConfigController::~ConfigController() { ConfigController::~ConfigController() {
@ -140,7 +162,7 @@ bool ConfigController::parseArguments(int argc, char* argv[]) {
if (m_parsed) { if (m_parsed) {
return false; return false;
} }
mSubParserGraphicsInit(&m_subparsers[0], &m_graphicsOpts);
if (mArgumentsParse(&m_args, argc, argv, m_subparsers.data(), m_subparsers.size())) { if (mArgumentsParse(&m_args, argc, argv, m_subparsers.data(), m_subparsers.size())) {
mCoreConfigFreeOpts(&m_opts); mCoreConfigFreeOpts(&m_opts);
mArgumentsApply(&m_args, m_subparsers.data(), m_subparsers.size(), &m_config); mArgumentsApply(&m_args, m_subparsers.data(), m_subparsers.size(), &m_config);
@ -312,6 +334,10 @@ void ConfigController::usage(const char* arg0) const {
::usage(arg0, nullptr, nullptr, m_subparsers.data(), m_subparsers.size()); ::usage(arg0, nullptr, nullptr, m_subparsers.data(), m_subparsers.size());
} }
QStringList ConfigController::takeECardList() {
return QStringList(std::move(m_eCards));
}
bool ConfigController::isPortable() { bool ConfigController::isPortable() {
return mCoreConfigIsPortable(); return mCoreConfigIsPortable();
} }

View File

@ -96,6 +96,8 @@ public:
const mGraphicsOpts* graphicsOpts() const { return &m_graphicsOpts; } const mGraphicsOpts* graphicsOpts() const { return &m_graphicsOpts; }
void usage(const char* arg0) const; void usage(const char* arg0) const;
QStringList takeECardList();
static const QString& configDir(); static const QString& configDir();
static bool isPortable(); static bool isPortable();
@ -117,8 +119,9 @@ private:
mCoreOptions m_opts{}; mCoreOptions m_opts{};
mArguments m_args{}; mArguments m_args{};
mGraphicsOpts m_graphicsOpts{}; mGraphicsOpts m_graphicsOpts{};
std::array<mSubParser, 1> m_subparsers; std::array<mSubParser, 2> m_subparsers;
bool m_parsed = false; bool m_parsed = false;
QStringList m_eCards;
QHash<QString, ConfigOption*> m_optionSet; QHash<QString, ConfigOption*> m_optionSet;
std::unique_ptr<QSettings> m_settings; std::unique_ptr<QSettings> m_settings;

View File

@ -897,8 +897,31 @@ void CoreController::scanCard(const QString& path) {
QImage image(path); QImage image(path);
if (image.isNull()) { if (image.isNull()) {
QFile file(path); QFile file(path);
file.open(QIODevice::ReadOnly); if (!file.open(QIODevice::ReadOnly)) {
return;
}
m_eReaderData = file.read(2912); m_eReaderData = file.read(2912);
file.seek(0);
QStringList lines;
QDir basedir(QFileInfo(path).dir());
while (true) {
QByteArray line = file.readLine().trimmed();
if (line.isEmpty()) {
break;
}
QString filepath(QString::fromUtf8(line));
if (filepath[0] == QChar('#')) {
continue;
}
if (QFileInfo(filepath).isRelative()) {
lines.append(basedir.filePath(filepath));
} else {
lines.append(filepath);
}
}
scanCards(lines);
} else if (image.size() == QSize(989, 44) || image.size() == QSize(639, 44)) { } else if (image.size() == QSize(989, 44) || image.size() == QSize(639, 44)) {
const uchar* bits = image.constBits(); const uchar* bits = image.constBits();
size_t size; size_t size;
@ -917,6 +940,11 @@ void CoreController::scanCard(const QString& path) {
#endif #endif
} }
void CoreController::scanCards(const QStringList& paths) {
for (const QString& path : paths) {
scanCard(path);
}
}
void CoreController::importSharkport(const QString& path) { void CoreController::importSharkport(const QString& path) {
#ifdef M_CORE_GBA #ifdef M_CORE_GBA

View File

@ -159,6 +159,7 @@ public slots:
void loadSave(VFile*, bool temporary); void loadSave(VFile*, bool temporary);
void loadPatch(const QString&); void loadPatch(const QString&);
void scanCard(const QString&); void scanCard(const QString&);
void scanCards(const QStringList&);
void replaceGame(const QString&); void replaceGame(const QString&);
void yankPak(); void yankPak();

View File

@ -925,8 +925,16 @@ void Window::gameStarted() {
action->setActive(true); action->setActive(true);
} }
} }
interrupter.resume();
m_actions.rebuildMenu(menuBar(), this, *m_shortcutController); m_actions.rebuildMenu(menuBar(), this, *m_shortcutController);
#ifdef M_CORE_GBA
if (m_controller->platform() == mPLATFORM_GBA) {
m_controller->scanCards(m_config->takeECardList());
}
#endif
#ifdef USE_DISCORD_RPC #ifdef USE_DISCORD_RPC
DiscordCoordinator::gameStarted(m_controller); DiscordCoordinator::gameStarted(m_controller);
#endif #endif