23 |
25 |
24 bool FileEngine::open(QIODevice::OpenMode openMode) |
26 bool FileEngine::open(QIODevice::OpenMode openMode) |
25 { |
27 { |
26 close(); |
28 close(); |
27 |
29 |
28 if (openMode & QIODevice::WriteOnly) { |
30 if ((openMode & QIODevice::ReadWrite) == QIODevice::ReadWrite) { |
|
31 m_handle = PHYSFS_openAppend(m_fileName.toUtf8().constData()); |
|
32 if(m_handle) |
|
33 { |
|
34 m_readWrite = true; |
|
35 seek(0); |
|
36 } |
|
37 } |
|
38 |
|
39 else if (openMode & QIODevice::WriteOnly) { |
29 m_handle = PHYSFS_openWrite(m_fileName.toUtf8().constData()); |
40 m_handle = PHYSFS_openWrite(m_fileName.toUtf8().constData()); |
30 m_flags = QAbstractFileEngine::WriteOwnerPerm | QAbstractFileEngine::WriteUserPerm | QAbstractFileEngine::FileType; |
41 m_flags = QAbstractFileEngine::WriteOwnerPerm | QAbstractFileEngine::WriteUserPerm | QAbstractFileEngine::FileType; |
31 } |
42 } |
32 |
43 |
33 else if (openMode & QIODevice::ReadOnly) { |
44 else if (openMode & QIODevice::ReadOnly) { |
74 qint64 FileEngine::pos() const |
85 qint64 FileEngine::pos() const |
75 { |
86 { |
76 return PHYSFS_tell(m_handle); |
87 return PHYSFS_tell(m_handle); |
77 } |
88 } |
78 |
89 |
|
90 bool FileEngine::setSize(qint64 size) |
|
91 { |
|
92 if(size == 0) |
|
93 { |
|
94 m_size = 0; |
|
95 return open(QIODevice::WriteOnly); |
|
96 } |
|
97 else |
|
98 return false; |
|
99 } |
|
100 |
79 bool FileEngine::seek(qint64 pos) |
101 bool FileEngine::seek(qint64 pos) |
80 { |
102 { |
81 return PHYSFS_seek(m_handle, pos) != 0; |
103 bool ok = PHYSFS_seek(m_handle, pos) != 0; |
|
104 |
|
105 return ok; |
82 } |
106 } |
83 |
107 |
84 bool FileEngine::isSequential() const |
108 bool FileEngine::isSequential() const |
85 { |
109 { |
86 return false; |
110 return false; |
92 } |
116 } |
93 |
117 |
94 bool FileEngine::mkdir(const QString &dirName, bool createParentDirectories) const |
118 bool FileEngine::mkdir(const QString &dirName, bool createParentDirectories) const |
95 { |
119 { |
96 Q_UNUSED(createParentDirectories); |
120 Q_UNUSED(createParentDirectories); |
|
121 |
97 return PHYSFS_mkdir(dirName.toUtf8().constData()) != 0; |
122 return PHYSFS_mkdir(dirName.toUtf8().constData()) != 0; |
98 } |
123 } |
99 |
124 |
100 bool FileEngine::rmdir(const QString &dirName, bool recurseParentDirectories) const |
125 bool FileEngine::rmdir(const QString &dirName, bool recurseParentDirectories) const |
101 { |
126 { |
102 Q_UNUSED(recurseParentDirectories); |
127 Q_UNUSED(recurseParentDirectories); |
|
128 |
103 return PHYSFS_delete(dirName.toUtf8().constData()) != 0; |
129 return PHYSFS_delete(dirName.toUtf8().constData()) != 0; |
104 } |
130 } |
105 |
131 |
106 bool FileEngine::caseSensitive() const |
132 bool FileEngine::caseSensitive() const |
107 { |
133 { |
108 return true; |
134 return true; |
109 } |
135 } |
110 |
136 |
111 bool FileEngine::isRelativePath() const |
137 bool FileEngine::isRelativePath() const |
112 { |
138 { |
113 return true; |
139 return false; |
114 } |
140 } |
115 |
141 |
116 QAbstractFileEngineIterator * FileEngine::beginEntryList(QDir::Filters filters, const QStringList &filterNames) |
142 QAbstractFileEngineIterator * FileEngine::beginEntryList(QDir::Filters filters, const QStringList &filterNames) |
117 { |
143 { |
118 return new FileEngineIterator(filters, filterNames, entryList(filters, filterNames)); |
144 return new FileEngineIterator(filters, filterNames, entryList(filters, filterNames)); |
185 { |
210 { |
186 if(file.startsWith(FileEngineHandler::scheme)) |
211 if(file.startsWith(FileEngineHandler::scheme)) |
187 m_fileName = file.mid(FileEngineHandler::scheme.size()); |
212 m_fileName = file.mid(FileEngineHandler::scheme.size()); |
188 else |
213 else |
189 m_fileName = file; |
214 m_fileName = file; |
190 |
|
191 PHYSFS_Stat stat; |
215 PHYSFS_Stat stat; |
192 if (PHYSFS_stat(m_fileName.toUtf8().constData(), &stat) != 0) { |
216 if (PHYSFS_stat(m_fileName.toUtf8().constData(), &stat) != 0) { |
193 m_size = stat.filesize; |
217 m_size = stat.filesize; |
194 m_date = QDateTime::fromTime_t(stat.modtime); |
218 m_date = QDateTime::fromTime_t(stat.modtime); |
195 // _flags |= QAbstractFileEngine::WriteUserPerm; |
219 // m_flags |= QAbstractFileEngine::WriteOwnerPerm; |
|
220 m_flags |= QAbstractFileEngine::ReadOwnerPerm; |
196 m_flags |= QAbstractFileEngine::ReadUserPerm; |
221 m_flags |= QAbstractFileEngine::ReadUserPerm; |
197 m_flags |= QAbstractFileEngine::ExistsFlag; |
222 m_flags |= QAbstractFileEngine::ExistsFlag; |
|
223 m_flags |= QAbstractFileEngine::LocalDiskFlag; |
198 |
224 |
199 switch (stat.filetype) |
225 switch (stat.filetype) |
200 { |
226 { |
201 case PHYSFS_FILETYPE_REGULAR: |
227 case PHYSFS_FILETYPE_REGULAR: |
202 m_flags |= QAbstractFileEngine::FileType; |
228 m_flags |= QAbstractFileEngine::FileType; |
203 break; |
229 break; |
204 |
|
205 case PHYSFS_FILETYPE_DIRECTORY: |
230 case PHYSFS_FILETYPE_DIRECTORY: |
206 m_flags |= QAbstractFileEngine::DirectoryType; |
231 m_flags |= QAbstractFileEngine::DirectoryType; |
207 break; |
232 break; |
208 case PHYSFS_FILETYPE_SYMLINK: |
233 case PHYSFS_FILETYPE_SYMLINK: |
209 m_flags |= QAbstractFileEngine::LinkType; |
234 m_flags |= QAbstractFileEngine::LinkType; |
218 return PHYSFS_eof(m_handle) != 0; |
243 return PHYSFS_eof(m_handle) != 0; |
219 } |
244 } |
220 |
245 |
221 qint64 FileEngine::read(char *data, qint64 maxlen) |
246 qint64 FileEngine::read(char *data, qint64 maxlen) |
222 { |
247 { |
223 return PHYSFS_readBytes(m_handle, data, maxlen); |
248 if(m_readWrite) |
|
249 { |
|
250 if(pos() == 0) |
|
251 open(QIODevice::ReadOnly); |
|
252 else |
|
253 return -1; |
|
254 } |
|
255 |
|
256 qint64 len = PHYSFS_readBytes(m_handle, data, maxlen); |
|
257 return len; |
224 } |
258 } |
225 |
259 |
226 qint64 FileEngine::readLine(char *data, qint64 maxlen) |
260 qint64 FileEngine::readLine(char *data, qint64 maxlen) |
227 { |
261 { |
228 if(!m_bufferSet) |
262 if(!m_bufferSet) |