QTfrontend/util/FileEngine.h
author unc0rr
Thu, 22 Nov 2012 23:19:01 +0400
branchflibqtfrontend
changeset 8094 6c5b4e69f03d
parent 8055 04dd8b7fb605
child 8112 d85dc8a8f41c
permissions -rw-r--r--
Fix some frontlib bugs
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
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
    66
        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
    67
        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
    68
        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
    69
        static void mountPacks();
7770
ff3442338882 Many bugfixes and features to FileEngine
unc0rr
parents: 7768
diff changeset
    70
ff3442338882 Many bugfixes and features to FileEngine
unc0rr
parents: 7768
diff changeset
    71
//    private:
ff3442338882 Many bugfixes and features to FileEngine
unc0rr
parents: 7768
diff changeset
    72
        static const QString scheme;
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
ff3442338882 Many bugfixes and features to FileEngine
unc0rr
parents: 7768
diff changeset
    75
class FileEngineIterator : public QAbstractFileEngineIterator
ff3442338882 Many bugfixes and features to FileEngine
unc0rr
parents: 7768
diff changeset
    76
{
ff3442338882 Many bugfixes and features to FileEngine
unc0rr
parents: 7768
diff changeset
    77
public:
ff3442338882 Many bugfixes and features to FileEngine
unc0rr
parents: 7768
diff changeset
    78
        FileEngineIterator(QDir::Filters filters, const QStringList & nameFilters, const QStringList & entries);
ff3442338882 Many bugfixes and features to FileEngine
unc0rr
parents: 7768
diff changeset
    79
ff3442338882 Many bugfixes and features to FileEngine
unc0rr
parents: 7768
diff changeset
    80
        bool hasNext() const;
ff3442338882 Many bugfixes and features to FileEngine
unc0rr
parents: 7768
diff changeset
    81
        QString next();
ff3442338882 Many bugfixes and features to FileEngine
unc0rr
parents: 7768
diff changeset
    82
        QString currentFileName() const;
ff3442338882 Many bugfixes and features to FileEngine
unc0rr
parents: 7768
diff changeset
    83
private:
ff3442338882 Many bugfixes and features to FileEngine
unc0rr
parents: 7768
diff changeset
    84
        QStringList m_entries;
ff3442338882 Many bugfixes and features to FileEngine
unc0rr
parents: 7768
diff changeset
    85
        int m_index;
7768
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
    86
};
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
    87
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
    88
#endif