Commit 9509cd12 authored by Emmanuel Promayon's avatar Emmanuel Promayon
Browse files

FIXED do not crash if there is no testdata dir

parent 0be5e57b
...@@ -277,7 +277,7 @@ const QString Core::getConfig() { ...@@ -277,7 +277,7 @@ const QString Core::getConfig() {
} }
// ------------- getInstallDirectories (static) ----------------- // ------------- getInstallDirectories (static) -----------------
const QStringList Core::getInstallDirectories(QString suffix) { const QStringList Core::getInstallDirectories(QString suffix, bool exitOnError) {
QStringList dir; QStringList dir;
// find the build directory according to the current directory // find the build directory according to the current directory
...@@ -298,8 +298,9 @@ const QStringList Core::getInstallDirectories(QString suffix) { ...@@ -298,8 +298,9 @@ const QStringList Core::getInstallDirectories(QString suffix) {
dir.append(globalInstallDir.canonicalPath().toUtf8()); dir.append(globalInstallDir.canonicalPath().toUtf8());
} }
if (dir.empty()) { if (dir.empty() && exitOnError) {
QString msg = QObject::tr("Installation directory not found: no extensions can be found. Exiting. If you did not install CamiTK, you should at least set your current working directory to CamiTK Community Edition build dir. Note: the current working directory is %1").arg(getCurrentWorkingDir()); QString ext=QFileInfo(suffix).completeBaseName();
QString msg = QObject::tr("Installation directory not found: no %1 extensions can be found. Exiting. If you did not install CamiTK, you should at least set your current working directory to CamiTK Community Edition build dir. Note: the current working directory is %2, looking for %3").arg(ext, getCurrentWorkingDir(), suffix);
qDebug() << msg; // to force show on console qDebug() << msg; // to force show on console
CAMITK_ERROR_ALT(msg); CAMITK_ERROR_ALT(msg);
throw AbortException(msg.toStdString()); throw AbortException(msg.toStdString());
...@@ -335,7 +336,8 @@ const QStringList Core::getViewerDirectories() { ...@@ -335,7 +336,8 @@ const QStringList Core::getViewerDirectories() {
// ------------- getTestDataDir (static) ----------------- // ------------- getTestDataDir (static) -----------------
const QString Core::getTestDataDir() { const QString Core::getTestDataDir() {
QStringList testDataDirectories = getInstallDirectories("share/" + QString(Core::shortVersion) + "/testdata"); // check the testdata installation directory (but do not exit if it does not exist)
QStringList testDataDirectories = getInstallDirectories("share/" + QString(Core::shortVersion) + "/testdata", false);
// just returns the first one if exists // just returns the first one if exists
if (testDataDirectories.size() > 0) { if (testDataDirectories.size() > 0) {
return testDataDirectories.at(0); return testDataDirectories.at(0);
......
...@@ -120,8 +120,13 @@ public: ...@@ -120,8 +120,13 @@ public:
* 3. CamiTK SDK installation directory (global install tree) * 3. CamiTK SDK installation directory (global install tree)
* *
* It uses getExtensionDirectories() to take multiarch into account * It uses getExtensionDirectories() to take multiarch into account
*
* If no directory is available and exitOnError is true, the application exits.
* There are situation (namely for checking testdata dir) where it not mandatory
* to find a directory. In this case, exitOnError should be set to false so that
* the application does not exit.
*/ */
static const QStringList getInstallDirectories(QString suffix); static const QStringList getInstallDirectories(QString suffix, bool exitOnError = true);
/// get more information about installation, etc... /// get more information about installation, etc...
static const QString getConfig(); static const QString getConfig();
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment