Skip to content

Commit

Permalink
Custom path support
Browse files Browse the repository at this point in the history
Refactored how launch args are handled in a smarter way.
Custom paths must be an absolute path (so including the drive letter on Windows, or a forward slash '/' on *nix).
Attempts to fix custom paths on Windows, since local files expects backslashes '\'.
  • Loading branch information
SeongGino authored Mar 26, 2024
1 parent 9c2de5c commit 48b2193
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 15 deletions.
57 changes: 48 additions & 9 deletions main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,25 +4,64 @@

int main(int argc, char *argv[])
{
QCoreApplication app(argc, argv);
QCoreApplication *app = new QCoreApplication(argc, argv);

qhookerMain mainApp;

QString cliArg = argv[1];
if(cliArg == "-v") {
mainApp.verbosity = true;
qInfo() << "Enabling verbose output!";
// argc is a count of arguments starting from 1 (executable inclusive),
// argv is an array containing each argument starting from 0 (executable inclusive).
if(argc > 1) {
QStringList arguments;
for(uint8_t i = 1; i < argc; i++) {
arguments.append(argv[i]);
}
if(arguments.contains("-v")) {
mainApp.verbosity = true;
qInfo() << "Enabling verbose output!";
arguments.removeAt(arguments.indexOf("-v"));
}
if(arguments.contains("-p")) {
if(arguments.length() > 1) {
mainApp.customPath = arguments[arguments.indexOf("-p")+1];
#ifdef Q_OS_WIN
if(mainApp.customPath.contains('/')) {
mainApp.customPath.replace('/', '\\');
}
if(mainApp.customPath.contains(":\\") || mainApp.customPath.contains(":/")) {
#else
if(mainApp.customPath.contains("/")) {
#endif // Q_OS_WIN
mainApp.customPathSet = true;
#ifdef Q_OS_WIN
if(mainApp.customPath.endsWith('\\')) {
mainApp.customPath.append('\\');
}
#else
if(!mainApp.customPath.endsWith('/')) {
mainApp.customPath.append('/');
}
#endif // Q_OS_WIN
qInfo() << "Setting search path to" << mainApp.customPath;
arguments.removeAt(arguments.indexOf("-p")+1);
} else {
qWarning() << "Bad custom path specified (must be an absolute path)! Disregarding.";
}
} else {
qWarning() << "Detected custom path flag without any path specified! Disregarding.";
}
arguments.removeAt(arguments.indexOf("-p"));
}
}

// connect up the signals
QObject::connect(&mainApp, SIGNAL(finished()),
&app, SLOT(quit()));
QObject::connect(&app, SIGNAL(aboutToQuit()),
&mainApp, SLOT(aboutToQuitApp()));
app, SLOT(quit()), Qt::QueuedConnection);
QObject::connect(app, SIGNAL(aboutToQuit()),
&mainApp, SLOT(aboutToQuitApp()), Qt::QueuedConnection);

// This code will start the messaging engine in QT and in
// 10ms it will start the execution in the MainClass.run routine;
QTimer::singleShot(10, &mainApp, SLOT(run()));

return app.exec();
return app->exec();
}
16 changes: 10 additions & 6 deletions qhookermain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -148,14 +148,18 @@ void qhookerMain::GameSearching(QString input)
}
gameName = input.remove(0, input.indexOf("=")+1);
qInfo() << gameName;

// TODO: there might be a better path for this? Trying to prevent "../QMamehook/QMamehook/ini" on Windows here.
#ifdef Q_OS_WIN

if(customPathSet) {
LoadConfig(customPath + gameName + ".ini");
} else {
// TODO: there might be a better path for this? Trying to prevent "../QMamehook/QMamehook/ini" on Windows here.
#ifdef Q_OS_WIN
LoadConfig(QString(QStandardPaths::writableLocation(QStandardPaths::ConfigLocation) + "/ini/" + gameName + ".ini"));
#else
#else
LoadConfig(QString(QStandardPaths::writableLocation(QStandardPaths::ConfigLocation) + "/QMamehook/ini/" + gameName + ".ini"));
#endif

#endif
}

if(settings->contains("MameStart")) {
//qInfo() << "Detected start statement:";
QStringList tempBuffer = settings->value("MameStart").toStringList();
Expand Down
4 changes: 4 additions & 0 deletions qhookermain.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,10 @@ class qhookerMain : public QObject

bool verbosity = false;

bool customPathSet = false;

QString customPath;

void quit();

signals:
Expand Down

0 comments on commit 48b2193

Please sign in to comment.