void StelFileMgr::init() { // Set the userDir member. #ifdef Q_OS_WIN QString winApiPath = getWin32SpecialDirPath(CSIDL_APPDATA); if (!winApiPath.isEmpty()) { userDir = winApiPath + "\\Stellarium"; } #elif defined(Q_OS_MAC) userDir = QDir::homePath() + "/Library/Application Support/Stellarium"; #else userDir = QDir::homePath() + "/.stellarium"; #endif #if QT_VERSION >= 0x050A00 if (qEnvironmentVariableIsSet("STEL_USERDIR")) { userDir=qEnvironmentVariable("STEL_USERDIR"); } #else QByteArray userDirCand=qgetenv("STEL_USERDIR"); if (userDirCand.length()>0) { userDir=QString::fromLocal8Bit(userDirCand); } #endif if (!QFile(userDir).exists()) { qWarning() << "User config directory does not exist: " << QDir::toNativeSeparators(userDir); } try { makeSureDirExistsAndIsWritable(userDir); } catch (std::runtime_error &e) { qFatal("Error: cannot create user config directory: %s", e.what()); } // OK, now we have the userDir set, add it to the search path fileLocations.append(userDir); // Determine install data directory location QProcessEnvironment env = QProcessEnvironment::systemEnvironment(); QString envRoot = env.value("STELLARIUM_DATA_ROOT", "."); if (QFileInfo(envRoot + QDir::separator() + QString(CHECK_FILE)).exists()) { installDir = envRoot; } else { #if defined(Q_OS_MAC) QString relativePath = "/../Resources"; if (QCoreApplication::applicationDirPath().contains("src")) { relativePath = "/../.."; } QFileInfo MacOSdir(QCoreApplication::applicationDirPath() + relativePath); // These two lines are used to see if the Qt bug still exists. // The output from C: should simply be the parent of what is show for B: // qDebug() << "B: " << MacOSdir.absolutePath(); // qDebug() << "C: " << MacOSdir.dir().absolutePath(); QDir ResourcesDir(MacOSdir.absolutePath()); if (!QCoreApplication::applicationDirPath().contains("src")) { ResourcesDir.cd(QString("Resources")); } QFileInfo installLocation(ResourcesDir.absolutePath()); QFileInfo checkFile(installLocation.filePath() + QDir::separator() + QString(CHECK_FILE)); #elif defined(Q_OS_WIN) QFileInfo installLocation(QCoreApplication::applicationDirPath()); QFileInfo checkFile(installLocation.filePath() + QDir::separator() + QString(CHECK_FILE)); #else // Linux, BSD, Solaris etc. // We use the value from the config.h filesystem QFileInfo installLocation(QFile::decodeName(INSTALL_DATADIR)); QFileInfo checkFile(QFile::decodeName(INSTALL_DATADIR "/" CHECK_FILE)); #endif #ifdef DEBUG if (!checkFile.exists()) { // for DEBUG use sources location QString debugDataPath = INSTALL_DATADIR_FOR_DEBUG; checkFile = QFileInfo(debugDataPath + QDir::separator() + CHECK_FILE); installLocation = QFileInfo(debugDataPath); } #endif if (checkFile.exists()) { installDir = installLocation.filePath(); } else { qWarning() << "WARNING StelFileMgr::StelFileMgr: could not find install location:" << QDir::toNativeSeparators(installLocation.filePath()) << " (we checked for " << QDir::toNativeSeparators(checkFile.filePath()) << ")."; qWarning() << "Maybe this is AppImage or something similar? Let's check relative path..."; // This hook has been added after reverse-engineering an AppImage application QString relativePath = QCoreApplication::applicationDirPath() + QString("/../share/stellarium"); checkFile = QFileInfo(relativePath + QDir::separator() + CHECK_FILE); if (checkFile.exists()) { installDir = relativePath; } else { qWarning() << "WARNING StelFileMgr::StelFileMgr: could not find install location:" << QDir::toNativeSeparators(relativePath) << " (we checked for " << QDir::toNativeSeparators(checkFile.filePath()) << ")."; qWarning() << "Maybe this is development environment? Let's check source directory path..."; QString sourceDirPath = STELLARIUM_SOURCE_DIR; // The variable is defined in CMakeLists.txt file checkFile = QFileInfo(sourceDirPath + QDir::separator() + CHECK_FILE); if (checkFile.exists()) { installDir = sourceDirPath; } else { qWarning() << "WARNING StelFileMgr::StelFileMgr: could not find install location:" << QDir::toNativeSeparators(sourceDirPath) << " (we checked for " << QDir::toNativeSeparators(checkFile.filePath()) << ")."; #ifndef UNIT_TEST // NOTE: Hook for buildbots (using within testEphemeris) qFatal("Couldn't find install directory location."); #endif } } } } // Then add the installation directory to the search path fileLocations.append(installDir); }
void OSApi::ExecuteInstallerSilently(const QString& filename) { //http://stackoverflow.com/questions/21428208/how-to-silently-install-dmg-file-in-mac-os-x-system-using-shell-script QProcess::startDetached(ResourcesDir() + "install_app.sh", filename); }