Esempio n. 1
0
	KeziaResourceManager::KeziaResourceManager(ResourceManagerMode mode)
		:	m_Mode(mode),
			m_PreferredResourceManager(nullptr),
			m_SecondaryResourceManager(nullptr)
	{
		char tmp[255];
		GetCurrentDirectoryA(255, tmp);
		std::string currentDirectory(tmp);

		switch(m_Mode)
		{
		case PreferData:
			m_SecondaryResourceManager = new zlib_ResourceManager();
			m_SecondaryResourceManager->AddSourceDirectory(currentDirectory + "\\Data.zip");
		case DataOnly:
			m_PreferredResourceManager = new Windows_ResourceManager();
			m_PreferredResourceManager->AddSourceDirectory(currentDirectory + "\\Data");
			break;

		case PreferArchive:
			m_SecondaryResourceManager = new Windows_ResourceManager();
			m_SecondaryResourceManager->AddSourceDirectory(currentDirectory + "\\Data");
		case ArchiveOnly:
			m_PreferredResourceManager = new zlib_ResourceManager();
			m_PreferredResourceManager->AddSourceDirectory(currentDirectory + "\\Data.zip");
			break;
		}
	}
Esempio n. 2
0
/*!
  \internal

  Use this to replace all occurences of '*' with directory candidates (if applicable).

  This method will not work correctly when date tags are still present in path.
  You should run getOutputFilePath() first.

  \sa getOutputFilePath
 */
