Skip to content

Commit b3d9105

Browse files
Made working directory be available as command-line argument
1 parent 639c8da commit b3d9105

File tree

5 files changed

+82
-13
lines changed

5 files changed

+82
-13
lines changed

trikControl/src/display.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,12 +66,12 @@ void Display::removeLabels()
6666

6767
void Display::smile()
6868
{
69-
showImage(mStartDirPath + "/media/trik_smile_normal.png");
69+
showImage(mStartDirPath + "media/trik_smile_normal.png");
7070
}
7171

7272
void Display::sadSmile()
7373
{
74-
showImage(mStartDirPath + "/media/trik_smile_sad.png");
74+
showImage(mStartDirPath + "media/trik_smile_sad.png");
7575
}
7676

7777
void Display::setBackground(QString const &color)

trikGui/main.cpp

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,15 +34,20 @@
3434
using namespace trikGui;
3535

3636
void printUsage() {
37-
qDebug() << "Usage: ./trikGui [-qws] [-c <full path to config files>]";
37+
qDebug() << "Usage: ./trikGui"
38+
<< "[-qws]"
39+
<< "[-c <full path to config files>]"
40+
<< "[-d <full path to a directory with resources>]";
3841
qDebug() << "Arguments:";
3942
qDebug() << " -qws --- start in Qt for Embedded Linux server mode."
4043
<< "Exactly one GUI application needs to be run as server at a time. trikGui generally"
4144
<< "shall use this parameter, as in many cases it is the only GUI application on robot.";
4245
qDebug() << " -c --- path to a directory where all configs for TRIK runtime are stored. Config files are"
4346
<< "config.xml (configuration of robot hardware for trikControl library) and wpa-config.xml"
4447
<< "(configuration of known WiFi networks). Default value for this parameter is current directory."
45-
<< "Example: ./trikGui -qws -c /home/root/";
48+
<< "Example: ./trikGui -qws -c /home/root/trik/";
49+
qDebug() << " -d --- path to a directory where images, example scripts and system.js file are stored."
50+
<< "Example: ./trikGui -qws -d /home/root/trik/";
4651
}
4752

4853
int main(int argc, char *argv[])
@@ -84,15 +89,28 @@ int main(int argc, char *argv[])
8489
}
8590
}
8691

92+
QString startDirPath = QDir::currentPath();
93+
if (app.arguments().contains("-d")) {
94+
int const index = app.arguments().indexOf("-d");
95+
if (app.arguments().count() <= index + 1) {
96+
printUsage();
97+
return 1;
98+
}
99+
100+
startDirPath = app.arguments()[index + 1];
101+
}
102+
103+
if (startDirPath.right(1) != "/") {
104+
startDirPath += "/";
105+
}
106+
87107
#ifdef Q_WS_QWS
88108
QWSServer * const server = QWSServer::instance();
89109
if (server) {
90110
server->setCursorVisible(false);
91111
}
92112
#endif
93113

94-
QString startDirPath = QDir::currentPath();
95-
96114
if (QDir::current().exists("scripts")) {
97115
QDir::setCurrent("scripts");
98116
}

trikRun/main.cpp

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
#include <QtCore/qglobal.h>
1616

1717
#if QT_VERSION < QT_VERSION_CHECK(5, 0, 0)
18+
#include <QtGui/QWSServer>
1819
#include <QtGui/QApplication>
1920
#else
2021
#include <QtWidgets/QApplication>
@@ -28,15 +29,15 @@
2829

2930
void printUsage()
3031
{
31-
qDebug() << "Usage: trikRun <QtScript file name> [-c <config file name]>";
32+
qDebug() << "Usage: trikRun <QtScript file name> [-c <config file name] [-d <working directory name>]";
3233
}
3334

3435
int main(int argc, char *argv[])
3536
{
3637
QApplication app(argc, argv);
3738
QStringList const args = app.arguments();
3839

39-
if (args.count() != 2) {
40+
if (args.count() < 2) {
4041
printUsage();
4142
return 1;
4243
}
@@ -57,7 +58,29 @@ int main(int argc, char *argv[])
5758
}
5859
}
5960

