author | nemo |
Mon, 15 Oct 2018 13:08:29 -0400 | |
changeset 13925 | 7173b702e8db |
parent 13874 | bd796e4d8920 |
child 14323 | d688455cad8f |
permissions | -rw-r--r-- |
8440
ea4d6a7a2937
complete tabs and trailing whitespace formatting on frontend
koda
parents:
8206
diff
changeset
|
1 |
/* borrowed from https://github.com/skhaz/qt-physfs-wrapper |
ea4d6a7a2937
complete tabs and trailing whitespace formatting on frontend
koda
parents:
8206
diff
changeset
|
2 |
* TODO: add copyright header, determine license |
ea4d6a7a2937
complete tabs and trailing whitespace formatting on frontend
koda
parents:
8206
diff
changeset
|
3 |
*/ |
ea4d6a7a2937
complete tabs and trailing whitespace formatting on frontend
koda
parents:
8206
diff
changeset
|
4 |
|
10235 | 5 |
#include "FileEngine.h" |
8440
ea4d6a7a2937
complete tabs and trailing whitespace formatting on frontend
koda
parents:
8206
diff
changeset
|
6 |
#include "hwpacksmounter.h" |
ea4d6a7a2937
complete tabs and trailing whitespace formatting on frontend
koda
parents:
8206
diff
changeset
|
7 |
|
ea4d6a7a2937
complete tabs and trailing whitespace formatting on frontend
koda
parents:
8206
diff
changeset
|
8 |
|
ea4d6a7a2937
complete tabs and trailing whitespace formatting on frontend
koda
parents:
8206
diff
changeset
|
9 |
const QString FileEngineHandler::scheme = "physfs:/"; |
ea4d6a7a2937
complete tabs and trailing whitespace formatting on frontend
koda
parents:
8206
diff
changeset
|
10 |
|
ea4d6a7a2937
complete tabs and trailing whitespace formatting on frontend
koda
parents:
8206
diff
changeset
|
11 |
FileEngine::FileEngine(const QString& filename) |
ea4d6a7a2937
complete tabs and trailing whitespace formatting on frontend
koda
parents:
8206
diff
changeset
|
12 |
: m_handle(NULL) |
ea4d6a7a2937
complete tabs and trailing whitespace formatting on frontend
koda
parents:
8206
diff
changeset
|
13 |
, m_size(0) |
ea4d6a7a2937
complete tabs and trailing whitespace formatting on frontend
koda
parents:
8206
diff
changeset
|
14 |
, m_flags(0) |
ea4d6a7a2937
complete tabs and trailing whitespace formatting on frontend
koda
parents:
8206
diff
changeset
|
15 |
, m_bufferSet(false) |
ea4d6a7a2937
complete tabs and trailing whitespace formatting on frontend
koda
parents:
8206
diff
changeset
|
16 |
, m_readWrite(false) |
ea4d6a7a2937
complete tabs and trailing whitespace formatting on frontend
koda
parents:
8206
diff
changeset
|
17 |
{ |
ea4d6a7a2937
complete tabs and trailing whitespace formatting on frontend
koda
parents:
8206
diff
changeset
|
18 |
setFileName(filename); |
ea4d6a7a2937
complete tabs and trailing whitespace formatting on frontend
koda
parents:
8206
diff
changeset
|
19 |
} |
ea4d6a7a2937
complete tabs and trailing whitespace formatting on frontend
koda
parents:
8206
diff
changeset
|
20 |
|
ea4d6a7a2937
complete tabs and trailing whitespace formatting on frontend
koda
parents:
8206
diff
changeset
|
21 |
FileEngine::~FileEngine() |
ea4d6a7a2937
complete tabs and trailing whitespace formatting on frontend
koda
parents:
8206
diff
changeset
|
22 |
{ |
ea4d6a7a2937
complete tabs and trailing whitespace formatting on frontend
koda
parents:
8206
diff
changeset
|
23 |
close(); |
ea4d6a7a2937
complete tabs and trailing whitespace formatting on frontend
koda
parents:
8206
diff
changeset
|
24 |
} |
ea4d6a7a2937
complete tabs and trailing whitespace formatting on frontend
koda
parents:
8206
diff
changeset
|
25 |
|
ea4d6a7a2937
complete tabs and trailing whitespace formatting on frontend
koda
parents:
8206
diff
changeset
|
26 |
bool FileEngine::open(QIODevice::OpenMode openMode) |
ea4d6a7a2937
complete tabs and trailing whitespace formatting on frontend
koda
parents:
8206
diff
changeset
|
27 |
{ |
ea4d6a7a2937
complete tabs and trailing whitespace formatting on frontend
koda
parents:
8206
diff
changeset
|
28 |
close(); |
ea4d6a7a2937
complete tabs and trailing whitespace formatting on frontend
koda
parents:
8206
diff
changeset
|
29 |
|
ea4d6a7a2937
complete tabs and trailing whitespace formatting on frontend
koda
parents:
8206
diff
changeset
|
30 |
if ((openMode & QIODevice::ReadWrite) == QIODevice::ReadWrite) { |
ea4d6a7a2937
complete tabs and trailing whitespace formatting on frontend
koda
parents:
8206
diff
changeset
|
31 |
m_handle = PHYSFS_openAppend(m_fileName.toUtf8().constData()); |
ea4d6a7a2937
complete tabs and trailing whitespace formatting on frontend
koda
parents:
8206
diff
changeset
|
32 |
if(m_handle) |
ea4d6a7a2937
complete tabs and trailing whitespace formatting on frontend
koda
parents:
8206
diff
changeset
|
33 |
{ |
ea4d6a7a2937
complete tabs and trailing whitespace formatting on frontend
koda
parents:
8206
diff
changeset
|
34 |
m_readWrite = true; |
ea4d6a7a2937
complete tabs and trailing whitespace formatting on frontend
koda
parents:
8206
diff
changeset
|
35 |
seek(0); |
ea4d6a7a2937
complete tabs and trailing whitespace formatting on frontend
koda
parents:
8206
diff
changeset
|
36 |
} |
ea4d6a7a2937
complete tabs and trailing whitespace formatting on frontend
koda
parents:
8206
diff
changeset
|
37 |
} |
ea4d6a7a2937
complete tabs and trailing whitespace formatting on frontend
koda
parents:
8206
diff
changeset
|
38 |
|
ea4d6a7a2937
complete tabs and trailing whitespace formatting on frontend
koda
parents:
8206
diff
changeset
|
39 |
else if (openMode & QIODevice::WriteOnly) { |
ea4d6a7a2937
complete tabs and trailing whitespace formatting on frontend
koda
parents:
8206
diff
changeset
|
40 |
m_handle = PHYSFS_openWrite(m_fileName.toUtf8().constData()); |
ea4d6a7a2937
complete tabs and trailing whitespace formatting on frontend
koda
parents:
8206
diff
changeset
|
41 |
m_flags = QAbstractFileEngine::WriteOwnerPerm | QAbstractFileEngine::WriteUserPerm | QAbstractFileEngine::FileType; |
ea4d6a7a2937
complete tabs and trailing whitespace formatting on frontend
koda
parents:
8206
diff
changeset
|
42 |
} |
ea4d6a7a2937
complete tabs and trailing whitespace formatting on frontend
koda
parents:
8206
diff
changeset
|
43 |
|
ea4d6a7a2937
complete tabs and trailing whitespace formatting on frontend
koda
parents:
8206
diff
changeset
|
44 |
else if (openMode & QIODevice::ReadOnly) { |
ea4d6a7a2937
complete tabs and trailing whitespace formatting on frontend
koda
parents:
8206
diff
changeset
|
45 |
m_handle = PHYSFS_openRead(m_fileName.toUtf8().constData()); |
ea4d6a7a2937
complete tabs and trailing whitespace formatting on frontend
koda
parents:
8206
diff
changeset
|
46 |
} |
ea4d6a7a2937
complete tabs and trailing whitespace formatting on frontend
koda
parents:
8206
diff
changeset
|
47 |
|
ea4d6a7a2937
complete tabs and trailing whitespace formatting on frontend
koda
parents:
8206
diff
changeset
|
48 |
else if (openMode & QIODevice::Append) { |
ea4d6a7a2937
complete tabs and trailing whitespace formatting on frontend
koda
parents:
8206
diff
changeset
|
49 |
m_handle = PHYSFS_openAppend(m_fileName.toUtf8().constData()); |
ea4d6a7a2937
complete tabs and trailing whitespace formatting on frontend
koda
parents:
8206
diff
changeset
|
50 |
} |
ea4d6a7a2937
complete tabs and trailing whitespace formatting on frontend
koda
parents:
8206
diff
changeset
|
51 |
|
ea4d6a7a2937
complete tabs and trailing whitespace formatting on frontend
koda
parents:
8206
diff
changeset
|
52 |
else { |
ea4d6a7a2937
complete tabs and trailing whitespace formatting on frontend
koda
parents:
8206
diff
changeset
|
53 |
qWarning("[PHYSFS] Bad file open mode: %d", (int)openMode); |
ea4d6a7a2937
complete tabs and trailing whitespace formatting on frontend
koda
parents:
8206
diff
changeset
|
54 |
} |
ea4d6a7a2937
complete tabs and trailing whitespace formatting on frontend
koda
parents:
8206
diff
changeset
|
55 |
|
ea4d6a7a2937
complete tabs and trailing whitespace formatting on frontend
koda
parents:
8206
diff
changeset
|
56 |
if (!m_handle) { |
9239 | 57 |
qWarning("%s", QString("[PHYSFS] Failed to open %1, reason: %2").arg(m_fileName).arg(FileEngineHandler::errorStr()).toLocal8Bit().constData()); |
8440
ea4d6a7a2937
complete tabs and trailing whitespace formatting on frontend
koda
parents:
8206
diff
changeset
|
58 |
return false; |
ea4d6a7a2937
complete tabs and trailing whitespace formatting on frontend
koda
parents:
8206
diff
changeset
|
59 |
} |
ea4d6a7a2937
complete tabs and trailing whitespace formatting on frontend
koda
parents:
8206
diff
changeset
|
60 |
|
ea4d6a7a2937
complete tabs and trailing whitespace formatting on frontend
koda
parents:
8206
diff
changeset
|
61 |
return true; |
ea4d6a7a2937
complete tabs and trailing whitespace formatting on frontend
koda
parents:
8206
diff
changeset
|
62 |
} |
ea4d6a7a2937
complete tabs and trailing whitespace formatting on frontend
koda
parents:
8206
diff
changeset
|
63 |
|
ea4d6a7a2937
complete tabs and trailing whitespace formatting on frontend
koda
parents:
8206
diff
changeset
|
64 |
bool FileEngine::close() |
ea4d6a7a2937
complete tabs and trailing whitespace formatting on frontend
koda
parents:
8206
diff
changeset
|
65 |
{ |
ea4d6a7a2937
complete tabs and trailing whitespace formatting on frontend
koda
parents:
8206
diff
changeset
|
66 |
if (isOpened()) { |
ea4d6a7a2937
complete tabs and trailing whitespace formatting on frontend
koda
parents:
8206
diff
changeset
|
67 |
int result = PHYSFS_close(m_handle); |
ea4d6a7a2937
complete tabs and trailing whitespace formatting on frontend
koda
parents:
8206
diff
changeset
|
68 |
m_handle = NULL; |
ea4d6a7a2937
complete tabs and trailing whitespace formatting on frontend
koda
parents:
8206
diff
changeset
|
69 |
return result != 0; |
ea4d6a7a2937
complete tabs and trailing whitespace formatting on frontend
koda
parents:
8206
diff
changeset
|
70 |
} |
ea4d6a7a2937
complete tabs and trailing whitespace formatting on frontend
koda
parents:
8206
diff
changeset
|
71 |
|
ea4d6a7a2937
complete tabs and trailing whitespace formatting on frontend
koda
parents:
8206
diff
changeset
|
72 |
return true; |
ea4d6a7a2937
complete tabs and trailing whitespace formatting on frontend
koda
parents:
8206
diff
changeset
|
73 |
} |
ea4d6a7a2937
complete tabs and trailing whitespace formatting on frontend
koda
parents:
8206
diff
changeset
|
74 |
|
ea4d6a7a2937
complete tabs and trailing whitespace formatting on frontend
koda
parents:
8206
diff
changeset
|
75 |
bool FileEngine::flush() |
ea4d6a7a2937
complete tabs and trailing whitespace formatting on frontend
koda
parents:
8206
diff
changeset
|
76 |
{ |
ea4d6a7a2937
complete tabs and trailing whitespace formatting on frontend
koda
parents:
8206
diff
changeset
|
77 |
return PHYSFS_flush(m_handle) != 0; |
ea4d6a7a2937
complete tabs and trailing whitespace formatting on frontend
koda
parents:
8206
diff
changeset
|
78 |
} |
ea4d6a7a2937
complete tabs and trailing whitespace formatting on frontend
koda
parents:
8206
diff
changeset
|
79 |
|
ea4d6a7a2937
complete tabs and trailing whitespace formatting on frontend
koda
parents:
8206
diff
changeset
|
80 |
qint64 FileEngine::size() const |
ea4d6a7a2937
complete tabs and trailing whitespace formatting on frontend
koda
parents:
8206
diff
changeset
|
81 |
{ |
ea4d6a7a2937
complete tabs and trailing whitespace formatting on frontend
koda
parents:
8206
diff
changeset
|
82 |
return m_size; |
ea4d6a7a2937
complete tabs and trailing whitespace formatting on frontend
koda
parents:
8206
diff
changeset
|
83 |
} |
ea4d6a7a2937
complete tabs and trailing whitespace formatting on frontend
koda
parents:
8206
diff
changeset
|
84 |
|
ea4d6a7a2937
complete tabs and trailing whitespace formatting on frontend
koda
parents:
8206
diff
changeset
|
85 |
qint64 FileEngine::pos() const |
ea4d6a7a2937
complete tabs and trailing whitespace formatting on frontend
koda
parents:
8206
diff
changeset
|
86 |
{ |
ea4d6a7a2937
complete tabs and trailing whitespace formatting on frontend
koda
parents:
8206
diff
changeset
|
87 |
return PHYSFS_tell(m_handle); |
ea4d6a7a2937
complete tabs and trailing whitespace formatting on frontend
koda
parents:
8206
diff
changeset
|
88 |
} |
ea4d6a7a2937
complete tabs and trailing whitespace formatting on frontend
koda
parents:
8206
diff
changeset
|
89 |
|
ea4d6a7a2937
complete tabs and trailing whitespace formatting on frontend
koda
parents:
8206
diff
changeset
|
90 |
bool FileEngine::setSize(qint64 size) |
ea4d6a7a2937
complete tabs and trailing whitespace formatting on frontend
koda
parents:
8206
diff
changeset
|
91 |
{ |
ea4d6a7a2937
complete tabs and trailing whitespace formatting on frontend
koda
parents:
8206
diff
changeset
|
92 |
if(size == 0) |
ea4d6a7a2937
complete tabs and trailing whitespace formatting on frontend
koda
parents:
8206
diff
changeset
|
93 |
{ |
ea4d6a7a2937
complete tabs and trailing whitespace formatting on frontend
koda
parents:
8206
diff
changeset
|
94 |
m_size = 0; |
ea4d6a7a2937
complete tabs and trailing whitespace formatting on frontend
koda
parents:
8206
diff
changeset
|
95 |
return open(QIODevice::WriteOnly); |
ea4d6a7a2937
complete tabs and trailing whitespace formatting on frontend
koda
parents:
8206
diff
changeset
|
96 |
} |
ea4d6a7a2937
complete tabs and trailing whitespace formatting on frontend
koda
parents:
8206
diff
changeset
|
97 |
else |
ea4d6a7a2937
complete tabs and trailing whitespace formatting on frontend
koda
parents:
8206
diff
changeset
|
98 |
return false; |
ea4d6a7a2937
complete tabs and trailing whitespace formatting on frontend
koda
parents:
8206
diff
changeset
|
99 |
} |
ea4d6a7a2937
complete tabs and trailing whitespace formatting on frontend
koda
parents:
8206
diff
changeset
|
100 |
|
ea4d6a7a2937
complete tabs and trailing whitespace formatting on frontend
koda
parents:
8206
diff
changeset
|
101 |
bool FileEngine::seek(qint64 pos) |
ea4d6a7a2937
complete tabs and trailing whitespace formatting on frontend
koda
parents:
8206
diff
changeset
|
102 |
{ |
ea4d6a7a2937
complete tabs and trailing whitespace formatting on frontend
koda
parents:
8206
diff
changeset
|
103 |
bool ok = PHYSFS_seek(m_handle, pos) != 0; |
ea4d6a7a2937
complete tabs and trailing whitespace formatting on frontend
koda
parents:
8206
diff
changeset
|
104 |
|
ea4d6a7a2937
complete tabs and trailing whitespace formatting on frontend
koda
parents:
8206
diff
changeset
|
105 |
return ok; |
ea4d6a7a2937
complete tabs and trailing whitespace formatting on frontend
koda
parents:
8206
diff
changeset
|
106 |
} |
ea4d6a7a2937
complete tabs and trailing whitespace formatting on frontend
koda
parents:
8206
diff
changeset
|
107 |
|
ea4d6a7a2937
complete tabs and trailing whitespace formatting on frontend
koda
parents:
8206
diff
changeset
|
108 |
bool FileEngine::isSequential() const |
ea4d6a7a2937
complete tabs and trailing whitespace formatting on frontend
koda
parents:
8206
diff
changeset
|
109 |
{ |
ea4d6a7a2937
complete tabs and trailing whitespace formatting on frontend
koda
parents:
8206
diff
changeset
|
110 |
return false; |
ea4d6a7a2937
complete tabs and trailing whitespace formatting on frontend
koda
parents:
8206
diff
changeset
|
111 |
} |
ea4d6a7a2937
complete tabs and trailing whitespace formatting on frontend
koda
parents:
8206
diff
changeset
|
112 |
|
ea4d6a7a2937
complete tabs and trailing whitespace formatting on frontend
koda
parents:
8206
diff
changeset
|
113 |
bool FileEngine::remove() |
ea4d6a7a2937
complete tabs and trailing whitespace formatting on frontend
koda
parents:
8206
diff
changeset
|
114 |
{ |
ea4d6a7a2937
complete tabs and trailing whitespace formatting on frontend
koda
parents:
8206
diff
changeset
|
115 |
return PHYSFS_delete(m_fileName.toUtf8().constData()) != 0; |
ea4d6a7a2937
complete tabs and trailing whitespace formatting on frontend
koda
parents:
8206
diff
changeset
|
116 |
} |
ea4d6a7a2937
complete tabs and trailing whitespace formatting on frontend
koda
parents:
8206
diff
changeset
|
117 |
|
ea4d6a7a2937
complete tabs and trailing whitespace formatting on frontend
koda
parents:
8206
diff
changeset
|
118 |
bool FileEngine::mkdir(const QString &dirName, bool createParentDirectories) const |
ea4d6a7a2937
complete tabs and trailing whitespace formatting on frontend
koda
parents:
8206
diff
changeset
|
119 |
{ |
ea4d6a7a2937
complete tabs and trailing whitespace formatting on frontend
koda
parents:
8206
diff
changeset
|
120 |
Q_UNUSED(createParentDirectories); |
ea4d6a7a2937
complete tabs and trailing whitespace formatting on frontend
koda
parents:
8206
diff
changeset
|
121 |
|
ea4d6a7a2937
complete tabs and trailing whitespace formatting on frontend
koda
parents:
8206
diff
changeset
|
122 |
return PHYSFS_mkdir(dirName.toUtf8().constData()) != 0; |
ea4d6a7a2937
complete tabs and trailing whitespace formatting on frontend
koda
parents:
8206
diff
changeset
|
123 |
} |
ea4d6a7a2937
complete tabs and trailing whitespace formatting on frontend
koda
parents:
8206
diff
changeset
|
124 |
|
ea4d6a7a2937
complete tabs and trailing whitespace formatting on frontend
koda
parents:
8206
diff
changeset
|
125 |
bool FileEngine::rmdir(const QString &dirName, bool recurseParentDirectories) const |
ea4d6a7a2937
complete tabs and trailing whitespace formatting on frontend
koda
parents:
8206
diff
changeset
|
126 |
{ |
ea4d6a7a2937
complete tabs and trailing whitespace formatting on frontend
koda
parents:
8206
diff
changeset
|
127 |
Q_UNUSED(recurseParentDirectories); |
ea4d6a7a2937
complete tabs and trailing whitespace formatting on frontend
koda
parents:
8206
diff
changeset
|
128 |
|
ea4d6a7a2937
complete tabs and trailing whitespace formatting on frontend
koda
parents:
8206
diff
changeset
|
129 |
return PHYSFS_delete(dirName.toUtf8().constData()) != 0; |
ea4d6a7a2937
complete tabs and trailing whitespace formatting on frontend
koda
parents:
8206
diff
changeset
|
130 |
} |
ea4d6a7a2937
complete tabs and trailing whitespace formatting on frontend
koda
parents:
8206
diff
changeset
|
131 |
|
ea4d6a7a2937
complete tabs and trailing whitespace formatting on frontend
koda
parents:
8206
diff
changeset
|
132 |
bool FileEngine::caseSensitive() const |
ea4d6a7a2937
complete tabs and trailing whitespace formatting on frontend
koda
parents:
8206
diff
changeset
|
133 |
{ |
ea4d6a7a2937
complete tabs and trailing whitespace formatting on frontend
koda
parents:
8206
diff
changeset
|
134 |
return true; |
ea4d6a7a2937
complete tabs and trailing whitespace formatting on frontend
koda
parents:
8206
diff
changeset
|
135 |
} |
ea4d6a7a2937
complete tabs and trailing whitespace formatting on frontend
koda
parents:
8206
diff
changeset
|
136 |
|
ea4d6a7a2937
complete tabs and trailing whitespace formatting on frontend
koda
parents:
8206
diff
changeset
|
137 |
bool FileEngine::isRelativePath() const |
ea4d6a7a2937
complete tabs and trailing whitespace formatting on frontend
koda
parents:
8206
diff
changeset
|
138 |
{ |
ea4d6a7a2937
complete tabs and trailing whitespace formatting on frontend
koda
parents:
8206
diff
changeset
|
139 |
return false; |
ea4d6a7a2937
complete tabs and trailing whitespace formatting on frontend
koda
parents:
8206
diff
changeset
|
140 |
} |
ea4d6a7a2937
complete tabs and trailing whitespace formatting on frontend
koda
parents:
8206
diff
changeset
|
141 |
|
ea4d6a7a2937
complete tabs and trailing whitespace formatting on frontend
koda
parents:
8206
diff
changeset
|
142 |
QAbstractFileEngineIterator * FileEngine::beginEntryList(QDir::Filters filters, const QStringList &filterNames) |
ea4d6a7a2937
complete tabs and trailing whitespace formatting on frontend
koda
parents:
8206
diff
changeset
|
143 |
{ |
ea4d6a7a2937
complete tabs and trailing whitespace formatting on frontend
koda
parents:
8206
diff
changeset
|
144 |
return new FileEngineIterator(filters, filterNames, entryList(filters, filterNames)); |
ea4d6a7a2937
complete tabs and trailing whitespace formatting on frontend
koda
parents:
8206
diff
changeset
|
145 |
} |
ea4d6a7a2937
complete tabs and trailing whitespace formatting on frontend
koda
parents:
8206
diff
changeset
|
146 |
|
ea4d6a7a2937
complete tabs and trailing whitespace formatting on frontend
koda
parents:
8206
diff
changeset
|
147 |
QStringList FileEngine::entryList(QDir::Filters filters, const QStringList &filterNames) const |
ea4d6a7a2937
complete tabs and trailing whitespace formatting on frontend
koda
parents:
8206
diff
changeset
|
148 |
{ |
ea4d6a7a2937
complete tabs and trailing whitespace formatting on frontend
koda
parents:
8206
diff
changeset
|
149 |
Q_UNUSED(filters); |
ea4d6a7a2937
complete tabs and trailing whitespace formatting on frontend
koda
parents:
8206
diff
changeset
|
150 |
|
ea4d6a7a2937
complete tabs and trailing whitespace formatting on frontend
koda
parents:
8206
diff
changeset
|
151 |
QString file; |
ea4d6a7a2937
complete tabs and trailing whitespace formatting on frontend
koda
parents:
8206
diff
changeset
|
152 |
QStringList result; |
ea4d6a7a2937
complete tabs and trailing whitespace formatting on frontend
koda
parents:
8206
diff
changeset
|
153 |
char **files = PHYSFS_enumerateFiles(m_fileName.toUtf8().constData()); |
ea4d6a7a2937
complete tabs and trailing whitespace formatting on frontend
koda
parents:
8206
diff
changeset
|
154 |
|
ea4d6a7a2937
complete tabs and trailing whitespace formatting on frontend
koda
parents:
8206
diff
changeset
|
155 |
for (char **i = files; *i != NULL; i++) { |
ea4d6a7a2937
complete tabs and trailing whitespace formatting on frontend
koda
parents:
8206
diff
changeset
|
156 |
file = QString::fromUtf8(*i); |
ea4d6a7a2937
complete tabs and trailing whitespace formatting on frontend
koda
parents:
8206
diff
changeset
|
157 |
|
ea4d6a7a2937
complete tabs and trailing whitespace formatting on frontend
koda
parents:
8206
diff
changeset
|
158 |
if (filterNames.isEmpty() || QDir::match(filterNames, file)) { |
ea4d6a7a2937
complete tabs and trailing whitespace formatting on frontend
koda
parents:
8206
diff
changeset
|
159 |
result << file; |
ea4d6a7a2937
complete tabs and trailing whitespace formatting on frontend
koda
parents:
8206
diff
changeset
|
160 |
} |
ea4d6a7a2937
complete tabs and trailing whitespace formatting on frontend
koda
parents:
8206
diff
changeset
|
161 |
} |
ea4d6a7a2937
complete tabs and trailing whitespace formatting on frontend
koda
parents:
8206
diff
changeset
|
162 |
|
ea4d6a7a2937
complete tabs and trailing whitespace formatting on frontend
koda
parents:
8206
diff
changeset
|
163 |
PHYSFS_freeList(files); |
ea4d6a7a2937
complete tabs and trailing whitespace formatting on frontend
koda
parents:
8206
diff
changeset
|
164 |
|
ea4d6a7a2937
complete tabs and trailing whitespace formatting on frontend
koda
parents:
8206
diff
changeset
|
165 |
return result; |
ea4d6a7a2937
complete tabs and trailing whitespace formatting on frontend
koda
parents:
8206
diff
changeset
|
166 |
} |
ea4d6a7a2937
complete tabs and trailing whitespace formatting on frontend
koda
parents:
8206
diff
changeset
|
167 |
|
ea4d6a7a2937
complete tabs and trailing whitespace formatting on frontend
koda
parents:
8206
diff
changeset
|
168 |
QAbstractFileEngine::FileFlags FileEngine::fileFlags(FileFlags type) const |
ea4d6a7a2937
complete tabs and trailing whitespace formatting on frontend
koda
parents:
8206
diff
changeset
|
169 |
{ |
ea4d6a7a2937
complete tabs and trailing whitespace formatting on frontend
koda
parents:
8206
diff
changeset
|
170 |
return type & m_flags; |
ea4d6a7a2937
complete tabs and trailing whitespace formatting on frontend
koda
parents:
8206
diff
changeset
|
171 |
} |
ea4d6a7a2937
complete tabs and trailing whitespace formatting on frontend
koda
parents:
8206
diff
changeset
|
172 |
|
ea4d6a7a2937
complete tabs and trailing whitespace formatting on frontend
koda
parents:
8206
diff
changeset
|
173 |
QString FileEngine::fileName(FileName file) const |
ea4d6a7a2937
complete tabs and trailing whitespace formatting on frontend
koda
parents:
8206
diff
changeset
|
174 |
{ |
ea4d6a7a2937
complete tabs and trailing whitespace formatting on frontend
koda
parents:
8206
diff
changeset
|
175 |
switch(file) |
ea4d6a7a2937
complete tabs and trailing whitespace formatting on frontend
koda
parents:
8206
diff
changeset
|
176 |
{ |
ea4d6a7a2937
complete tabs and trailing whitespace formatting on frontend
koda
parents:
8206
diff
changeset
|
177 |
case QAbstractFileEngine::AbsolutePathName: |
ea4d6a7a2937
complete tabs and trailing whitespace formatting on frontend
koda
parents:
8206
diff
changeset
|
178 |
{ |
ea4d6a7a2937
complete tabs and trailing whitespace formatting on frontend
koda
parents:
8206
diff
changeset
|
179 |
QString s(PHYSFS_getWriteDir()); |
ea4d6a7a2937
complete tabs and trailing whitespace formatting on frontend
koda
parents:
8206
diff
changeset
|
180 |
return s; |
ea4d6a7a2937
complete tabs and trailing whitespace formatting on frontend
koda
parents:
8206
diff
changeset
|
181 |
} |
ea4d6a7a2937
complete tabs and trailing whitespace formatting on frontend
koda
parents:
8206
diff
changeset
|
182 |
case QAbstractFileEngine::BaseName: |
ea4d6a7a2937
complete tabs and trailing whitespace formatting on frontend
koda
parents:
8206
diff
changeset
|
183 |
{ |
ea4d6a7a2937
complete tabs and trailing whitespace formatting on frontend
koda
parents:
8206
diff
changeset
|
184 |
int l = m_fileName.lastIndexOf('/'); |
ea4d6a7a2937
complete tabs and trailing whitespace formatting on frontend
koda
parents:
8206
diff
changeset
|
185 |
QString s = m_fileName.mid(l + 1); |
ea4d6a7a2937
complete tabs and trailing whitespace formatting on frontend
koda
parents:
8206
diff
changeset
|
186 |
return s; |
ea4d6a7a2937
complete tabs and trailing whitespace formatting on frontend
koda
parents:
8206
diff
changeset
|
187 |
} |
ea4d6a7a2937
complete tabs and trailing whitespace formatting on frontend
koda
parents:
8206
diff
changeset
|
188 |
case QAbstractFileEngine::DefaultName: |
ea4d6a7a2937
complete tabs and trailing whitespace formatting on frontend
koda
parents:
8206
diff
changeset
|
189 |
case QAbstractFileEngine::AbsoluteName: |
ea4d6a7a2937
complete tabs and trailing whitespace formatting on frontend
koda
parents:
8206
diff
changeset
|
190 |
default: |
ea4d6a7a2937
complete tabs and trailing whitespace formatting on frontend
koda
parents:
8206
diff
changeset
|
191 |
{ |
ea4d6a7a2937
complete tabs and trailing whitespace formatting on frontend
koda
parents:
8206
diff
changeset
|
192 |
QString s = "physfs:/" + m_fileName; |
ea4d6a7a2937
complete tabs and trailing whitespace formatting on frontend
koda
parents:
8206
diff
changeset
|
193 |
return s; |
ea4d6a7a2937
complete tabs and trailing whitespace formatting on frontend
koda
parents:
8206
diff
changeset
|
194 |
} |
ea4d6a7a2937
complete tabs and trailing whitespace formatting on frontend
koda
parents:
8206
diff
changeset
|
195 |
} |
ea4d6a7a2937
complete tabs and trailing whitespace formatting on frontend
koda
parents:
8206
diff
changeset
|
196 |
} |
ea4d6a7a2937
complete tabs and trailing whitespace formatting on frontend
koda
parents:
8206
diff
changeset
|
197 |
|
ea4d6a7a2937
complete tabs and trailing whitespace formatting on frontend
koda
parents:
8206
diff
changeset
|
198 |
QDateTime FileEngine::fileTime(FileTime time) const |
ea4d6a7a2937
complete tabs and trailing whitespace formatting on frontend
koda
parents:
8206
diff
changeset
|
199 |
{ |
ea4d6a7a2937
complete tabs and trailing whitespace formatting on frontend
koda
parents:
8206
diff
changeset
|
200 |
switch (time) |
ea4d6a7a2937
complete tabs and trailing whitespace formatting on frontend
koda
parents:
8206
diff
changeset
|
201 |
{ |
ea4d6a7a2937
complete tabs and trailing whitespace formatting on frontend
koda
parents:
8206
diff
changeset
|
202 |
case QAbstractFileEngine::ModificationTime: |
ea4d6a7a2937
complete tabs and trailing whitespace formatting on frontend
koda
parents:
8206
diff
changeset
|
203 |
default: |
ea4d6a7a2937
complete tabs and trailing whitespace formatting on frontend
koda
parents:
8206
diff
changeset
|
204 |
return m_date; |
ea4d6a7a2937
complete tabs and trailing whitespace formatting on frontend
koda
parents:
8206
diff
changeset
|
205 |
break; |
ea4d6a7a2937
complete tabs and trailing whitespace formatting on frontend
koda
parents:
8206
diff
changeset
|
206 |
}; |
ea4d6a7a2937
complete tabs and trailing whitespace formatting on frontend
koda
parents:
8206
diff
changeset
|
207 |
} |
ea4d6a7a2937
complete tabs and trailing whitespace formatting on frontend
koda
parents:
8206
diff
changeset
|
208 |
|
ea4d6a7a2937
complete tabs and trailing whitespace formatting on frontend
koda
parents:
8206
diff
changeset
|
209 |
void FileEngine::setFileName(const QString &file) |
ea4d6a7a2937
complete tabs and trailing whitespace formatting on frontend
koda
parents:
8206
diff
changeset
|
210 |
{ |
ea4d6a7a2937
complete tabs and trailing whitespace formatting on frontend
koda
parents:
8206
diff
changeset
|
211 |
if(file.startsWith(FileEngineHandler::scheme)) |
ea4d6a7a2937
complete tabs and trailing whitespace formatting on frontend
koda
parents:
8206
diff
changeset
|
212 |
m_fileName = file.mid(FileEngineHandler::scheme.size()); |
ea4d6a7a2937
complete tabs and trailing whitespace formatting on frontend
koda
parents:
8206
diff
changeset
|
213 |
else |
ea4d6a7a2937
complete tabs and trailing whitespace formatting on frontend
koda
parents:
8206
diff
changeset
|
214 |
m_fileName = file; |
ea4d6a7a2937
complete tabs and trailing whitespace formatting on frontend
koda
parents:
8206
diff
changeset
|
215 |
PHYSFS_Stat stat; |
ea4d6a7a2937
complete tabs and trailing whitespace formatting on frontend
koda
parents:
8206
diff
changeset
|
216 |
if (PHYSFS_stat(m_fileName.toUtf8().constData(), &stat) != 0) { |
ea4d6a7a2937
complete tabs and trailing whitespace formatting on frontend
koda
parents:
8206
diff
changeset
|
217 |
m_size = stat.filesize; |
ea4d6a7a2937
complete tabs and trailing whitespace formatting on frontend
koda
parents:
8206
diff
changeset
|
218 |
m_date = QDateTime::fromTime_t(stat.modtime); |
ea4d6a7a2937
complete tabs and trailing whitespace formatting on frontend
koda
parents:
8206
diff
changeset
|
219 |
// m_flags |= QAbstractFileEngine::WriteOwnerPerm; |
ea4d6a7a2937
complete tabs and trailing whitespace formatting on frontend
koda
parents:
8206
diff
changeset
|
220 |
m_flags |= QAbstractFileEngine::ReadOwnerPerm; |
ea4d6a7a2937
complete tabs and trailing whitespace formatting on frontend
koda
parents:
8206
diff
changeset
|
221 |
m_flags |= QAbstractFileEngine::ReadUserPerm; |
ea4d6a7a2937
complete tabs and trailing whitespace formatting on frontend
koda
parents:
8206
diff
changeset
|
222 |
m_flags |= QAbstractFileEngine::ExistsFlag; |
ea4d6a7a2937
complete tabs and trailing whitespace formatting on frontend
koda
parents:
8206
diff
changeset
|
223 |
m_flags |= QAbstractFileEngine::LocalDiskFlag; |
ea4d6a7a2937
complete tabs and trailing whitespace formatting on frontend
koda
parents:
8206
diff
changeset
|
224 |
|
ea4d6a7a2937
complete tabs and trailing whitespace formatting on frontend
koda
parents:
8206
diff
changeset
|
225 |
switch (stat.filetype) |
ea4d6a7a2937
complete tabs and trailing whitespace formatting on frontend
koda
parents:
8206
diff
changeset
|
226 |
{ |
ea4d6a7a2937
complete tabs and trailing whitespace formatting on frontend
koda
parents:
8206
diff
changeset
|
227 |
case PHYSFS_FILETYPE_REGULAR: |
ea4d6a7a2937
complete tabs and trailing whitespace formatting on frontend
koda
parents:
8206
diff
changeset
|
228 |
m_flags |= QAbstractFileEngine::FileType; |
ea4d6a7a2937
complete tabs and trailing whitespace formatting on frontend
koda
parents:
8206
diff
changeset
|
229 |
break; |
ea4d6a7a2937
complete tabs and trailing whitespace formatting on frontend
koda
parents:
8206
diff
changeset
|
230 |
case PHYSFS_FILETYPE_DIRECTORY: |
ea4d6a7a2937
complete tabs and trailing whitespace formatting on frontend
koda
parents:
8206
diff
changeset
|
231 |
m_flags |= QAbstractFileEngine::DirectoryType; |
ea4d6a7a2937
complete tabs and trailing whitespace formatting on frontend
koda
parents:
8206
diff
changeset
|
232 |
break; |
ea4d6a7a2937
complete tabs and trailing whitespace formatting on frontend
koda
parents:
8206
diff
changeset
|
233 |
case PHYSFS_FILETYPE_SYMLINK: |
ea4d6a7a2937
complete tabs and trailing whitespace formatting on frontend
koda
parents:
8206
diff
changeset
|
234 |
m_flags |= QAbstractFileEngine::LinkType; |
ea4d6a7a2937
complete tabs and trailing whitespace formatting on frontend
koda
parents:
8206
diff
changeset
|
235 |
break; |
ea4d6a7a2937
complete tabs and trailing whitespace formatting on frontend
koda
parents:
8206
diff
changeset
|
236 |
default: ; |
ea4d6a7a2937
complete tabs and trailing whitespace formatting on frontend
koda
parents:
8206
diff
changeset
|
237 |
} |
ea4d6a7a2937
complete tabs and trailing whitespace formatting on frontend
koda
parents:
8206
diff
changeset
|
238 |
} |
ea4d6a7a2937
complete tabs and trailing whitespace formatting on frontend
koda
parents:
8206
diff
changeset
|
239 |
} |
ea4d6a7a2937
complete tabs and trailing whitespace formatting on frontend
koda
parents:
8206
diff
changeset
|
240 |
|
ea4d6a7a2937
complete tabs and trailing whitespace formatting on frontend
koda
parents:
8206
diff
changeset
|
241 |
bool FileEngine::atEnd() const |
ea4d6a7a2937
complete tabs and trailing whitespace formatting on frontend
koda
parents:
8206
diff
changeset
|
242 |
{ |
ea4d6a7a2937
complete tabs and trailing whitespace formatting on frontend
koda
parents:
8206
diff
changeset
|
243 |
return PHYSFS_eof(m_handle) != 0; |
ea4d6a7a2937
complete tabs and trailing whitespace formatting on frontend
koda
parents:
8206
diff
changeset
|
244 |
} |
ea4d6a7a2937
complete tabs and trailing whitespace formatting on frontend
koda
parents:
8206
diff
changeset
|
245 |
|
ea4d6a7a2937
complete tabs and trailing whitespace formatting on frontend
koda
parents:
8206
diff
changeset
|
246 |
qint64 FileEngine::read(char *data, qint64 maxlen) |
ea4d6a7a2937
complete tabs and trailing whitespace formatting on frontend
koda
parents:
8206
diff
changeset
|
247 |
{ |
ea4d6a7a2937
complete tabs and trailing whitespace formatting on frontend
koda
parents:
8206
diff
changeset
|
248 |
if(m_readWrite) |
ea4d6a7a2937
complete tabs and trailing whitespace formatting on frontend
koda
parents:
8206
diff
changeset
|
249 |
{ |
ea4d6a7a2937
complete tabs and trailing whitespace formatting on frontend
koda
parents:
8206
diff
changeset
|
250 |
if(pos() == 0) |
ea4d6a7a2937
complete tabs and trailing whitespace formatting on frontend
koda
parents:
8206
diff
changeset
|
251 |
open(QIODevice::ReadOnly); |
ea4d6a7a2937
complete tabs and trailing whitespace formatting on frontend
koda
parents:
8206
diff
changeset
|
252 |
else |
ea4d6a7a2937
complete tabs and trailing whitespace formatting on frontend
koda
parents:
8206
diff
changeset
|
253 |
return -1; |
ea4d6a7a2937
complete tabs and trailing whitespace formatting on frontend
koda
parents:
8206
diff
changeset
|
254 |
} |
ea4d6a7a2937
complete tabs and trailing whitespace formatting on frontend
koda
parents:
8206
diff
changeset
|
255 |
|
ea4d6a7a2937
complete tabs and trailing whitespace formatting on frontend
koda
parents:
8206
diff
changeset
|
256 |
qint64 len = PHYSFS_readBytes(m_handle, data, maxlen); |
ea4d6a7a2937
complete tabs and trailing whitespace formatting on frontend
koda
parents:
8206
diff
changeset
|
257 |
return len; |
ea4d6a7a2937
complete tabs and trailing whitespace formatting on frontend
koda
parents:
8206
diff
changeset
|
258 |
} |
ea4d6a7a2937
complete tabs and trailing whitespace formatting on frontend
koda
parents:
8206
diff
changeset
|
259 |
|
ea4d6a7a2937
complete tabs and trailing whitespace formatting on frontend
koda
parents:
8206
diff
changeset
|
260 |
qint64 FileEngine::readLine(char *data, qint64 maxlen) |
ea4d6a7a2937
complete tabs and trailing whitespace formatting on frontend
koda
parents:
8206
diff
changeset
|
261 |
{ |
ea4d6a7a2937
complete tabs and trailing whitespace formatting on frontend
koda
parents:
8206
diff
changeset
|
262 |
if(!m_bufferSet) |
ea4d6a7a2937
complete tabs and trailing whitespace formatting on frontend
koda
parents:
8206
diff
changeset
|
263 |
{ |
ea4d6a7a2937
complete tabs and trailing whitespace formatting on frontend
koda
parents:
8206
diff
changeset
|
264 |
PHYSFS_setBuffer(m_handle, 4096); |
ea4d6a7a2937
complete tabs and trailing whitespace formatting on frontend
koda
parents:
8206
diff
changeset
|
265 |
m_bufferSet = true; |
ea4d6a7a2937
complete tabs and trailing whitespace formatting on frontend
koda
parents:
8206
diff
changeset
|
266 |
} |
ea4d6a7a2937
complete tabs and trailing whitespace formatting on frontend
koda
parents:
8206
diff
changeset
|
267 |
|
ea4d6a7a2937
complete tabs and trailing whitespace formatting on frontend
koda
parents:
8206
diff
changeset
|
268 |
qint64 bytesRead = 0; |
ea4d6a7a2937
complete tabs and trailing whitespace formatting on frontend
koda
parents:
8206
diff
changeset
|
269 |
while(PHYSFS_readBytes(m_handle, data, 1) |
ea4d6a7a2937
complete tabs and trailing whitespace formatting on frontend
koda
parents:
8206
diff
changeset
|
270 |
&& maxlen |
ea4d6a7a2937
complete tabs and trailing whitespace formatting on frontend
koda
parents:
8206
diff
changeset
|
271 |
&& (*data == '\n')) |
ea4d6a7a2937
complete tabs and trailing whitespace formatting on frontend
koda
parents:
8206
diff
changeset
|
272 |
{ |
ea4d6a7a2937
complete tabs and trailing whitespace formatting on frontend
koda
parents:
8206
diff
changeset
|
273 |
++data; |
ea4d6a7a2937
complete tabs and trailing whitespace formatting on frontend
koda
parents:
8206
diff
changeset
|
274 |
--maxlen; |
ea4d6a7a2937
complete tabs and trailing whitespace formatting on frontend
koda
parents:
8206
diff
changeset
|
275 |
++bytesRead; |
ea4d6a7a2937
complete tabs and trailing whitespace formatting on frontend
koda
parents:
8206
diff
changeset
|
276 |
} |
ea4d6a7a2937
complete tabs and trailing whitespace formatting on frontend
koda
parents:
8206
diff
changeset
|
277 |
|
ea4d6a7a2937
complete tabs and trailing whitespace formatting on frontend
koda
parents:
8206
diff
changeset
|
278 |
return bytesRead; |
ea4d6a7a2937
complete tabs and trailing whitespace formatting on frontend
koda
parents:
8206
diff
changeset
|
279 |
} |
ea4d6a7a2937
complete tabs and trailing whitespace formatting on frontend
koda
parents:
8206
diff
changeset
|
280 |
|
ea4d6a7a2937
complete tabs and trailing whitespace formatting on frontend
koda
parents:
8206
diff
changeset
|
281 |
qint64 FileEngine::write(const char *data, qint64 len) |
ea4d6a7a2937
complete tabs and trailing whitespace formatting on frontend
koda
parents:
8206
diff
changeset
|
282 |
{ |
ea4d6a7a2937
complete tabs and trailing whitespace formatting on frontend
koda
parents:
8206
diff
changeset
|
283 |
return PHYSFS_writeBytes(m_handle, data, len); |
ea4d6a7a2937
complete tabs and trailing whitespace formatting on frontend
koda
parents:
8206
diff
changeset
|
284 |
} |
ea4d6a7a2937
complete tabs and trailing whitespace formatting on frontend
koda
parents:
8206
diff
changeset
|
285 |
|
ea4d6a7a2937
complete tabs and trailing whitespace formatting on frontend
koda
parents:
8206
diff
changeset
|
286 |
bool FileEngine::isOpened() const |
ea4d6a7a2937
complete tabs and trailing whitespace formatting on frontend
koda
parents:
8206
diff
changeset
|
287 |
{ |
ea4d6a7a2937
complete tabs and trailing whitespace formatting on frontend
koda
parents:
8206
diff
changeset
|
288 |
return m_handle != NULL; |
ea4d6a7a2937
complete tabs and trailing whitespace formatting on frontend
koda
parents:
8206
diff
changeset
|
289 |
} |
ea4d6a7a2937
complete tabs and trailing whitespace formatting on frontend
koda
parents:
8206
diff
changeset
|
290 |
|
ea4d6a7a2937
complete tabs and trailing whitespace formatting on frontend
koda
parents:
8206
diff
changeset
|
291 |
QFile::FileError FileEngine::error() const |
ea4d6a7a2937
complete tabs and trailing whitespace formatting on frontend
koda
parents:
8206
diff
changeset
|
292 |
{ |
ea4d6a7a2937
complete tabs and trailing whitespace formatting on frontend
koda
parents:
8206
diff
changeset
|
293 |
return QFile::UnspecifiedError; |
ea4d6a7a2937
complete tabs and trailing whitespace formatting on frontend
koda
parents:
8206
diff
changeset
|
294 |
} |
ea4d6a7a2937
complete tabs and trailing whitespace formatting on frontend
koda
parents:
8206
diff
changeset
|
295 |
|
ea4d6a7a2937
complete tabs and trailing whitespace formatting on frontend
koda
parents:
8206
diff
changeset
|
296 |
QString FileEngine::errorString() const |
ea4d6a7a2937
complete tabs and trailing whitespace formatting on frontend
koda
parents:
8206
diff
changeset
|
297 |
{ |
12729
d47ab9245259
Fix PhysFS 3.0.0 deprecation warnings for error reporting
Wuzzy <Wuzzy2@mail.ru>
parents:
10235
diff
changeset
|
298 |
#if PHYSFS_VER_MAJOR >= 3 |
d47ab9245259
Fix PhysFS 3.0.0 deprecation warnings for error reporting
Wuzzy <Wuzzy2@mail.ru>
parents:
10235
diff
changeset
|
299 |
return PHYSFS_getErrorByCode(PHYSFS_getLastErrorCode()); |
d47ab9245259
Fix PhysFS 3.0.0 deprecation warnings for error reporting
Wuzzy <Wuzzy2@mail.ru>
parents:
10235
diff
changeset
|
300 |
#else |
8440
ea4d6a7a2937
complete tabs and trailing whitespace formatting on frontend
koda
parents:
8206
diff
changeset
|
301 |
return PHYSFS_getLastError(); |
12729
d47ab9245259
Fix PhysFS 3.0.0 deprecation warnings for error reporting
Wuzzy <Wuzzy2@mail.ru>
parents:
10235
diff
changeset
|
302 |
#endif |
8440
ea4d6a7a2937
complete tabs and trailing whitespace formatting on frontend
koda
parents:
8206
diff
changeset
|
303 |
} |
ea4d6a7a2937
complete tabs and trailing whitespace formatting on frontend
koda
parents:
8206
diff
changeset
|
304 |
|
ea4d6a7a2937
complete tabs and trailing whitespace formatting on frontend
koda
parents:
8206
diff
changeset
|
305 |
bool FileEngine::supportsExtension(Extension extension) const |
ea4d6a7a2937
complete tabs and trailing whitespace formatting on frontend
koda
parents:
8206
diff
changeset
|
306 |
{ |
ea4d6a7a2937
complete tabs and trailing whitespace formatting on frontend
koda
parents:
8206
diff
changeset
|
307 |
return |
ea4d6a7a2937
complete tabs and trailing whitespace formatting on frontend
koda
parents:
8206
diff
changeset
|
308 |
(extension == QAbstractFileEngine::AtEndExtension) |
ea4d6a7a2937
complete tabs and trailing whitespace formatting on frontend
koda
parents:
8206
diff
changeset
|
309 |
|| (extension == QAbstractFileEngine::FastReadLineExtension) |
ea4d6a7a2937
complete tabs and trailing whitespace formatting on frontend
koda
parents:
8206
diff
changeset
|
310 |
; |
ea4d6a7a2937
complete tabs and trailing whitespace formatting on frontend
koda
parents:
8206
diff
changeset
|
311 |
} |
ea4d6a7a2937
complete tabs and trailing whitespace formatting on frontend
koda
parents:
8206
diff
changeset
|
312 |
|
ea4d6a7a2937
complete tabs and trailing whitespace formatting on frontend
koda
parents:
8206
diff
changeset
|
313 |
|
ea4d6a7a2937
complete tabs and trailing whitespace formatting on frontend
koda
parents:
8206
diff
changeset
|
314 |
FileEngineHandler::FileEngineHandler(char *argv0) |
ea4d6a7a2937
complete tabs and trailing whitespace formatting on frontend
koda
parents:
8206
diff
changeset
|
315 |
{ |
13874 | 316 |
if (!PHYSFS_init(argv0)) |
317 |
{ |
|
318 |
qDebug("PHYSFS initialization failed"); |
|
319 |
} |
|
9239 | 320 |
qDebug("%s", QString("[PHYSFS] Init: %1").arg(errorStr()).toLocal8Bit().constData()); |
8440
ea4d6a7a2937
complete tabs and trailing whitespace formatting on frontend
koda
parents:
8206
diff
changeset
|
321 |
} |
ea4d6a7a2937
complete tabs and trailing whitespace formatting on frontend
koda
parents:
8206
diff
changeset
|
322 |
|
ea4d6a7a2937
complete tabs and trailing whitespace formatting on frontend
koda
parents:
8206
diff
changeset
|
323 |
FileEngineHandler::~FileEngineHandler() |
ea4d6a7a2937
complete tabs and trailing whitespace formatting on frontend
koda
parents:
8206
diff
changeset
|
324 |
{ |
ea4d6a7a2937
complete tabs and trailing whitespace formatting on frontend
koda
parents:
8206
diff
changeset
|
325 |
PHYSFS_deinit(); |
ea4d6a7a2937
complete tabs and trailing whitespace formatting on frontend
koda
parents:
8206
diff
changeset
|
326 |
} |
ea4d6a7a2937
complete tabs and trailing whitespace formatting on frontend
koda
parents:
8206
diff
changeset
|
327 |
|
ea4d6a7a2937
complete tabs and trailing whitespace formatting on frontend
koda
parents:
8206
diff
changeset
|
328 |
QAbstractFileEngine* FileEngineHandler::create(const QString &filename) const |
ea4d6a7a2937
complete tabs and trailing whitespace formatting on frontend
koda
parents:
8206
diff
changeset
|
329 |
{ |
ea4d6a7a2937
complete tabs and trailing whitespace formatting on frontend
koda
parents:
8206
diff
changeset
|
330 |
if (filename.startsWith(scheme)) |
ea4d6a7a2937
complete tabs and trailing whitespace formatting on frontend
koda
parents:
8206
diff
changeset
|
331 |
return new FileEngine(filename); |
ea4d6a7a2937
complete tabs and trailing whitespace formatting on frontend
koda
parents:
8206
diff
changeset
|
332 |
else |
ea4d6a7a2937
complete tabs and trailing whitespace formatting on frontend
koda
parents:
8206
diff
changeset
|
333 |
return NULL; |
ea4d6a7a2937
complete tabs and trailing whitespace formatting on frontend
koda
parents:
8206
diff
changeset
|
334 |
} |
ea4d6a7a2937
complete tabs and trailing whitespace formatting on frontend
koda
parents:
8206
diff
changeset
|
335 |
|
ea4d6a7a2937
complete tabs and trailing whitespace formatting on frontend
koda
parents:
8206
diff
changeset
|
336 |
void FileEngineHandler::mount(const QString &path) |
ea4d6a7a2937
complete tabs and trailing whitespace formatting on frontend
koda
parents:
8206
diff
changeset
|
337 |
{ |
8714 | 338 |
PHYSFS_mount(path.toUtf8().constData(), NULL, 0); |
9239 | 339 |
qDebug("%s", QString("[PHYSFS] Mounting '%1' to '/': %2").arg(path).arg(errorStr()).toLocal8Bit().constData()); |
8440
ea4d6a7a2937
complete tabs and trailing whitespace formatting on frontend
koda
parents:
8206
diff
changeset
|
340 |
} |
ea4d6a7a2937
complete tabs and trailing whitespace formatting on frontend
koda
parents:
8206
diff
changeset
|
341 |
|
ea4d6a7a2937
complete tabs and trailing whitespace formatting on frontend
koda
parents:
8206
diff
changeset
|
342 |
void FileEngineHandler::mount(const QString & path, const QString & mountPoint) |
ea4d6a7a2937
complete tabs and trailing whitespace formatting on frontend
koda
parents:
8206
diff
changeset
|
343 |
{ |
8714 | 344 |
PHYSFS_mount(path.toUtf8().constData(), mountPoint.toUtf8().constData(), 0); |
9239 | 345 |
qDebug("%s", QString("[PHYSFS] Mounting '%1' to '%2': %3").arg(path).arg(mountPoint).arg(errorStr()).toLocal8Bit().data()); |
8440
ea4d6a7a2937
complete tabs and trailing whitespace formatting on frontend
koda
parents:
8206
diff
changeset
|
346 |
} |
ea4d6a7a2937
complete tabs and trailing whitespace formatting on frontend
koda
parents:
8206
diff
changeset
|
347 |
|
ea4d6a7a2937
complete tabs and trailing whitespace formatting on frontend
koda
parents:
8206
diff
changeset
|
348 |
void FileEngineHandler::setWriteDir(const QString &path) |
ea4d6a7a2937
complete tabs and trailing whitespace formatting on frontend
koda
parents:
8206
diff
changeset
|
349 |
{ |
ea4d6a7a2937
complete tabs and trailing whitespace formatting on frontend
koda
parents:
8206
diff
changeset
|
350 |
PHYSFS_setWriteDir(path.toUtf8().constData()); |
9239 | 351 |
qDebug("%s", QString("[PHYSFS] Setting write dir to '%1': %2").arg(path).arg(errorStr()).toLocal8Bit().data()); |
8440
ea4d6a7a2937
complete tabs and trailing whitespace formatting on frontend
koda
parents:
8206
diff
changeset
|
352 |
} |
ea4d6a7a2937
complete tabs and trailing whitespace formatting on frontend
koda
parents:
8206
diff
changeset
|
353 |
|
ea4d6a7a2937
complete tabs and trailing whitespace formatting on frontend
koda
parents:
8206
diff
changeset
|
354 |
void FileEngineHandler::mountPacks() |
ea4d6a7a2937
complete tabs and trailing whitespace formatting on frontend
koda
parents:
8206
diff
changeset
|
355 |
{ |
ea4d6a7a2937
complete tabs and trailing whitespace formatting on frontend
koda
parents:
8206
diff
changeset
|
356 |
hedgewarsMountPackages(); |
ea4d6a7a2937
complete tabs and trailing whitespace formatting on frontend
koda
parents:
8206
diff
changeset
|
357 |
} |
ea4d6a7a2937
complete tabs and trailing whitespace formatting on frontend
koda
parents:
8206
diff
changeset
|
358 |
|
9170 | 359 |
QString FileEngineHandler::errorStr() |
360 |
{ |
|
12729
d47ab9245259
Fix PhysFS 3.0.0 deprecation warnings for error reporting
Wuzzy <Wuzzy2@mail.ru>
parents:
10235
diff
changeset
|
361 |
QString s; |
d47ab9245259
Fix PhysFS 3.0.0 deprecation warnings for error reporting
Wuzzy <Wuzzy2@mail.ru>
parents:
10235
diff
changeset
|
362 |
#if PHYSFS_VER_MAJOR >= 3 |
d47ab9245259
Fix PhysFS 3.0.0 deprecation warnings for error reporting
Wuzzy <Wuzzy2@mail.ru>
parents:
10235
diff
changeset
|
363 |
s = QString::fromUtf8(PHYSFS_getErrorByCode(PHYSFS_getLastErrorCode())); |
d47ab9245259
Fix PhysFS 3.0.0 deprecation warnings for error reporting
Wuzzy <Wuzzy2@mail.ru>
parents:
10235
diff
changeset
|
364 |
#else |
d47ab9245259
Fix PhysFS 3.0.0 deprecation warnings for error reporting
Wuzzy <Wuzzy2@mail.ru>
parents:
10235
diff
changeset
|
365 |
s = QString::fromUtf8(PHYSFS_getLastError()); |
d47ab9245259
Fix PhysFS 3.0.0 deprecation warnings for error reporting
Wuzzy <Wuzzy2@mail.ru>
parents:
10235
diff
changeset
|
366 |
#endif |
9170 | 367 |
return s.isEmpty() ? "ok" : s; |
368 |
} |
|
369 |
||
8440
ea4d6a7a2937
complete tabs and trailing whitespace formatting on frontend
koda
parents:
8206
diff
changeset
|
370 |
|
ea4d6a7a2937
complete tabs and trailing whitespace formatting on frontend
koda
parents:
8206
diff
changeset
|
371 |
FileEngineIterator::FileEngineIterator(QDir::Filters filters, const QStringList &nameFilters, const QStringList &entries) |
ea4d6a7a2937
complete tabs and trailing whitespace formatting on frontend
koda
parents:
8206
diff
changeset
|
372 |
: QAbstractFileEngineIterator(filters, nameFilters) |
ea4d6a7a2937
complete tabs and trailing whitespace formatting on frontend
koda
parents:
8206
diff
changeset
|
373 |
{ |
ea4d6a7a2937
complete tabs and trailing whitespace formatting on frontend
koda
parents:
8206
diff
changeset
|
374 |
m_entries = entries; |
ea4d6a7a2937
complete tabs and trailing whitespace formatting on frontend
koda
parents:
8206
diff
changeset
|
375 |
|
ea4d6a7a2937
complete tabs and trailing whitespace formatting on frontend
koda
parents:
8206
diff
changeset
|
376 |
/* heck.. docs are unclear on this |
ea4d6a7a2937
complete tabs and trailing whitespace formatting on frontend
koda
parents:
8206
diff
changeset
|
377 |
* QDirIterator puts iterator before first entry |
ea4d6a7a2937
complete tabs and trailing whitespace formatting on frontend
koda
parents:
8206
diff
changeset
|
378 |
* but QAbstractFileEngineIterator example puts iterator on first entry |
ea4d6a7a2937
complete tabs and trailing whitespace formatting on frontend
koda
parents:
8206
diff
changeset
|
379 |
* though QDirIterator approach seems to be the right one |
ea4d6a7a2937
complete tabs and trailing whitespace formatting on frontend
koda
parents:
8206
diff
changeset
|
380 |
*/ |
ea4d6a7a2937
complete tabs and trailing whitespace formatting on frontend
koda
parents:
8206
diff
changeset
|
381 |
|
ea4d6a7a2937
complete tabs and trailing whitespace formatting on frontend
koda
parents:
8206
diff
changeset
|
382 |
m_index = -1; |
ea4d6a7a2937
complete tabs and trailing whitespace formatting on frontend
koda
parents:
8206
diff
changeset
|
383 |
} |
ea4d6a7a2937
complete tabs and trailing whitespace formatting on frontend
koda
parents:
8206
diff
changeset
|
384 |
|
ea4d6a7a2937
complete tabs and trailing whitespace formatting on frontend
koda
parents:
8206
diff
changeset
|
385 |
bool FileEngineIterator::hasNext() const |
ea4d6a7a2937
complete tabs and trailing whitespace formatting on frontend
koda
parents:
8206
diff
changeset
|
386 |
{ |
ea4d6a7a2937
complete tabs and trailing whitespace formatting on frontend
koda
parents:
8206
diff
changeset
|
387 |
return m_index < m_entries.size() - 1; |
ea4d6a7a2937
complete tabs and trailing whitespace formatting on frontend
koda
parents:
8206
diff
changeset
|
388 |
} |
ea4d6a7a2937
complete tabs and trailing whitespace formatting on frontend
koda
parents:
8206
diff
changeset
|
389 |
|
ea4d6a7a2937
complete tabs and trailing whitespace formatting on frontend
koda
parents:
8206
diff
changeset
|
390 |
QString FileEngineIterator::next() |
ea4d6a7a2937
complete tabs and trailing whitespace formatting on frontend
koda
parents:
8206
diff
changeset
|
391 |
{ |
ea4d6a7a2937
complete tabs and trailing whitespace formatting on frontend
koda
parents:
8206
diff
changeset
|
392 |
if (!hasNext()) |
ea4d6a7a2937
complete tabs and trailing whitespace formatting on frontend
koda
parents:
8206
diff
changeset
|
393 |
return QString(); |
ea4d6a7a2937
complete tabs and trailing whitespace formatting on frontend
koda
parents:
8206
diff
changeset
|
394 |
|
ea4d6a7a2937
complete tabs and trailing whitespace formatting on frontend
koda
parents:
8206
diff
changeset
|
395 |
++m_index; |
ea4d6a7a2937
complete tabs and trailing whitespace formatting on frontend
koda
parents:
8206
diff
changeset
|
396 |
return currentFilePath(); |
ea4d6a7a2937
complete tabs and trailing whitespace formatting on frontend
koda
parents:
8206
diff
changeset
|
397 |
} |
ea4d6a7a2937
complete tabs and trailing whitespace formatting on frontend
koda
parents:
8206
diff
changeset
|
398 |
|
ea4d6a7a2937
complete tabs and trailing whitespace formatting on frontend
koda
parents:
8206
diff
changeset
|
399 |
QString FileEngineIterator::currentFileName() const |
ea4d6a7a2937
complete tabs and trailing whitespace formatting on frontend
koda
parents:
8206
diff
changeset
|
400 |
{ |
ea4d6a7a2937
complete tabs and trailing whitespace formatting on frontend
koda
parents:
8206
diff
changeset
|
401 |
return m_entries.at(m_index); |
ea4d6a7a2937
complete tabs and trailing whitespace formatting on frontend
koda
parents:
8206
diff
changeset
|
402 |
} |