コード例 #1
0
void ConfigurationManager::processPaths(Files::PathContainer& dataDirs, bool create)
{
    std::string path;
    for (Files::PathContainer::iterator it = dataDirs.begin(); it != dataDirs.end(); ++it)
    {
        path = it->string();
        boost::erase_all(path, "\"");
        *it = boost::filesystem::path(path);

        // Check if path contains a token
        if (!path.empty() && *path.begin() == '?')
        {
            std::string::size_type pos = path.find('?', 1);
            if (pos != std::string::npos && pos != 0)
            {
                TokensMappingContainer::iterator tokenIt = mTokensMapping.find(path.substr(0, pos + 1));
                if (tokenIt != mTokensMapping.end())
                {
                    boost::filesystem::path tempPath(((mFixedPath).*(tokenIt->second))());
                    if (pos < path.length() - 1)
                    {
                        // There is something after the token, so we should
                        // append it to the path
                        tempPath /= path.substr(pos + 1, path.length() - pos);
                    }

                    *it = tempPath;
                }
                else
                {
                    // Clean invalid / unknown token, it will be removed outside the loop
                    (*it).clear();
                }
            }
        }

        if (!boost::filesystem::is_directory(*it))
        {
            if (create)
            {
                try
                {
                    boost::filesystem::create_directories (*it);
                }
                catch (...) {}

                if (boost::filesystem::is_directory(*it))
                    continue;
            }

            (*it).clear();
        }
    }

    dataDirs.erase(std::remove_if(dataDirs.begin(), dataDirs.end(),
        boost::bind(&boost::filesystem::path::empty, _1)), dataDirs.end());
}
コード例 #2
0
ファイル: multidircollection.cpp プロジェクト: 0xmono/openmw
    MultiDirCollection::MultiDirCollection(const Files::PathContainer& directories,
        const std::string& extension, bool foldCase)
    : mFiles (NameLess (!foldCase))
    {
        NameEqual equal (!foldCase);

        for (PathContainer::const_iterator iter = directories.begin();
            iter!=directories.end(); ++iter)
        {
            if (!boost::filesystem::is_directory(*iter))
            {
                std::cout << "Skipping invalid directory: " << (*iter).string() << std::endl;
                continue;
            }

            for (boost::filesystem::directory_iterator dirIter(*iter);
                    dirIter != boost::filesystem::directory_iterator(); ++dirIter)
            {
                boost::filesystem::path path = *dirIter;

                if (!equal (extension, path.extension().string()))
                    continue;

                std::string filename = path.filename().string();

                TIter result = mFiles.find (filename);

                if (result==mFiles.end())
                {
                    mFiles.insert (std::make_pair (filename, path));
                }
                else if (result->first==filename)
                {
                    mFiles[filename] = path;
                }
                else
                {
                    // handle case folding
                    mFiles.erase (result->first);
                    mFiles.insert (std::make_pair (filename, path));
                }
            }
        }
    }
コード例 #3
0
ファイル: datafileslist.cpp プロジェクト: dougmencken/openmw
bool DataFilesList::setupDataFiles(Files::PathContainer dataDirs, const QString encoding)
{
    // Set the charset for reading the esm/esp files
    if (!encoding.isEmpty() && encoding != QLatin1String("win1252")) {
        mMastersModel->setEncoding(encoding);
        mPluginsModel->setEncoding(encoding);
    }

    // Add the paths to the respective models
    for (Files::PathContainer::iterator it = dataDirs.begin(); it != dataDirs.end(); ++it) {
        QString path = QString::fromStdString(it->string());
        path.remove(QChar('\"'));
        mMastersModel->addMasters(path);
        mPluginsModel->addPlugins(path);
    }

    mMastersModel->sort(0);
    mPluginsModel->sort(0);
//    mMastersTable->sortByColumn(3, Qt::AscendingOrder);
//    mPluginsTable->sortByColumn(3, Qt::AscendingOrder);

    return true;
}