QTfrontend/util/FileEngine.h
author Wuzzy <almikes@aol.com>
Wed, 23 Nov 2016 16:02:03 +0100
changeset 12043 cba2ef0cf2e8
parent 10017 de822cd3df3a
child 12902 fc47fc4af6bd
permissions -rw-r--r--
Add sine gun to Crazy weapon set
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
10017
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 9170
diff changeset
     1
#ifndef _FileEngine_h
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 9170
diff changeset
     2
#define _FileEngine_h
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 9170
diff changeset
     3
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 9170
diff changeset
     4
#include <QAbstractFileEngine>
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 9170
diff changeset
     5
#include <QAbstractFileEngineHandler>
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 9170
diff changeset
     6
#include <QAbstractFileEngineIterator>
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 9170
diff changeset
     7
#include <QDateTime>
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 9170
diff changeset
     8
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 9170
diff changeset
     9
#include "physfs.h"
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 9170
diff changeset
    10
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 9170
diff changeset
    11
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 9170
diff changeset
    12
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 9170
diff changeset
    13
class FileEngine : public QAbstractFileEngine
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 9170
diff changeset
    14
{
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 9170
diff changeset
    15
    public:
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 9170
diff changeset
    16
        FileEngine(const QString& filename);
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 9170
diff changeset
    17
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 9170
diff changeset
    18
        virtual ~FileEngine();
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 9170
diff changeset
    19
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 9170
diff changeset
    20
        virtual bool open(QIODevice::OpenMode openMode);
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 9170
diff changeset
    21
        virtual bool close();
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 9170
diff changeset
    22
        virtual bool flush();
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 9170
diff changeset
    23
        virtual qint64 size() const;
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 9170
diff changeset
    24
        virtual qint64 pos() const;
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 9170
diff changeset
    25
        virtual bool setSize(qint64 size);
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 9170
diff changeset
    26
        virtual bool seek(qint64 pos);
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 9170
diff changeset
    27
        virtual bool isSequential() const;
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 9170
diff changeset
    28
        virtual bool remove();
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 9170
diff changeset
    29
        virtual bool mkdir(const QString &dirName, bool createParentDirectories) const;
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 9170
diff changeset
    30
        virtual bool rmdir(const QString &dirName, bool recurseParentDirectories) const;
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 9170
diff changeset
    31
        virtual bool caseSensitive() const;
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 9170
diff changeset
    32
        virtual bool isRelativePath() const;
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 9170
diff changeset
    33
        QAbstractFileEngineIterator *beginEntryList(QDir::Filters filters, const QStringList & filterNames);
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 9170
diff changeset
    34
        virtual QStringList entryList(QDir::Filters filters, const QStringList &filterNames) const;
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 9170
diff changeset
    35
        virtual FileFlags fileFlags(FileFlags type=FileInfoAll) const;
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 9170
diff changeset
    36
        virtual QString fileName(FileName file=DefaultName) const;
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 9170
diff changeset
    37
        virtual QDateTime fileTime(FileTime time) const;
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 9170
diff changeset
    38
        virtual void setFileName(const QString &file);
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 9170
diff changeset
    39
        bool atEnd() const;
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 9170
diff changeset
    40
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 9170
diff changeset
    41
        virtual qint64 read(char *data, qint64 maxlen);
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 9170
diff changeset
    42
        virtual qint64 readLine(char *data, qint64 maxlen);
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 9170
diff changeset
    43
        virtual qint64 write(const char *data, qint64 len);
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 9170
diff changeset
    44
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 9170
diff changeset
    45
        bool isOpened() const;
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 9170
diff changeset
    46
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 9170
diff changeset
    47
        QFile::FileError error() const;
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 9170
diff changeset
    48
        QString errorString() const;
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 9170
diff changeset
    49
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 9170
diff changeset
    50
        virtual bool supportsExtension(Extension extension) const;
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 9170
diff changeset
    51
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 9170
diff changeset
    52
    private:
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 9170
diff changeset
    53
        PHYSFS_file *m_handle;
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 9170
diff changeset
    54
        qint64 m_size;
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 9170
diff changeset
    55
        FileFlags m_flags;
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 9170
diff changeset
    56
        QString m_fileName;
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 9170
diff changeset
    57
        QDateTime m_date;
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 9170
diff changeset
    58
        bool m_bufferSet;
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 9170
diff changeset
    59
        bool m_readWrite;
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 9170
diff changeset
    60
};
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 9170
diff changeset
    61
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 9170
diff changeset
    62
class FileEngineHandler : public QAbstractFileEngineHandler
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 9170
diff changeset
    63
{
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 9170
diff changeset
    64
    public:
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 9170
diff changeset
    65
        FileEngineHandler(char * argv0);
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 9170
diff changeset
    66
        ~FileEngineHandler();
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 9170
diff changeset
    67
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 9170
diff changeset
    68
        QAbstractFileEngine *create(const QString &filename) const;
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 9170
diff changeset
    69
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 9170
diff changeset
    70
        static void mount(const QString & path);
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 9170
diff changeset
    71
        static void mount(const QString & path, const QString & mountPoint);
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 9170
diff changeset
    72
        static void setWriteDir(const QString & path);
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 9170
diff changeset
    73
        static void mountPacks();
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 9170
diff changeset
    74
        static QString errorStr();
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 9170
diff changeset
    75
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 9170
diff changeset
    76
//    private:
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 9170
diff changeset
    77
        static const QString scheme;
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 9170
diff changeset
    78
};
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 9170
diff changeset
    79
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 9170
diff changeset
    80
class FileEngineIterator : public QAbstractFileEngineIterator
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 9170
diff changeset
    81
{
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 9170
diff changeset
    82
public:
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 9170
diff changeset
    83
        FileEngineIterator(QDir::Filters filters, const QStringList & nameFilters, const QStringList & entries);
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 9170
diff changeset
    84
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 9170
diff changeset
    85
        bool hasNext() const;
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 9170
diff changeset
    86
        QString next();
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 9170
diff changeset
    87
        QString currentFileName() const;
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 9170
diff changeset
    88
private:
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 9170
diff changeset
    89
        QStringList m_entries;
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 9170
diff changeset
    90
        int m_index;
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 9170
diff changeset
    91
};
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 9170
diff changeset
    92
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 9170
diff changeset
    93
#endif