QTfrontend/util/FileEngine.h
author unc0rr
Sat, 17 Nov 2012 22:45:30 +0400
branchphysfslayer
changeset 8049 133e22b5c410
parent 7955 85b3970b402a
child 8052 845b5ae03841
permissions -rw-r--r--
Get rid of DataManager::findFileForRead
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);
7955
85b3970b402a - Load teams via physfs
unc0rr
parents: 7770
diff changeset
    67
        void mount(const QString & path, const QString & mountPoint);
7770
ff3442338882 Many bugfixes and features to FileEngine
unc0rr
parents: 7768
diff changeset
    68
        void setWriteDir(const QString & path);
ff3442338882 Many bugfixes and features to FileEngine
unc0rr
parents: 7768
diff changeset
    69
ff3442338882 Many bugfixes and features to FileEngine
unc0rr
parents: 7768
diff changeset
    70
//    private:
ff3442338882 Many bugfixes and features to FileEngine
unc0rr
parents: 7768
diff changeset
    71
        static const QString scheme;
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
ff3442338882 Many bugfixes and features to FileEngine
unc0rr
parents: 7768
diff changeset
    74
class FileEngineIterator : public QAbstractFileEngineIterator
ff3442338882 Many bugfixes and features to FileEngine
unc0rr
parents: 7768
diff changeset
    75
{
ff3442338882 Many bugfixes and features to FileEngine
unc0rr
parents: 7768
diff changeset
    76
public:
ff3442338882 Many bugfixes and features to FileEngine
unc0rr
parents: 7768
diff changeset
    77
        FileEngineIterator(QDir::Filters filters, const QStringList & nameFilters, const QStringList & entries);
ff3442338882 Many bugfixes and features to FileEngine
unc0rr
parents: 7768
diff changeset
    78
ff3442338882 Many bugfixes and features to FileEngine
unc0rr
parents: 7768
diff changeset
    79
        bool hasNext() const;
ff3442338882 Many bugfixes and features to FileEngine
unc0rr
parents: 7768
diff changeset
    80
        QString next();
ff3442338882 Many bugfixes and features to FileEngine
unc0rr
parents: 7768
diff changeset
    81
        QString currentFileName() const;
ff3442338882 Many bugfixes and features to FileEngine
unc0rr
parents: 7768
diff changeset
    82
private:
ff3442338882 Many bugfixes and features to FileEngine
unc0rr
parents: 7768
diff changeset
    83
        QStringList m_entries;
ff3442338882 Many bugfixes and features to FileEngine
unc0rr
parents: 7768
diff changeset
    84
        int m_index;
7768
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
    85
};
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
    86
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
    87
#endif