QTfrontend/util/FileEngine.h
author unc0rr
Mon, 05 Nov 2012 00:32:41 +0400
branchphysfslayer
changeset 7951 c64c0b413ff7
parent 7770 ff3442338882
child 7955 85b3970b402a
permissions -rw-r--r--
merge with default again
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
7768
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
     1
#ifndef _FileEngine_h
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
     2
#define _FileEngine_h
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
     3
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
     4
#include <QAbstractFileEngine>
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
     5
#include <QAbstractFileEngineHandler>
7770
ff3442338882 Many bugfixes and features to FileEngine
unc0rr
parents: 7768
diff changeset
     6
#include <QAbstractFileEngineIterator>
7768
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
     7
#include <QDateTime>
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
     8
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
     9
#include "physfs.h"
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
    10
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
    11
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
    12
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
    13
class FileEngine : public QAbstractFileEngine
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
    14
{
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
    15
    public:
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
    16
        FileEngine(const QString& filename);
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
    17
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
    18
        virtual ~FileEngine();
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
    19
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
    20
        virtual bool open(QIODevice::OpenMode openMode);
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
    21
        virtual bool close();
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
    22
        virtual bool flush();
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
    23
        virtual qint64 size() const;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
    24
        virtual qint64 pos() const;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
    25
        virtual bool seek(qint64 pos);
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
    26
        virtual bool isSequential() const;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
    27
        virtual bool remove();
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
    28
        virtual bool mkdir(const QString &dirName, bool createParentDirectories) const;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
    29
        virtual bool rmdir(const QString &dirName, bool recurseParentDirectories) const;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
    30
        virtual bool caseSensitive() const;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
    31
        virtual bool isRelativePath() const;
7770
ff3442338882 Many bugfixes and features to FileEngine
unc0rr
parents: 7768
diff changeset
    32
        QAbstractFileEngineIterator *beginEntryList(QDir::Filters filters, const QStringList & filterNames);
7768
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
    33
        virtual QStringList entryList(QDir::Filters filters, const QStringList &filterNames) const;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
    34
        virtual FileFlags fileFlags(FileFlags type=FileInfoAll) const;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
    35
        virtual QString fileName(FileName file=DefaultName) const;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
    36
        virtual QDateTime fileTime(FileTime time) const;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
    37
        virtual void setFileName(const QString &file);
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
    38
        bool atEnd() const;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
    39
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
    40
        virtual qint64 read(char *data, qint64 maxlen);
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
    41
        virtual qint64 write(const char *data, qint64 len);
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
    42
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
    43
        bool isOpened() const;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
    44
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
    45
        QFile::FileError error() const;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
    46
        QString errorString() const;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
    47
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
    48
        virtual bool supportsExtension(Extension extension) const;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
    49
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
    50
    private:
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
    51
        PHYSFS_file *_handler;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
    52
        qint64 _size;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
    53
        FileFlags _flags;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
    54
        QString _filename;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
    55
        QDateTime _datetime;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
    56
};
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
    57
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
    58
class FileEngineHandler : public QAbstractFileEngineHandler
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
    59
{
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
    60
    public:
7770
ff3442338882 Many bugfixes and features to FileEngine
unc0rr
parents: 7768
diff changeset
    61
        FileEngineHandler(char * argv0);
ff3442338882 Many bugfixes and features to FileEngine
unc0rr
parents: 7768
diff changeset
    62
        ~FileEngineHandler();
ff3442338882 Many bugfixes and features to FileEngine
unc0rr
parents: 7768
diff changeset
    63
7768
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
    64
        QAbstractFileEngine *create(const QString &filename) const;
7770
ff3442338882 Many bugfixes and features to FileEngine
unc0rr
parents: 7768
diff changeset
    65
ff3442338882 Many bugfixes and features to FileEngine
unc0rr
parents: 7768
diff changeset
    66
        void mount(const QString & path);
ff3442338882 Many bugfixes and features to FileEngine
unc0rr
parents: 7768
diff changeset
    67
        void setWriteDir(const QString & path);
ff3442338882 Many bugfixes and features to FileEngine
unc0rr
parents: 7768
diff changeset
    68
ff3442338882 Many bugfixes and features to FileEngine
unc0rr
parents: 7768
diff changeset
    69
//    private:
ff3442338882 Many bugfixes and features to FileEngine
unc0rr
parents: 7768
diff changeset
    70
        static const QString scheme;
ff3442338882 Many bugfixes and features to FileEngine
unc0rr
parents: 7768
diff changeset
    71
};
ff3442338882 Many bugfixes and features to FileEngine
unc0rr
parents: 7768
diff changeset
    72
ff3442338882 Many bugfixes and features to FileEngine
unc0rr
parents: 7768
diff changeset
    73
class FileEngineIterator : public QAbstractFileEngineIterator
ff3442338882 Many bugfixes and features to FileEngine
unc0rr
parents: 7768
diff changeset
    74
{
ff3442338882 Many bugfixes and features to FileEngine
unc0rr
parents: 7768
diff changeset
    75
public:
ff3442338882 Many bugfixes and features to FileEngine
unc0rr
parents: 7768
diff changeset
    76
        FileEngineIterator(QDir::Filters filters, const QStringList & nameFilters, const QStringList & entries);
ff3442338882 Many bugfixes and features to FileEngine
unc0rr
parents: 7768
diff changeset
    77
ff3442338882 Many bugfixes and features to FileEngine
unc0rr
parents: 7768
diff changeset
    78
        bool hasNext() const;
ff3442338882 Many bugfixes and features to FileEngine
unc0rr
parents: 7768
diff changeset
    79
        QString next();
ff3442338882 Many bugfixes and features to FileEngine
unc0rr
parents: 7768
diff changeset
    80
        QString currentFileName() const;
ff3442338882 Many bugfixes and features to FileEngine
unc0rr
parents: 7768
diff changeset
    81
private:
ff3442338882 Many bugfixes and features to FileEngine
unc0rr
parents: 7768
diff changeset
    82
        QStringList m_entries;
ff3442338882 Many bugfixes and features to FileEngine
unc0rr
parents: 7768
diff changeset
    83
        int m_index;
7768
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
    84
};
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
    85
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
    86
#endif