60-
trikScriptRunner::TrikScriptRunner runner(configPath, QDir::currentPath());
61+
QString startDirPath = QDir::currentPath();
62+
if (app.arguments().contains("-d")) {
63+
int const index = app.arguments().indexOf("-d");
64+
if (app.arguments().count() <= index + 1) {
65+
printUsage();
66+
return 1;
67+
}
68+
69+
startDirPath = app.arguments()[index + 1];
70+
}
71+
72+
if (startDirPath.right(1) != "/") {
73+
startDirPath += "/";
74+
}
75+
76+
#ifdef Q_WS_QWS
77+
QWSServer * const server = QWSServer::instance();
78+
if (server) {
79+
server->setCursorVisible(false);
80+
}
81+
#endif
82+
83+
trikScriptRunner::TrikScriptRunner runner(configPath, startDirPath);
6184
QObject::connect(&runner, SIGNAL(completed()), &app, SLOT(quit()));
6285
runner.runFromFile(scriptFileName);
6386

trikScriptRunner/src/scriptEngineWorker.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,8 +68,8 @@ void ScriptEngineWorker::run(QString const &script)
6868
QScriptValue brickProxy = mEngine->newQObject(&mBrick);
6969
mEngine->globalObject().setProperty("brick", brickProxy);
7070

71-
if (QFile::exists(mStartDirPath + "/system.js")) {
72-
runAndReportException(FileUtils::readFromFile(mStartDirPath + "/system.js"));
71+
if (QFile::exists(mStartDirPath + "system.js")) {
72+
runAndReportException(FileUtils::readFromFile(mStartDirPath + "system.js"));
7373
}
7474

7575
runAndReportException(script);

trikServer/main.cpp

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
#if QT_VERSION < QT_VERSION_CHECK(5, 0, 0)
1818
#include <QtGui/QApplication>
19+
#include <QtGui/QWSServer>
1920
#else
2021
#include <QtWidgets/QApplication>
2122
#endif
@@ -26,6 +27,11 @@
2627

2728
#include <trikCommunicator/trikCommunicator.h>
2829

30+
void printUsage()
31+
{
32+
qDebug() << "Usage: trikServer [-c <config file name] [-d <working directory name>]";
33+
}
34+
2935
int main(int argc, char *argv[])
3036
{
3137
int const port = 8888;
@@ -36,7 +42,7 @@ int main(int argc, char *argv[])
3642
if (app.arguments().contains("-c")) {
3743
int const index = app.arguments().indexOf("-c");
3844
if (app.arguments().count() <= index + 1) {
39-
qDebug() << "Usage: ./trikServer [-c <config file path>]";
45+
printUsage();
4046
return 1;
4147
}
4248

@@ -46,9 +52,31 @@ int main(int argc, char *argv[])
4652
}
4753
}
4854

55+
QString startDirPath = QDir::currentPath();
56+
if (app.arguments().contains("-d")) {
57+
int const index = app.arguments().indexOf("-d");
58+
if (app.arguments().count() <= index + 1) {
59+
printUsage();
60+
return 1;
61+
}
62+
63+
startDirPath = app.arguments()[index + 1];
64+
}
65+
66+
if (startDirPath.right(1) != "/") {
67+
startDirPath += "/";
68+
}
69+
70+
#ifdef Q_WS_QWS
71+
QWSServer * const server = QWSServer::instance();
72+
if (server) {
73+
server->setCursorVisible(false);
74+
}
75+
#endif
76+
4977
qDebug() << "Running TrikServer on port" << port;
5078

51-
trikCommunicator::TrikCommunicator communicator(configPath, QDir::currentPath());
79+
trikCommunicator::TrikCommunicator communicator(configPath, startDirPath);
5280
communicator.startServer(port);
5381

5482
return app.exec();

0 commit comments

Comments
 (0)