Debian Codegraph @

src/fs/fs.h

raw symbols SCIP
1 // Copyright (C) 2014 Sacha Refshauge
2
3 // This program is free software: you can redistribute it and/or modify
4 // it under the terms of the GNU General Public License as published by
5 // the Free Software Foundation, version 3.0.
6
7 // This program is distributed in the hope that it will be useful,
8 // but WITHOUT ANY WARRANTY; without even the implied warranty of
9 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 // GNU General Public License 3.0 for more details.
11
12 // A copy of the GPL 3.0 should have been included with the program.
13 // If not, see http://www.gnu.org/licenses/
14
15 // Official GIT repository and contact information can be found at
16 // http://github.com/xsacha/Sachesi
17
18 #pragma once
19
20 #include <QFile>
21 #include <QIODevice>
22 #include <QDataStream>
23 #include <QDir>
24 #include <QDebug>
25 #include <QDesktopServices>
26 #include <QUrl>
27
28 // node.mode flags
29 #define QCFM_IS_COMPRESSED ((1 << 22) | (1 << 23) | (1 << 24))
30 // lzo1x_decompress_safe
31 #define QCFM_IS_LZO_COMPRESSED (1 << 23)
32 // ucl_nrv2b_decompress_8
33 #define QCFM_IS_UCL_COMPRESSED ((1 << 22) | (1 << 23))
34 #define QCFM_IS_GZIP_COMPRESSED (1 << 22)
35 #define QCFM_IS_DIRECTORY (1 << 14)
36 #define QCFM_IS_SYMLINK (1 << 13)
37 // QNX6 maximum filename length
38 #define QNX6_MAX_CHARS 510
39
40 // Utility function to quickly grab from stream
41 #define READ_TMP(x, y) x y; stream >> y;
42 // Maximum amount to store in RAM at any time between reading QIODevice and writing to disk.
43 #define BUFFER_LEN (qint64)4096
44 #define FAST_BUFFER_LEN (qint64)819200
45
46 #ifdef _WIN32
47 #include "Windows.h"
48 // We need to update the time of the extracted file based on the unix filesystem it comes from.
49 void fixFileTime(QString filename, int time);
50 #endif
51
52 // Since QNX files are always LittleEndian but Qt defaults to BigEndian, this wrapper exists
53 class QNXStream : public QDataStream {
54 public:
55 QNXStream(QIODevice * device)
56 : QDataStream(device) {
57 setByteOrder(QDataStream::LittleEndian);
58 }
59 QNXStream(QByteArray * a, QIODevice::OpenMode flags)
60 : QDataStream(a, flags) {
61 setByteOrder(QDataStream::LittleEndian);
62 resetStatus();
63 }
64 int grabInt() {
65 int tmp;
66 this->operator >>(tmp);
67 return tmp;
68 }
69 unsigned short grabUShort() {
70 unsigned short tmp;
71 this->operator >>(tmp);
72 return tmp;
73 }
74 unsigned char grabUChar() {
75 unsigned char tmp;
76 this->operator >>(tmp);
77 return tmp;
78 }
79 };
80
81 class QFileSystem : public QObject
82 {
83 Q_OBJECT
84 public:
85 explicit QFileSystem(QString filename, QIODevice* file = nullptr, qint64 offset = 0, qint64 size = 0, QString path = ".", QString imageExt = "");
86 ~QFileSystem();
87
88 // Basis of size reporting
89 void increaseCurSize(qint64 read) {
90 if (read <= 0)
91 return;
92 curSize += read;
93 emit sizeChanged(read);
94 }
95
96 QString uniqueDir(QString name);
97 QString uniqueFile(QString name);
98 virtual QString generateName(QString imageExt = "");
99 bool writeFile(QString fileName, qint64 offset, qint64 writeSize, bool absolute = false);
100 bool extractImage();
101 virtual bool createImage(QString name);
102 bool extractContents();
103 virtual bool createContents() = 0;
104
105 qint64 curSize;
106 qint64 maxSize;
107
108 signals:
109 void sizeChanged(qint64 delta);
110
111 protected:
112 QIODevice* _file;
113 qint64 _offset, _size;
114 QString _path, _filename;
115 QString _imageExt;
116 };