QTfrontend/util/FileEngine.h
author sheepluva
Tue, 26 Mar 2013 18:52:42 +0100
changeset 8792 af4ab297b2b7
parent 8178 8bd087478b48
child 9170 7c75643d0b66
permissions -rw-r--r--
merge
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;
8178
8bd087478b48 Fix QSettings problems:
unc0rr
parents: 8115
diff changeset
    25
        virtual bool setSize(qint64 size);
7768
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
    26
        virtual bool seek(qint64 pos);
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
    27
        virtual bool isSequential() const;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
    28
        virtual bool remove();
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
    29
        virtual bool mkdir(const QString &dirName, bool createParentDirectories) const;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
    30
        virtual bool rmdir(const QString &dirName, bool recurseParentDirectories) const;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
    31
        virtual bool caseSensitive() const;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
    32
        virtual bool isRelativePath() const;
7770
ff3442338882 Many bugfixes and features to FileEngine
unc0rr
parents: 7768
diff changeset
    33
        QAbstractFileEngineIterator *beginEntryList(QDir::Filters filters, const QStringList & filterNames);
7768
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
    34
        virtual QStringList entryList(QDir::Filters filters, const QStringList &filterNames) const;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
    35
        virtual FileFlags fileFlags(FileFlags type=FileInfoAll) const;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
    36
        virtual QString fileName(FileName file=DefaultName) const;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
    37
        virtual QDateTime fileTime(FileTime time) const;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
    38
        virtual void setFileName(const QString &file);
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
    39
        bool atEnd() const;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
    40
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
    41
        virtual qint64 read(char *data, qint64 maxlen);
8112
d85dc8a8f41c Implement QAbstractFileEngine::FastReadLineExtension
unc0rr
parents: 8055
diff changeset
    42
        virtual qint64 readLine(char *data, qint64 maxlen);
7768
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
    43
        virtual qint64 write(const char *data, qint64 len);
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
    44
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
    45
        bool isOpened() const;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
    46
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
    47
        QFile::FileError error() const;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
    48
        QString errorString() const;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
    49
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
    50
        virtual bool supportsExtension(Extension extension) const;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
    51
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
    52
    private:
8115
ac1007c6dea8 Refactor identifiers names
unc0rr
parents: 8112
diff changeset
    53
        PHYSFS_file *m_handle;
ac1007c6dea8 Refactor identifiers names
unc0rr
parents: 8112
diff changeset
    54
        qint64 m_size;
ac1007c6dea8 Refactor identifiers names
unc0rr
parents: 8112
diff changeset
    55
        FileFlags m_flags;
ac1007c6dea8 Refactor identifiers names
unc0rr
parents: 8112
diff changeset
    56
        QString m_fileName;
ac1007c6dea8 Refactor identifiers names
unc0rr
parents: 8112
diff changeset
    57
        QDateTime m_date;
8112
d85dc8a8f41c Implement QAbstractFileEngine::FastReadLineExtension
unc0rr
parents: 8055
diff changeset
    58
        bool m_bufferSet;
8178
8bd087478b48 Fix QSettings problems:
unc0rr
parents: 8115
diff changeset
    59
        bool m_readWrite;
7768
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
    60
};
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
    61
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
    62
class FileEngineHandler : public QAbstractFileEngineHandler
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
    63
{
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
    64
    public:
7770
ff3442338882 Many bugfixes and features to FileEngine
unc0rr
parents: 7768
diff changeset
    65
        FileEngineHandler(char * argv0);
ff3442338882 Many bugfixes and features to FileEngine
unc0rr
parents: 7768
diff changeset
    66
        ~FileEngineHandler();
ff3442338882 Many bugfixes and features to FileEngine
unc0rr
parents: 7768
diff changeset
    67
7768
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
    68
        QAbstractFileEngine *create(const QString &filename) const;
7770
ff3442338882 Many bugfixes and features to FileEngine
unc0rr
parents: 7768
diff changeset
    69
8055
04dd8b7fb605 - Download .hwp files into Data folder and mount them immediately (yes, could cause problems in case of overlapped contents)
unc0rr
parents: 8052
diff changeset
    70
        static void mount(const QString & path);
04dd8b7fb605 - Download .hwp files into Data folder and mount them immediately (yes, could cause problems in case of overlapped contents)
unc0rr
parents: 8052
diff changeset
    71
        static void mount(const QString & path, const QString & mountPoint);
04dd8b7fb605 - Download .hwp files into Data folder and mount them immediately (yes, could cause problems in case of overlapped contents)
unc0rr
parents: 8052
diff changeset
    72
        static void setWriteDir(const QString & path);
04dd8b7fb605 - Download .hwp files into Data folder and mount them immediately (yes, could cause problems in case of overlapped contents)
unc0rr
parents: 8052
diff changeset
    73
        static void mountPacks();
7770
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
//    private:
ff3442338882 Many bugfixes and features to FileEngine
unc0rr
parents: 7768
diff changeset
    76
        static const QString scheme;
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
ff3442338882 Many bugfixes and features to FileEngine
unc0rr
parents: 7768
diff changeset
    79
class FileEngineIterator : public QAbstractFileEngineIterator
ff3442338882 Many bugfixes and features to FileEngine
unc0rr
parents: 7768
diff changeset
    80
{
ff3442338882 Many bugfixes and features to FileEngine
unc0rr
parents: 7768
diff changeset
    81
public:
ff3442338882 Many bugfixes and features to FileEngine
unc0rr
parents: 7768
diff changeset
    82
        FileEngineIterator(QDir::Filters filters, const QStringList & nameFilters, const QStringList & entries);
ff3442338882 Many bugfixes and features to FileEngine
unc0rr
parents: 7768
diff changeset
    83
ff3442338882 Many bugfixes and features to FileEngine
unc0rr
parents: 7768
diff changeset
    84
        bool hasNext() const;
ff3442338882 Many bugfixes and features to FileEngine
unc0rr
parents: 7768
diff changeset
    85
        QString next();
ff3442338882 Many bugfixes and features to FileEngine
unc0rr
parents: 7768
diff changeset
    86
        QString currentFileName() const;
ff3442338882 Many bugfixes and features to FileEngine
unc0rr
parents: 7768
diff changeset
    87
private:
ff3442338882 Many bugfixes and features to FileEngine
unc0rr
parents: 7768
diff changeset
    88
        QStringList m_entries;
ff3442338882 Many bugfixes and features to FileEngine
unc0rr
parents: 7768
diff changeset
    89
        int m_index;
7768
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
    90
};
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
    91
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
    92
#endif