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; }
// // Step 3 // Check if directories are exists and // create root directories if needed // bool InstallWindow::Step3PrepareDirs() { PrintStep(tr("Prepare directories")); QSettings settings(ORGANIZATION_NAME, APPLICATION_NAME); QString mainName(_game->JsonTitle()); if (mainName.isEmpty()) return Failed(tr("Main property not found in Json: ") + mainName); _game->SetBinPath(settings.value("Main/BinDir", BIN_DIR_ROOT).toString() + QString("/") + mainName); _game->SetDataPath(settings.value("Main/DataDir", DATA_DIR_ROOT).toString() + QString("/") + mainName); QDir dataDir(_game->DataPath()); QDir binDir(_game->BinPath()); if (dataDir.exists()) if (!ConfirmRemoveDir(dataDir.path())) return false; if (binDir.exists()) if (!ConfirmRemoveDir(binDir.path())) return false; if (!dataDir.mkpath(dataDir.path())) return Failed(QString(tr("Can't create directory %1")) .arg(dataDir.path())); if (!binDir.mkpath(binDir.path())) return Failed(QString(tr("Can't create directory %1")) .arg(binDir.path())); PrintOK(); return Step4Unpack(); }
bool VUtils::deleteFile(const QString &p_recycleBinFolderPath, const QString &p_path) { QString binPath = getRecycleBinSubFolderToUse(p_recycleBinFolderPath); QDir binDir(binPath); if (!binDir.exists()) { binDir.mkpath(binPath); if (!binDir.exists()) { return false; } } QString destName = getFileNameWithSequence(binPath, fileNameFromPath(p_path), true); qDebug() << "try to move" << p_path << "to" << binPath << "as" << destName; if (!binDir.rename(p_path, binDir.filePath(destName))) { qWarning() << "fail to move" << p_path << "to" << binDir.filePath(destName); return false; } return true; }
void LegacyUpdate::jarStart() { LegacyInstance *inst = (LegacyInstance *)m_inst; if (!inst->shouldUpdate() || inst->shouldUseCustomBaseJar()) { ModTheJar(); return; } setStatus(tr("Checking for jar updates...")); // Make directories QDir binDir(inst->binDir()); if (!binDir.exists() && !binDir.mkpath(".")) { emitFailed("Failed to create bin folder."); return; } // Build a list of URLs that will need to be downloaded. setStatus(tr("Downloading new minecraft.jar ...")); QString version_id = inst->intendedVersionId(); QString localPath = version_id + "/" + version_id + ".jar"; QString urlstr = "http://" + URLConstants::AWS_DOWNLOAD_VERSIONS + localPath; auto dljob = new NetJob("Minecraft.jar for version " + version_id); auto metacache = MMC->metacache(); auto entry = metacache->resolveEntry("versions", localPath); dljob->addNetAction(CacheDownload::make(QUrl(urlstr), entry)); connect(dljob, SIGNAL(succeeded()), SLOT(jarFinished())); connect(dljob, SIGNAL(failed()), SLOT(jarFailed())); connect(dljob, SIGNAL(progress(qint64, qint64)), SIGNAL(progress(qint64, qint64))); legacyDownloadJob.reset(dljob); legacyDownloadJob->start(); }
QString LegacyInstance::defaultCustomBaseJar() const { return PathCombine(binDir(), "mcbackup.jar"); }
QString LegacyInstance::runnableJar() const { return PathCombine(binDir(), "minecraft.jar"); }
void ccViewer::loadPlugins() { ui.menuPlugins->setEnabled(false); QString appPath = QCoreApplication::applicationDirPath(); QStringList filters; #if defined(Q_OS_MAC) filters << "*.dylib"; // plugins are in the bundle appPath.remove( "MacOS" ); pluginsPath += "Plugins/ccViewerPlugins"; #elif defined(Q_OS_WIN) filters << "*.dll"; //plugins are in bin/plugins appPath += "/plugins"; #elif defined(Q_OS_LINUX) filters << "*.so"; // Plugins are relative to the bin directory where the executable is found QDir binDir( appPath ); if ( binDir.dirName() == "bin" ) { binDir.cdUp(); appPath = (binDir.absolutePath() + "/lib/cloudcompare/plugins"); } else { // Choose a reasonable default to look in appPath = "/usr/lib/cloudcompare/plugins"; } #else #warning Need to specify the plugin path for this OS. #endif tPluginInfoList plugins; ccPlugins::LoadPlugins(plugins, QStringList(appPath), filters); for ( const tPluginInfo &plugin : plugins ) { if (!plugin.object) { assert(false); continue; } assert(plugin.qObject); plugin.qObject->setParent(this); //is this a GL plugin? if (plugin.object->getType() == CC_GL_FILTER_PLUGIN) { QString pluginName = plugin.object->getName(); if (pluginName.isEmpty()) { ccLog::Warning("Plugin has an invalid (empty) name!"); continue; } ccLog::Print(QString("Plugin name: [%1] (GL filter)").arg(pluginName)); //(auto)create action QAction* action = new QAction(pluginName, plugin.qObject); action->setToolTip(plugin.object->getDescription()); action->setIcon(plugin.object->getIcon()); //connect default signal connect(action, SIGNAL(triggered()), this, SLOT(doEnableGLFilter())); ui.menuPlugins->addAction(action); ui.menuPlugins->setEnabled(true); ui.menuPlugins->setVisible(true); } else { //ignored } } }
void wrapInFunction() { //! [0] QDir("/home/user/Documents") QDir("C:/Documents and Settings") //! [0] //! [1] QDir("images/landscape.png") //! [1] //! [2] QDir("Documents/Letters/Applications").dirName() // "Applications" QDir().dirName() // "." //! [2] //! [3] QDir directory("Documents/Letters"); QString path = directory.filePath("contents.txt"); QString absolutePath = directory.absoluteFilePath("contents.txt"); //! [3] //! [4] QDir dir("example"); if (!dir.exists()) qWarning("Cannot find the example directory"); //! [4] //! [5] QDir dir = QDir::root(); // "/" if (!dir.cd("tmp")) { // "/tmp" qWarning("Cannot find the \"/tmp\" directory"); } else { QFile file(dir.filePath("ex1.txt")); // "/tmp/ex1.txt" if (!file.open(QIODevice::ReadWrite)) qWarning("Cannot create the file %s", file.name()); } //! [5] //! [6] QString bin = "/local/bin"; // where /local/bin is a symlink to /usr/bin QDir binDir(bin); QString canonicalBin = binDir.canonicalPath(); // canonicalBin now equals "/usr/bin" QString ls = "/local/bin/ls"; // where ls is the executable "ls" QDir lsDir(ls); QString canonicalLs = lsDir.canonicalPath(); // canonicalLS now equals "/usr/bin/ls". //! [6] //! [7] QDir dir("/home/bob"); QString s; s = dir.relativeFilePath("images/file.jpg"); // s is "images/file.jpg" s = dir.relativeFilePath("/home/mary/file.txt"); // s is "../mary/file.txt" //! [7] //! [8] QDir::setSearchPaths("icons", QStringList(QDir::homePath() + "/images")); QDir::setSearchPaths("docs", QStringList(":/embeddedDocuments")); ... QPixmap pixmap("icons:undo.png"); // will look for undo.png in QDir::homePath() + "/images" QFile file("docs:design.odf"); // will look in the :/embeddedDocuments resource path //! [8] //! [9] QDir dir("/tmp/root_link"); dir = dir.canonicalPath(); if (dir.isRoot()) qWarning("It is a root link"); //! [9] //! [10] // The current directory is "/usr/local" QDir d1("/usr/local/bin"); QDir d2("bin"); if (d1 == d2) qDebug("They're the same"); //! [10] //! [11] // The current directory is "/usr/local" QDir d1("/usr/local/bin"); d1.setFilter(QDir::Executable); QDir d2("bin"); if (d1 != d2) qDebug("They differ"); //! [11] //! [12] C:/Documents and Settings/Username //! [12] //! [13] Q_INIT_RESOURCE(myapp); //! [13] //! [14] inline void initMyResource() { Q_INIT_RESOURCE(myapp); }
int main(int argc, char **argv) { //See http://doc.qt.io/qt-5/qopenglwidget.html#opengl-function-calls-headers-and-qopenglfunctions /** Calling QSurfaceFormat::setDefaultFormat() before constructing the QApplication instance is mandatory on some platforms (for example, OS X) when an OpenGL core profile context is requested. This is to ensure that resource sharing between contexts stays functional as all internal contexts are created using the correct version and profile. **/ { QSurfaceFormat format = QSurfaceFormat::defaultFormat(); format.setSwapBehavior(QSurfaceFormat::DoubleBuffer); format.setOption(QSurfaceFormat::StereoBuffers, true); format.setStencilBufferSize(0); #ifdef CC_GL_WINDOW_USE_QWINDOW format.setStereo(true); #endif #ifdef Q_OS_MAC format.setStereo(false); format.setVersion( 2, 1 ); format.setProfile( QSurfaceFormat::CoreProfile ); #endif #ifdef QT_DEBUG format.setOption(QSurfaceFormat::DebugContext, true); #endif QSurfaceFormat::setDefaultFormat(format); } //The 'AA_ShareOpenGLContexts' attribute must be defined BEFORE the creation of the Q(Gui)Application //DGM: this is mandatory to enable exclusive full screen for ccGLWidget (at least on Windows) QCoreApplication::setAttribute(Qt::AA_ShareOpenGLContexts); //QT initialiation qccApplication app(argc, argv); //Locale management { //Force 'english' locale so as to get a consistent behavior everywhere QLocale locale = QLocale(QLocale::English); locale.setNumberOptions(QLocale::c().numberOptions()); QLocale::setDefault(locale); #ifdef Q_OS_UNIX //We reset the numeric locale for POSIX functions //See http://qt-project.org/doc/qt-5/qcoreapplication.html#locale-settings setlocale(LC_NUMERIC, "C"); #endif } #ifdef USE_VLD VLDEnable(); #endif #ifdef Q_OS_MAC // This makes sure that our "working directory" is not within the application bundle QDir appDir = QCoreApplication::applicationDirPath(); if ( appDir.dirName() == "MacOS" ) { appDir.cdUp(); appDir.cdUp(); appDir.cdUp(); QDir::setCurrent( appDir.absolutePath() ); } #endif //store the log message until a valid logging instance is registered ccLog::EnableMessageBackup(true); //restore some global parameters { QSettings settings; settings.beginGroup(ccPS::GlobalShift()); double maxAbsCoord = settings.value(ccPS::MaxAbsCoord(), ccGlobalShiftManager::MaxCoordinateAbsValue()).toDouble(); double maxAbsDiag = settings.value(ccPS::MaxAbsDiag(), ccGlobalShiftManager::MaxBoundgBoxDiagonal()).toDouble(); settings.endGroup(); ccLog::Print(QString("[Global Shift] Max abs. coord = %1 / max abs. diag = %2").arg(maxAbsCoord, 0, 'e', 0).arg(maxAbsDiag, 0, 'e', 0)); ccGlobalShiftManager::SetMaxCoordinateAbsValue(maxAbsCoord); ccGlobalShiftManager::SetMaxBoundgBoxDiagonal(maxAbsDiag); } //Command line mode? bool commandLine = (argc > 1 && argv[1][0] == '-'); //specific commands int lastArgumentIndex = 1; QTranslator translator; if (commandLine) { //translation file selection if (QString(argv[lastArgumentIndex]).toUpper() == "-LANG") { QString langFilename = QString(argv[2]); //Load translation file if (translator.load(langFilename, QCoreApplication::applicationDirPath())) { qApp->installTranslator(&translator); } else { QMessageBox::warning(0, QObject::tr("Translation"), QObject::tr("Failed to load language file '%1'").arg(langFilename)); } commandLine = false; lastArgumentIndex += 2; } } //splash screen QSplashScreen* splash = 0; QTime splashStartTime; //standard mode if (!commandLine) { if ((QGLFormat::openGLVersionFlags() & QGLFormat::OpenGL_Version_2_1) == 0) { QMessageBox::critical(0, "Error", "This application needs OpenGL 2.1 at least to run!"); return EXIT_FAILURE; } //splash screen splashStartTime.start(); QPixmap pixmap(QString::fromUtf8(":/CC/images/imLogoV2Qt.png")); splash = new QSplashScreen(pixmap, Qt::WindowStaysOnTopHint); splash->show(); QApplication::processEvents(); } //global structures initialization FileIOFilter::InitInternalFilters(); //load all known I/O filters (plugins will come later!) ccNormalVectors::GetUniqueInstance(); //force pre-computed normals array initialization ccColorScalesManager::GetUniqueInstance(); //force pre-computed color tables initialization //load the plugins tPluginInfoList plugins; QStringList dirFilters; QStringList pluginPaths; { QString appPath = QCoreApplication::applicationDirPath(); #if defined(Q_OS_MAC) dirFilters << "*.dylib"; // plugins are in the bundle appPath.remove("MacOS"); pluginPaths += (appPath + "Plugins/ccPlugins"); #if defined(CC_MAC_DEV_PATHS) // used for development only - this is the path where the plugins are built // this avoids having to install into the application bundle when developing pluginPaths += (appPath + "../../../ccPlugins"); #endif #elif defined(Q_OS_WIN) dirFilters << "*.dll"; //plugins are in bin/plugins pluginPaths << (appPath + "/plugins"); #elif defined(Q_OS_LINUX) dirFilters << "*.so"; // Plugins are relative to the bin directory where the executable is found QDir binDir(appPath); if (binDir.dirName() == "bin") { binDir.cdUp(); pluginPaths << (binDir.absolutePath() + "/lib/cloudcompare/plugins"); } else { // Choose a reasonable default to look in pluginPaths << "/usr/lib/cloudcompare/plugins"; } #else #warning Need to specify the plugin path for this OS. #endif #ifdef Q_OS_MAC // Add any app data paths // Plugins in these directories take precendence over the included ones QStringList appDataPaths = QStandardPaths::standardLocations(QStandardPaths::AppDataLocation); for (const QString &appDataPath : appDataPaths) { pluginPaths << (appDataPath + "/plugins"); } #endif } ccPlugins::LoadPlugins(plugins, pluginPaths, dirFilters); int result = 0; //command line mode if (commandLine) { //command line processing (no GUI) result = ccCommandLineParser::Parse(argc, argv); } else { //main window init. MainWindow* mainWindow = MainWindow::TheInstance(); if (!mainWindow) { QMessageBox::critical(0, "Error", "Failed to initialize the main application window?!"); return EXIT_FAILURE; } mainWindow->dispatchPlugins(plugins, pluginPaths); mainWindow->show(); QApplication::processEvents(); //show current Global Shift parameters in Console { ccLog::Print(QString("[Global Shift] Max abs. coord = %1 / max abs. diag = %2") .arg(ccGlobalShiftManager::MaxCoordinateAbsValue(), 0, 'e', 0) .arg(ccGlobalShiftManager::MaxBoundgBoxDiagonal(), 0, 'e', 0)); } if (argc > lastArgumentIndex) { if (splash) splash->close(); //any additional argument is assumed to be a filename --> we try to load it/them QStringList filenames; for (int i = lastArgumentIndex; i < argc; ++i) { QString arg(argv[i]); //special command: auto start a plugin if (arg.startsWith(":start-plugin:")) { QString pluginName = arg.mid(14); QString pluginNameUpper = pluginName.toUpper(); //look for this plugin bool found = false; for (const tPluginInfo &plugin : plugins) { if (plugin.object->getName().replace(' ', '_').toUpper() == pluginNameUpper) { found = true; bool success = plugin.object->start(); if (!success) { ccLog::Error(QString("Failed to start the plugin '%1'").arg(plugin.object->getName())); } break; } } if (!found) { ccLog::Error(QString("Couldn't find the plugin '%1'").arg(pluginName.replace('_', ' '))); } } else { filenames << arg; } } mainWindow->addToDB(filenames); } if (splash) { //we want the splash screen to be visible a minimum amount of time (1000 ms.) while (splashStartTime.elapsed() < 1000) { splash->raise(); QApplication::processEvents(); //to let the system breath! } splash->close(); QApplication::processEvents(); delete splash; splash = 0; } //let's rock! try { result = app.exec(); } catch (...) { QMessageBox::warning(0, "CC crashed!", "Hum, it seems that CC has crashed... Sorry about that :)"); } //release the plugins for (tPluginInfo &plugin : plugins) { plugin.object->stop(); //just in case if (!plugin.qObject->parent()) { delete plugin.object; plugin.object = 0; plugin.qObject = 0; } } } //release global structures MainWindow::DestroyInstance(); FileIOFilter::UnregisterAll(); #ifdef CC_TRACK_ALIVE_SHARED_OBJECTS //for debug purposes unsigned alive = CCShareable::GetAliveCount(); if (alive > 1) { printf("Error: some shared objects (%u) have not been released on program end!",alive); system("PAUSE"); } #endif return result; }