QTfrontend/util/FileEngine.h
author Wuzzy <Wuzzy2@mail.ru>
Mon, 12 Oct 2020 01:01:28 +0200
changeset 15769 ed3c5c15dcbd
parent 12897 fc47fc4af6bd
permissions -rw-r--r--
Fix minor offset mismatch with wrapping laser
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
12897
fc47fc4af6bd Finish porting. Seems to work, but no thorough testing has been performed
unc0rr
parents: 10017
diff changeset
     4
#include <private/qabstractfileengine_p.h>
10017
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 9170
diff changeset
     5
#include <QDateTime>
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 9170
diff changeset
     6
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 9170
diff changeset
     7
#include "physfs.h"
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 9170
diff changeset
     8
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 9170
diff changeset
     9
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 9170
diff changeset
    10
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 9170
diff changeset
    11
class FileEngine : public QAbstractFileEngine
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 9170
diff changeset
    12
{
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 9170
diff changeset
    13
    public:
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 9170
diff changeset
    14
        FileEngine(const QString& filename);
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 9170
diff changeset
    15
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 9170
diff changeset
    16
        virtual ~FileEngine();
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 9170
diff changeset
    17
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 9170
diff changeset
    18
        virtual bool open(QIODevice::OpenMode openMode);
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 9170
diff changeset
    19
        virtual bool close();
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 9170
diff changeset
    20
        virtual bool flush();
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 9170
diff changeset
    21
        virtual qint64 size() const;
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 9170
diff changeset
    22
        virtual qint64 pos() const;
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 9170
diff changeset
    23
        virtual bool setSize(qint64 size);
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 9170
diff changeset
    24
        virtual bool seek(qint64 pos);
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 9170
diff changeset
    25
        virtual bool isSequential() const;
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 9170
diff changeset
    26
        virtual bool remove();
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 9170
diff changeset
    27
        virtual bool mkdir(const QString &dirName, bool createParentDirectories) const;
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 9170
diff changeset
    28
        virtual bool rmdir(const QString &dirName, bool recurseParentDirectories) const;
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 9170
diff changeset
    29
        virtual bool caseSensitive() const;
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 9170
diff changeset
    30
        virtual bool isRelativePath() const;
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 9170
diff changeset
    31
        QAbstractFileEngineIterator *beginEntryList(QDir::Filters filters, const QStringList & filterNames);
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 9170
diff changeset
    32
        virtual QStringList entryList(QDir::Filters filters, const QStringList &filterNames) const;
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 9170
diff changeset
    33
        virtual FileFlags fileFlags(FileFlags type=FileInfoAll) const;
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 9170
diff changeset
    34
        virtual QString fileName(FileName file=DefaultName) const;
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 9170
diff changeset
    35
        virtual QDateTime fileTime(FileTime time) const;
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 9170
diff changeset
    36
        virtual void setFileName(const QString &file);
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 9170
diff changeset
    37
        bool atEnd() const;
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 9170
diff changeset
    38
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 9170
diff changeset
    39
        virtual qint64 read(char *data, qint64 maxlen);
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 9170
diff changeset
    40
        virtual qint64 readLine(char *data, qint64 maxlen);
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 9170
diff changeset
    41
        virtual qint64 write(const char *data, qint64 len);
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 9170
diff changeset
    42
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 9170
diff changeset
    43
        bool isOpened() const;
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 9170
diff changeset
    44
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 9170
diff changeset
    45
        QFile::FileError error() const;
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 9170
diff changeset
    46
        QString errorString() const;
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 9170
diff changeset
    47
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 9170
diff changeset
    48
        virtual bool supportsExtension(Extension extension) const;
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 9170
diff changeset
    49
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 9170
diff changeset
    50
    private:
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 9170
diff changeset
    51
        PHYSFS_file *m_handle;
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 9170
diff changeset
    52
        qint64 m_size;
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 9170
diff changeset
    53
        FileFlags m_flags;
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 9170
diff changeset
    54
        QString m_fileName;
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 9170
diff changeset
    55
        QDateTime m_date;
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 9170
diff changeset
    56
        bool m_bufferSet;
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 9170
diff changeset
    57
        bool m_readWrite;
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 9170
diff changeset
    58
};
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 9170
diff changeset
    59
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 9170
diff changeset
    60
class FileEngineHandler : public QAbstractFileEngineHandler
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 9170
diff changeset
    61
{
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 9170
diff changeset
    62
    public:
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 9170
diff changeset
    63
        FileEngineHandler(char * argv0);
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 9170
diff changeset
    64
        ~FileEngineHandler();
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 9170
diff changeset
    65
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 9170
diff changeset
    66
        QAbstractFileEngine *create(const QString &filename) const;
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 9170
diff changeset
    67
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 9170
diff changeset
    68
        static void mount(const QString & path);
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 9170
diff changeset
    69
        static void mount(const QString & path, const QString & mountPoint);
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 9170
diff changeset
    70
        static void setWriteDir(const QString & path);
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 9170
diff changeset
    71
        static void mountPacks();
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 9170
diff changeset
    72
        static QString errorStr();
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 9170
diff changeset
    73
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 9170
diff changeset
    74
//    private:
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 9170
diff changeset
    75
        static const QString scheme;
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 9170
diff changeset
    76
};
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 9170
diff changeset
    77
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 9170
diff changeset
    78
class FileEngineIterator : public QAbstractFileEngineIterator
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 9170
diff changeset
    79
{
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 9170
diff changeset
    80
public:
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 9170
diff changeset
    81
        FileEngineIterator(QDir::Filters filters, const QStringList & nameFilters, const QStringList & entries);
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 9170
diff changeset
    82
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 9170
diff changeset
    83
        bool hasNext() const;
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 9170
diff changeset
    84
        QString next();
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 9170
diff changeset
    85
        QString currentFileName() const;
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 9170
diff changeset
    86
private:
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 9170
diff changeset
    87
        QStringList m_entries;
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 9170
diff changeset
    88
        int m_index;
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 9170
diff changeset
    89
};
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 9170
diff changeset
    90
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 9170
diff changeset
    91
#endif