std::string getWZInstallPrefix() { const std::string dirSeparator(PHYSFS_getDirSeparator()); ASSERT(dirSeparator.length() > 0, "PHYSFS_getDirSeparator returned an empty string"); // Construct the install PREFIX path std::string prefixDir(PHYSFS_getBaseDir()); while (!prefixDir.empty() && (prefixDir.rfind(dirSeparator, std::string::npos) == (prefixDir.length() - dirSeparator.length()))) { prefixDir.resize(prefixDir.length() - dirSeparator.length()); // Remove trailing path separators } size_t binDirComponentsCount = 1; #ifdef WZ_BINDIR // Trim off as many path components as are in WZ_BINDIR std::string binDir(WZ_BINDIR); std::vector<std::string> binDirComponents = splitAtAnyDelimiter(binDir, "/"); binDirComponentsCount = std::count_if(binDirComponents.begin(), binDirComponents.end(), [](const std::string &s) { return !s.empty() && (s != "."); }); ASSERT(binDirComponentsCount > 0, "WZ_BINDIR unexpectedly has zero components?: \"%s\"", WZ_BINDIR); #endif for (size_t i = 0; i < binDirComponentsCount; ++i) { size_t lastSlash = prefixDir.rfind(dirSeparator, std::string::npos); if (lastSlash != std::string::npos) { prefixDir = prefixDir.substr(0, lastSlash); // Trim off the last path component } } return prefixDir; }
/****************************************************************************** * Returns the list of directories containing the Ovito plugins. ******************************************************************************/ QList<QDir> PluginManager::pluginDirs() { QDir prefixDir(QCoreApplication::applicationDirPath()); #if defined(Q_OS_WIN) || defined(Q_OS_MAC) return { QDir(prefixDir.absolutePath() + QStringLiteral("/plugins")) }; #else prefixDir.cdUp(); return { QDir(prefixDir.absolutePath() + QStringLiteral("/lib/ovito/plugins")) }; #endif }
/****************************************************************************** * Shows the online manual and opens the given help page. ******************************************************************************/ void MainWindow::openHelpTopic(const QString& page) { QDir prefixDir(QCoreApplication::applicationDirPath()); #if defined(Q_OS_WIN) QDir helpDir = QDir(prefixDir.absolutePath() + "/doc/manual/html/"); #elif defined(Q_OS_MAC) prefixDir.cdUp(); QDir helpDir = QDir(prefixDir.absolutePath() + "/Resources/doc/manual/html/"); #else prefixDir.cdUp(); QDir helpDir = QDir(prefixDir.absolutePath() + "/share/ovito/doc/manual/html/"); #endif // Use the web browser to display online help. QString fullPath = helpDir.absoluteFilePath(page.isEmpty() ? QStringLiteral("index.html") : page); if(!QDesktopServices::openUrl(QUrl::fromLocalFile(fullPath))) { Exception(tr("Could not launch web browser to display online manual. The requested file path is %1").arg(fullPath)).showError(); } }