QString SpdrImportPrivate::substituteStarsInPath(const QString &outputFilePath) const
{
    Q_Q(const SpdrImport);

    QChar star('*');
    if (!outputFilePath.contains(star)) {
        return outputFilePath;
    }

    QStringList outputPathSegments(outputFilePath.split(mPathSeparatorRegularExpression,
                                                        QString::KeepEmptyParts));

    // Go through every segment, see if dir exists, see if there is a name match,
    // fix the segment.
    QString pathBuilder;
    foreach(const QString &segment, outputPathSegments) {
        if (!pathBuilder.isEmpty()) {
            pathBuilder.append("/");
        }
//        else if (pathBuilder.isEmpty() && q->outputPath().startsWith('/')) {
//            pathBuilder.append("/");
//        }

        // Get existing directory names, look for a candidate
        if (segment.contains(star)) {
            QDir currentDirectory(pathBuilder);
            QFileInfoList dirs(currentDirectory.entryInfoList(QDir::Dirs | QDir::NoDotAndDotDot));

            QString regExpString(segment); // "*" + dirName + "*"
            QRegularExpression regExp(regExpString);
            q->log(QCoreApplication::translate("SpdrImportPrivate", "Star matching regular expression set to: %1").arg(regExpString), Spdr::Debug);

            bool found = false;
            foreach (const QFileInfo &dirInfo, dirs) {
                QString dirName(dirInfo.fileName());

                if (regExp.match(dirName).hasMatch()) {
                    pathBuilder.append(dirName);
                    found = true;
                    q->log(QCoreApplication::translate("SpdrImportPrivate", "An existing directory that matches wildcard has been found: %1")
                           .arg(dirName), Spdr::ExcessiveLogging);
                    break;
                }
            }

            if (!found) {
                QString plainDir(segment);
                pathBuilder.append(plainDir.remove('*'));
            }
        } else {
Esempio n. 3
0
void Game::NewGame() {
    // Create a file name for saving
    auto t = time(nullptr);
    auto tm = *localtime(&t);
    std::stringstream ss;
    ss << std::put_time(&tm, "%d-%m-%Y-%m-%d_%H-%M-%S");
    string saveDirectory = "Resources/saved games";
    QDir currentDirectory(".");
    currentDirectory.mkdir(saveDirectory.c_str());
    this->savedFileName = currentDirectory.absolutePath().toStdString() +
        "/" + saveDirectory + "/PG-" + ss.str() + ".xml";
    
    // New game message
    cout << "New game selected" << endl;

    // Initialize components
    fullTurn = 1;
    phase = 0;
    playStep = 1;

    // Load the config to have the maps
    GameStatus::GetInstance().Init(this, "", CONFIG_FILE_PATH);
}
void FolderNavigationWidget::contextMenuEvent(QContextMenuEvent *ev)
{
    QMenu menu;
    // Open current item
    const QModelIndex current = currentItem();
    const bool hasCurrentItem = current.isValid();
    QAction *actionOpen = menu.addAction(actionOpenText(m_fileSystemModel, current));
    actionOpen->setEnabled(hasCurrentItem);

    // JULIA STUDIO -------
    QAction* actionJuliaRun = menu.addAction(tr("Run this file"));
    actionJuliaRun->setEnabled( hasCurrentItem && !m_fileSystemModel->isDir(current) );
    // -------

    // Explorer & teminal
    QAction *actionExplorer = menu.addAction(Core::FileUtils::msgGraphicalShellAction());
    actionExplorer->setEnabled(hasCurrentItem);
    QAction *actionTerminal = menu.addAction(Core::FileUtils::msgTerminalAction());
    actionTerminal->setEnabled(hasCurrentItem);

    QAction *actionFind = menu.addAction(msgFindOnFileSystem());
    actionFind->setEnabled(hasCurrentItem);
    // open with...
    if (!m_fileSystemModel->isDir(current)) {
        QMenu *openWith = menu.addMenu(tr("Open with"));
        Core::DocumentManager::populateOpenWithMenu(openWith,
                                                m_fileSystemModel->filePath(current));
    }

    // Open file dialog to choose a path starting from current
    QAction *actionChooseFolder = menu.addAction(tr("Choose Folder..."));

    QAction *action = menu.exec(ev->globalPos());
    if (!action)
        return;

    ev->accept();
    if (action == actionOpen) { // Handle open file.
        openItem(current);
        return;
    }
    if (action == actionChooseFolder) { // Open file dialog
        const QString newPath = QFileDialog::getExistingDirectory(this, tr("Choose Folder"), currentDirectory());
        if (!newPath.isEmpty())
            setCurrentDirectory(newPath);
        return;
    }
    if (action == actionTerminal) {
        Core::FileUtils::openTerminal(m_fileSystemModel->filePath(current));
        return;
    }
    if (action == actionExplorer) {
        Core::FileUtils::showInGraphicalShell(this, m_fileSystemModel->filePath(current));
        return;
    }
    if (action == actionFind) {
        QFileInfo info = m_fileSystemModel->fileInfo(current);
        if (m_fileSystemModel->isDir(current))
            findOnFileSystem(info.absoluteFilePath());
        else
            findOnFileSystem(info.absolutePath());
        return;
    }
    // JULIA STUDIO -------
    if (action == actionJuliaRun) {
      QFileInfo file_info = m_fileSystemModel->fileInfo(current);
      IEvaluator* evaluator = findEvaluatorFor( file_info.suffix() );

      evaluator->eval( &file_info );

      return;
    }
    // -------

    Core::DocumentManager::executeOpenWithMenuAction(action);
}
void FolderNavigationWidget::contextMenuEvent(QContextMenuEvent *ev)
{
    QMenu menu;
    // Open current item
    const QModelIndex current = currentItem();
    const bool hasCurrentItem = current.isValid();
    QAction *actionOpen = menu.addAction(actionOpenText(m_fileSystemModel, current));
    actionOpen->setEnabled(hasCurrentItem);
    // Explorer & teminal
    QAction *actionExplorer = menu.addAction(Core::FileUtils::msgGraphicalShellAction());
    actionExplorer->setEnabled(hasCurrentItem);
    QAction *actionTerminal = menu.addAction(Core::FileUtils::msgTerminalAction());
    actionTerminal->setEnabled(hasCurrentItem);

    QAction *actionFind = menu.addAction(Core::FileUtils::msgFindInDirectory());
    actionFind->setEnabled(hasCurrentItem);
    // open with...
    if (!m_fileSystemModel->isDir(current)) {
        QMenu *openWith = menu.addMenu(tr("Open with"));
        Core::DocumentManager::populateOpenWithMenu(openWith,
                                                m_fileSystemModel->filePath(current));
    }

    // Open file dialog to choose a path starting from current
    QAction *actionChooseFolder = menu.addAction(tr("Choose Folder..."));

    QAction *action = menu.exec(ev->globalPos());
    if (!action)
        return;

    ev->accept();
    if (action == actionOpen) { // Handle open file.
        openItem(current);
        return;
    }
    if (action == actionChooseFolder) { // Open file dialog
        const QString newPath = QFileDialog::getExistingDirectory(this, tr("Choose Folder"), currentDirectory());
        if (!newPath.isEmpty())
            setCurrentDirectory(newPath);
        return;
    }
    if (action == actionTerminal) {
        Core::FileUtils::openTerminal(m_fileSystemModel->filePath(current));
        return;
    }
    if (action == actionExplorer) {
        Core::FileUtils::showInGraphicalShell(this, m_fileSystemModel->filePath(current));
        return;
    }
    if (action == actionFind) {
        TextEditor::FindInFiles::findOnFileSystem(m_fileSystemModel->filePath(current));
        return;
    }
    Core::DocumentManager::executeOpenWithMenuAction(action);
}
Esempio n. 6
0
DynamicLib::DynamicLib(const boost::filesystem::path& path) :
    m_name(path),
    m_handle(0)
{

    std::string actualDllName = path.string();
    //std::string::size_type pos = actualDllName.find_last_of(".");

    boost::filesystem::path realPath(actualDllName, boost::filesystem::native);

    boost::filesystem::path currentDirectory(boost::filesystem::initial_path());

    std::string fullPath = boost::filesystem::system_complete(realPath).string();

#ifdef WIN32
    // First, try to get the handle without loading the library.
    // If we can get a handle then it is already loaded.
    HMODULE mod = GetModuleHandle(fullPath.c_str());
    if( mod )
    {
        //std::string error = std::string("ERROR: Plugin ") +
        //    std::string(fullPath.c_str()) + std::string(" is already loaded.");
        //throw UnableToLoadDynamicLibException(error);
        m_handle = mod;
        return;
    }

    m_handle = LoadLibrary(fullPath.c_str());
    if( !m_handle )
    {
        std::stringstream str;
        str << "ERROR loading dll " << fullPath << " ";
        switch(GetLastError())
        {
        case ERROR_MOD_NOT_FOUND:
            str << "The specified DLL could not be found ";
            str << "(" << (long)ERROR_MOD_NOT_FOUND << ").";
            str << "A common reason for this is if the plugin has an implicit ";
            str << "DLL requirement that can't be found.";
            break;

        case ERROR_INVALID_MODULETYPE:
            str << "The operating system cannot run the specified module ";
            str << "(" << (long)ERROR_INVALID_MODULETYPE << ").";
            break;

        case ERROR_TOO_MANY_MODULES:
            str << "Too many dynamic-link modules are attached to this program or dynamic-link module ";
            str << "(" << (long)ERROR_TOO_MANY_MODULES << ").";
            break;

        case ERROR_DLL_INIT_FAILED:
            str << "Dynamic link library (DLL) initialization routine failed ";
            str << "(" << (long)ERROR_DLL_INIT_FAILED << ").";
            break;

        case ERROR_DLL_NOT_FOUND:
            str << "The library file cannot be found ";
            str << "(" << (long)ERROR_DLL_NOT_FOUND << ").";
            break;

        case ERROR_INVALID_DLL:
            str << "The library file is damaged ";
            str << "(" << (long)ERROR_INVALID_DLL << ").";
            break;

        default:
            str << "\tERROR NUMBER = " << GetLastError();
            break;
        }
        throw UnableToLoadDynamicLibException(str.str());
    }
#else

    m_handle = dlopen(actualDllName.c_str(), RTLD_LAZY | RTLD_GLOBAL);
    if( !m_handle )
    {
        cerr << dlerror() << endl;
        throw std::runtime_error("Can't load.");
    }

#endif

}
void FolderNavigationWidget::contextMenuEvent(QContextMenuEvent *ev)
{
    QMenu menu;
    // Open current item
    const QModelIndex current = currentItem();
    const bool hasCurrentItem = current.isValid();
    QAction *actionOpen = menu.addAction(actionOpenText(m_fileSystemModel, current));
    actionOpen->setEnabled(hasCurrentItem);

    // we need dummy DocumentModel::Entry with absolute file path in it
    // to get EditorManager::addNativeDirAndOpenWithActions() working
    Core::DocumentModel::Entry fakeEntry;
    Core::IDocument document;
    document.setFilePath(Utils::FileName::fromString(m_fileSystemModel->filePath(current)));
    fakeEntry.document = &document;
    Core::EditorManager::addNativeDirAndOpenWithActions(&menu, &fakeEntry);

    const bool isDirectory = hasCurrentItem && m_fileSystemModel->isDir(current);
    QAction *actionOpenDirectoryAsProject = 0;
    if (isDirectory && m_fileSystemModel->fileName(current) != QLatin1String("..")) {
        actionOpenDirectoryAsProject =
            menu.addAction(tr("Open Project in \"%1\"")
                           .arg(m_fileSystemModel->fileName(current)));
    }

    // Open file dialog to choose a path starting from current
    QAction *actionChooseFolder = menu.addAction(tr("Choose Folder..."));

    QAction *action = menu.exec(ev->globalPos());
    if (!action)
        return;

    ev->accept();
    if (action == actionOpen) { // Handle open file.
        openItem(current);
    } else if (action == actionOpenDirectoryAsProject) {
        openItem(current, true);
    } else if (action == actionChooseFolder) { // Open file dialog
        const QString newPath = QFileDialog::getExistingDirectory(this, tr("Choose Folder"), currentDirectory());
        if (!newPath.isEmpty())
            setCurrentDirectory(newPath);
    }
}