equal
deleted
inserted
replaced
10 |
10 |
11 FileEngine::FileEngine(const QString& filename) |
11 FileEngine::FileEngine(const QString& filename) |
12 : m_handle(NULL) |
12 : m_handle(NULL) |
13 , m_flags(0) |
13 , m_flags(0) |
14 , m_bufferSet(false) |
14 , m_bufferSet(false) |
|
15 , m_readWrite(false) |
15 { |
16 { |
16 setFileName(filename); |
17 setFileName(filename); |
17 } |
18 } |
18 |
19 |
19 FileEngine::~FileEngine() |
20 FileEngine::~FileEngine() |
23 |
24 |
24 bool FileEngine::open(QIODevice::OpenMode openMode) |
25 bool FileEngine::open(QIODevice::OpenMode openMode) |
25 { |
26 { |
26 close(); |
27 close(); |
27 |
28 |
28 if (openMode & QIODevice::WriteOnly) { |
29 if ((openMode & QIODevice::ReadWrite) == QIODevice::ReadWrite) { |
|
30 m_handle = PHYSFS_openAppend(m_fileName.toUtf8().constData()); |
|
31 m_readWrite = true; |
|
32 seek(0); |
|
33 } |
|
34 |
|
35 else if (openMode & QIODevice::WriteOnly) { |
29 m_handle = PHYSFS_openWrite(m_fileName.toUtf8().constData()); |
36 m_handle = PHYSFS_openWrite(m_fileName.toUtf8().constData()); |
30 m_flags = QAbstractFileEngine::WriteOwnerPerm | QAbstractFileEngine::WriteUserPerm | QAbstractFileEngine::FileType; |
37 m_flags = QAbstractFileEngine::WriteOwnerPerm | QAbstractFileEngine::WriteUserPerm | QAbstractFileEngine::FileType; |
31 } |
38 } |
32 |
39 |
33 else if (openMode & QIODevice::ReadOnly) { |
40 else if (openMode & QIODevice::ReadOnly) { |
74 qint64 FileEngine::pos() const |
81 qint64 FileEngine::pos() const |
75 { |
82 { |
76 return PHYSFS_tell(m_handle); |
83 return PHYSFS_tell(m_handle); |
77 } |
84 } |
78 |
85 |
|
86 bool FileEngine::setSize(qint64 size) |
|
87 { |
|
88 if(size == 0) |
|
89 { |
|
90 m_size = 0; |
|
91 return open(QIODevice::WriteOnly); |
|
92 } |
|
93 else |
|
94 return false; |
|
95 } |
|
96 |
79 bool FileEngine::seek(qint64 pos) |
97 bool FileEngine::seek(qint64 pos) |
80 { |
98 { |
81 return PHYSFS_seek(m_handle, pos) != 0; |
99 bool ok = PHYSFS_seek(m_handle, pos) != 0; |
|
100 |
|
101 return ok; |
82 } |
102 } |
83 |
103 |
84 bool FileEngine::isSequential() const |
104 bool FileEngine::isSequential() const |
85 { |
105 { |
86 return false; |
106 return false; |
108 return true; |
128 return true; |
109 } |
129 } |
110 |
130 |
111 bool FileEngine::isRelativePath() const |
131 bool FileEngine::isRelativePath() const |
112 { |
132 { |
113 return true; |
133 return false; |
114 } |
134 } |
115 |
135 |
116 QAbstractFileEngineIterator * FileEngine::beginEntryList(QDir::Filters filters, const QStringList &filterNames) |
136 QAbstractFileEngineIterator * FileEngine::beginEntryList(QDir::Filters filters, const QStringList &filterNames) |
117 { |
137 { |
118 return new FileEngineIterator(filters, filterNames, entryList(filters, filterNames)); |
138 return new FileEngineIterator(filters, filterNames, entryList(filters, filterNames)); |
187 m_fileName = file.mid(FileEngineHandler::scheme.size()); |
207 m_fileName = file.mid(FileEngineHandler::scheme.size()); |
188 else |
208 else |
189 m_fileName = file; |
209 m_fileName = file; |
190 |
210 |
191 PHYSFS_Stat stat; |
211 PHYSFS_Stat stat; |
192 if (PHYSFS_stat(m_fileName.toUtf8().constData(), &stat) != 0) { |
212 if (PHYSFS_stat(m_fileName.toUtf8().constData(), &stat) != 0) { |
193 m_size = stat.filesize; |
213 m_size = stat.filesize; |
194 m_date = QDateTime::fromTime_t(stat.modtime); |
214 m_date = QDateTime::fromTime_t(stat.modtime); |
195 // _flags |= QAbstractFileEngine::WriteUserPerm; |
215 // _flags |= QAbstractFileEngine::WriteUserPerm; |
196 m_flags |= QAbstractFileEngine::ReadUserPerm; |
216 m_flags |= QAbstractFileEngine::ReadUserPerm; |
197 m_flags |= QAbstractFileEngine::ExistsFlag; |
217 m_flags |= QAbstractFileEngine::ExistsFlag; |
218 return PHYSFS_eof(m_handle) != 0; |
238 return PHYSFS_eof(m_handle) != 0; |
219 } |
239 } |
220 |
240 |
221 qint64 FileEngine::read(char *data, qint64 maxlen) |
241 qint64 FileEngine::read(char *data, qint64 maxlen) |
222 { |
242 { |
223 return PHYSFS_readBytes(m_handle, data, maxlen); |
243 if(m_readWrite) |
|
244 { |
|
245 if(pos() == 0) |
|
246 open(QIODevice::ReadOnly); |
|
247 else |
|
248 return -1; |
|
249 } |
|
250 |
|
251 qint64 len = PHYSFS_readBytes(m_handle, data, maxlen); |
|
252 return len; |
224 } |
253 } |
225 |
254 |
226 qint64 FileEngine::readLine(char *data, qint64 maxlen) |
255 qint64 FileEngine::readLine(char *data, qint64 maxlen) |
227 { |
256 { |
228 if(!m_bufferSet) |
257 if(!m_bufferSet) |
284 } |
313 } |
285 |
314 |
286 QAbstractFileEngine* FileEngineHandler::create(const QString &filename) const |
315 QAbstractFileEngine* FileEngineHandler::create(const QString &filename) const |
287 { |
316 { |
288 if (filename.startsWith(scheme)) |
317 if (filename.startsWith(scheme)) |
289 return new FileEngine(filename.mid(scheme.size())); |
318 return new FileEngine(filename); |
290 else |
319 else |
291 return NULL; |
320 return NULL; |
292 } |
321 } |
293 |
322 |
294 void FileEngineHandler::mount(const QString &path) |
323 void FileEngineHandler::mount(const QString &path) |