⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 qresource.cpp

📁 奇趣公司比较新的qt/emd版本
💻 CPP
📖 第 1 页 / 共 3 页
字号:
            bool ok = false;            if (file.open(QIODevice::ReadOnly))                ok = (data_len == (uint)file.read((char*)data, data_len));            if (!ok) {                delete [] data;                data = 0;                data_len = 0;                return false;            }            fromMM = false;        }        if(data && QDynamicBufferResourceRoot::registerSelf(data)) {            if(fromMM) {                unmapPointer = data;                unmapLength = data_len;            }            fileName = f;            return true;        }        return false;    }};static QString qt_resource_fixResourceRoot(QString r) {    if(!r.isEmpty()) {        if(r.startsWith(QLatin1Char(':')))            r = r.mid(1);        if(!r.isEmpty())            r = QDir::cleanPath(r);    }    return r;}/*!   \fn bool QResource::registerResource(const QString &rccFileName, const QString &mapRoot)   Registers the resource with the given \a rccFileName at the location in the   resource tree specified by \a mapRoot, and returns true if the file is   successfully opened; otherwise returns false.   \sa unregisterResource()*/boolQResource::registerResource(const QString &rccFilename, const QString &resourceRoot){    QString r = qt_resource_fixResourceRoot(resourceRoot);    if(!r.isEmpty() && r[0] != QLatin1Char('/')) {        qWarning("QDir::registerResource: Registering a resource [%s] must be rooted in an absolute path (start with /) [%s]",                 rccFilename.toLocal8Bit().data(), resourceRoot.toLocal8Bit().data());        return false;    }    QDynamicFileResourceRoot *root = new QDynamicFileResourceRoot(r);    if(root->registerSelf(rccFilename)) {        root->ref.ref();        QMutexLocker lock(resourceMutex());        resourceList()->append(root);        return true;    }    delete root;    return false;}/*!  \fn bool QResource::unregisterResource(const QString &rccFileName, const QString &mapRoot)  Unregisters the resource with the given \a rccFileName at the location in  the resource tree specified by \a mapRoot, and returns true if the  resource is successfully unloaded and no references exist for the  resource; otherwise returns false.  \sa registerResource()*/boolQResource::unregisterResource(const QString &rccFilename, const QString &resourceRoot){    QString r = qt_resource_fixResourceRoot(resourceRoot);    QMutexLocker lock(resourceMutex());    ResourceList *list = resourceList();    for(int i = 0; i < list->size(); ++i) {        QResourceRoot *res = list->at(i);        if(res->type() == QResourceRoot::Resource_File) {	    QDynamicFileResourceRoot *root = reinterpret_cast<QDynamicFileResourceRoot*>(res);	    if(root->mappingFile() == rccFilename && root->mappingRoot() == r) {                resourceList()->removeAt(i);                if(!root->ref.deref()) {                    delete root;                    return true;                }                return false;            }	}    }    return false;}/*!   \fn bool QResource::registerResource(const uchar *rccData, const QString &mapRoot)   \since 4.3   Registers the resource with the given \a rccData at the location in the   resource tree specified by \a mapRoot, and returns true if the file is   successfully opened; otherwise returns false.   \warning The data must remain valid throughout the life of any QFile   that may reference the resource data.   \sa unregisterResource()*/boolQResource::registerResource(const uchar *rccData, const QString &resourceRoot){    QString r = qt_resource_fixResourceRoot(resourceRoot);    if(!r.isEmpty() && r[0] != QLatin1Char('/')) {        qWarning("QDir::registerResource: Registering a resource [%p] must be rooted in an absolute path (start with /) [%s]",                 rccData, resourceRoot.toLocal8Bit().data());        return false;    }    QDynamicBufferResourceRoot *root = new QDynamicBufferResourceRoot(r);    if(root->registerSelf(rccData)) {        root->ref.ref();        QMutexLocker lock(resourceMutex());        resourceList()->append(root);        return true;    }    delete root;    return false;}/*!  \fn bool QResource::unregisterResource(const uchar *rccData, const QString &mapRoot)  \since 4.3  Unregisters the resource with the given \a rccData at the location in the  resource tree specified by \a mapRoot, and returns true if the resource is  successfully unloaded and no references exist into the resource; otherwise returns false.  \sa registerResource()*/boolQResource::unregisterResource(const uchar *rccData, const QString &resourceRoot){    QString r = qt_resource_fixResourceRoot(resourceRoot);    QMutexLocker lock(resourceMutex());    ResourceList *list = resourceList();    for(int i = 0; i < list->size(); ++i) {        QResourceRoot *res = list->at(i);        if(res->type() == QResourceRoot::Resource_Buffer) {	    QDynamicBufferResourceRoot *root = reinterpret_cast<QDynamicBufferResourceRoot*>(res);	    if(root->mappingBuffer() == rccData && root->mappingRoot() == r) {                resourceList()->removeAt(i);                if(!root->ref.deref()) {                    delete root;                    return true;                }		return false;            }	}    }    return false;}//file type handlerclass QResourceFileEngineHandler : public QAbstractFileEngineHandler{public:    QResourceFileEngineHandler() { }    ~QResourceFileEngineHandler() { }    QAbstractFileEngine *create(const QString &path) const;};QAbstractFileEngine *QResourceFileEngineHandler::create(const QString &path) const{    if (path.size() > 0 && path.startsWith(QLatin1Char(':')))        return new QResourceFileEngine(path);    return 0;}//resource engineclass QResourceFileEnginePrivate : public QAbstractFileEnginePrivate{protected:    Q_DECLARE_PUBLIC(QResourceFileEngine)private:    qint64 offset;    QResource resource;    QByteArray uncompressed;protected:    QResourceFileEnginePrivate() : offset(0) { }};bool QResourceFileEngine::mkdir(const QString &, bool) const{    return false;}bool QResourceFileEngine::rmdir(const QString &, bool) const{    return false;}bool QResourceFileEngine::setSize(qint64){    return false;}QStringList QResourceFileEngine::entryList(QDir::Filters filters, const QStringList &filterNames) const{    return QAbstractFileEngine::entryList(filters, filterNames);}bool QResourceFileEngine::caseSensitive() const{    return true;}QResourceFileEngine::QResourceFileEngine(const QString &file) :    QAbstractFileEngine(*new QResourceFileEnginePrivate){    Q_D(QResourceFileEngine);    d->resource.setFileName(file);    if(d->resource.isCompressed() && d->resource.size()) {#ifndef QT_NO_COMPRESS        d->uncompressed = qUncompress(d->resource.data(), d->resource.size());#else        Q_ASSERT("QResourceFileEngine::open: Qt built without support for compression");#endif    }}QResourceFileEngine::~QResourceFileEngine(){}void QResourceFileEngine::setFileName(const QString &file){    Q_D(QResourceFileEngine);    d->resource.setFileName(file);}bool QResourceFileEngine::open(QIODevice::OpenMode flags){    Q_D(QResourceFileEngine);    if (d->resource.fileName().isEmpty()) {        qWarning("QResourceFileEngine::open: Missing file name");        return false;    }    if(flags & QIODevice::WriteOnly)        return false;    if(!d->resource.isValid())       return false;    return true;}bool QResourceFileEngine::close(){    Q_D(QResourceFileEngine);    d->offset = 0;    d->uncompressed.clear();    return true;}bool QResourceFileEngine::flush(){    return false;}qint64 QResourceFileEngine::read(char *data, qint64 len){    Q_D(QResourceFileEngine);    if(len > size()-d->offset)        len = size()-d->offset;    if(len <= 0)        return 0;    if(d->resource.isCompressed())        memcpy(data, d->uncompressed.constData()+d->offset, len);    else        memcpy(data, d->resource.data()+d->offset, len);    d->offset += len;    return len;}qint64 QResourceFileEngine::write(const char *, qint64){    return -1;}bool QResourceFileEngine::remove(){    return false;}bool QResourceFileEngine::copy(const QString &){    return false;}bool QResourceFileEngine::rename(const QString &){    return false;}bool QResourceFileEngine::link(const QString &){    return false;}qint64 QResourceFileEngine::size() const{    Q_D(const QResourceFileEngine);    if(!d->resource.isValid())        return 0;    if(d->resource.isCompressed())        return d->uncompressed.size();    return d->resource.size();}qint64 QResourceFileEngine::pos() const{    Q_D(const QResourceFileEngine);    return d->offset;}bool QResourceFileEngine::atEnd() const{    Q_D(const QResourceFileEngine);    if(!d->resource.isValid())        return true;    return d->offset == size();}bool QResourceFileEngine::seek(qint64 pos){    Q_D(QResourceFileEngine);    if(!d->resource.isValid())        return false;    if(d->offset > size())        return false;    d->offset = pos;    return true;}bool QResourceFileEngine::isSequential() const{    return false;}QAbstractFileEngine::FileFlags QResourceFileEngine::fileFlags(QAbstractFileEngine::FileFlags type) const{    Q_D(const QResourceFileEngine);    QAbstractFileEngine::FileFlags ret = 0;    if(!d->resource.isValid())        return ret;    if(type & PermsMask)        ret |= QAbstractFileEngine::FileFlags(ReadOwnerPerm|ReadUserPerm|ReadGroupPerm|ReadOtherPerm);    if(type & TypesMask) {        if(d->resource.isDir())            ret |= DirectoryType;        else            ret |= FileType;    }    if(type & FlagsMask) {        ret |= ExistsFlag;        if(d->resource.absoluteFilePath() == QLatin1String(":/"))            ret |= RootFlag;    }    return ret;}bool QResourceFileEngine::setPermissions(uint){    return false;}QString QResourceFileEngine::fileName(FileName file) const{    Q_D(const QResourceFileEngine);    if(file == BaseName) {	int slash = d->resource.fileName().lastIndexOf(QLatin1Char('/'));	if (slash == -1)	    return d->resource.fileName();	return d->resource.fileName().mid(slash + 1);    } else if(file == PathName || file == AbsolutePathName) {        const QString path = (file == AbsolutePathName) ? d->resource.absoluteFilePath() : d->resource.fileName();	const int slash = path.lastIndexOf(QLatin1Char('/'));	if (slash != -1)	    return path.left(slash);    } else if(file == CanonicalName || file == CanonicalPathName) {        const QString absoluteFilePath = d->resource.absoluteFilePath();        if(file == CanonicalPathName) {            const int slash = absoluteFilePath.lastIndexOf(QLatin1Char('/'));            if (slash != -1)                return absoluteFilePath.left(slash);        }        return absoluteFilePath;    }    return d->resource.fileName();}bool QResourceFileEngine::isRelativePath() const{    return false;}uint QResourceFileEngine::ownerId(FileOwner) const{    static const uint nobodyID = (uint) -2;    return nobodyID;}QString QResourceFileEngine::owner(FileOwner) const{    return QString();}QDateTime QResourceFileEngine::fileTime(FileTime) const{    return QDateTime();}/*!    \internal*/QAbstractFileEngine::Iterator *QResourceFileEngine::beginEntryList(QDir::Filters filters,                                                                   const QStringList &filterNames){    return new QResourceFileEngineIterator(filters, filterNames);}/*!    \internal*/QAbstractFileEngine::Iterator *QResourceFileEngine::endEntryList(){    return 0;}bool QResourceFileEngine::extension(Extension extension, const ExtensionOption *option, ExtensionReturn *output){    Q_UNUSED(extension);    Q_UNUSED(option);    Q_UNUSED(output);    return false;}bool QResourceFileEngine::supportsExtension(Extension extension) const{    Q_UNUSED(extension);    return false;}//Initialization and cleanupQ_GLOBAL_STATIC(QResourceFileEngineHandler, resource_file_handler)static int qt_force_resource_init() { resource_file_handler(); return 1; }Q_CORE_EXPORT void qInitResourceIO() { resource_file_handler(); }static int qt_forced_resource_init = qt_force_resource_init();Q_CONSTRUCTOR_FUNCTION(qt_force_resource_init)

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -