! * \brief getCustomPaths * Returns a tuple of path names where to store config, data and temp. files. * The method therefore reads the environment variables: * \list * \li FREECAD_USER_HOME * \li FREECAD_USER_DATA * \li FREECAD_USER_TEMP * \endlist */
| 3469 | * \endlist |
| 3470 | */ |
| 3471 | std::tuple<QString, QString, QString> getCustomPaths() |
| 3472 | { |
| 3473 | const QProcessEnvironment env(QProcessEnvironment::systemEnvironment()); |
| 3474 | QString userHome = env.value(QStringLiteral("FREECAD_USER_HOME")); |
| 3475 | QString userData = env.value(QStringLiteral("FREECAD_USER_DATA")); |
| 3476 | QString userTemp = env.value(QStringLiteral("FREECAD_USER_TEMP")); |
| 3477 | |
| 3478 | auto toNativePath = [](QString& path) { |
| 3479 | if (!path.isEmpty()) { |
| 3480 | const QDir dir(path); |
| 3481 | if (dir.exists()) |
| 3482 | path = QDir::toNativeSeparators(dir.canonicalPath()); |
| 3483 | else |
| 3484 | path.clear(); |
| 3485 | } |
| 3486 | }; |
| 3487 | |
| 3488 | // verify env. variables |
| 3489 | toNativePath(userHome); |
| 3490 | toNativePath(userData); |
| 3491 | toNativePath(userTemp); |
| 3492 | |
| 3493 | // if FREECAD_USER_HOME is set but not FREECAD_USER_DATA |
| 3494 | if (!userHome.isEmpty() && userData.isEmpty()) { |
| 3495 | userData = userHome; |
| 3496 | } |
| 3497 | |
| 3498 | // if FREECAD_USER_HOME is set but not FREECAD_USER_TEMP |
| 3499 | if (!userHome.isEmpty() && userTemp.isEmpty()) { |
| 3500 | const QDir dir(userHome); |
| 3501 | dir.mkdir(QStringLiteral("temp")); |
| 3502 | const QFileInfo fi(dir, QStringLiteral("temp")); |
| 3503 | userTemp = fi.absoluteFilePath(); |
| 3504 | } |
| 3505 | |
| 3506 | return {userHome, userData, userTemp}; |
| 3507 | } |
| 3508 | |
| 3509 | /*! |
| 3510 | * \brief getStandardPaths |
no test coverage detected