--- a/QTfrontend/util/FileEngine.cpp Fri Nov 23 16:16:02 2012 +0400
+++ b/QTfrontend/util/FileEngine.cpp Fri Nov 23 16:17:06 2012 +0400
@@ -9,8 +9,9 @@
const QString FileEngineHandler::scheme = "physfs:/";
FileEngine::FileEngine(const QString& filename)
-: _handler(NULL)
-, _flags(0)
+ : _handler(NULL)
+ , _flags(0)
+ , m_bufferSet(false)
{
setFileName(filename);
}
@@ -222,6 +223,27 @@
return PHYSFS_readBytes(_handler, data, maxlen);
}
+qint64 FileEngine::readLine(char *data, qint64 maxlen)
+{
+ if(!m_bufferSet)
+ {
+ PHYSFS_setBuffer(_handler, 4096);
+ m_bufferSet = true;
+ }
+
+ qint64 bytesRead = 0;
+ while(PHYSFS_readBytes(_handler, data, 1)
+ && maxlen
+ && (*data == '\n'))
+ {
+ ++data;
+ --maxlen;
+ ++bytesRead;
+ }
+
+ return bytesRead;
+}
+
qint64 FileEngine::write(const char *data, qint64 len)
{
return PHYSFS_writeBytes(_handler, data, len);
@@ -244,11 +266,13 @@
bool FileEngine::supportsExtension(Extension extension) const
{
- return extension == QAbstractFileEngine::AtEndExtension;
+ return
+ (extension == QAbstractFileEngine::AtEndExtension)
+ || (extension == QAbstractFileEngine::FastReadLineExtension)
+ ;
}
-
FileEngineHandler::FileEngineHandler(char *argv0)
{
PHYSFS_init(argv0);
--- a/QTfrontend/util/FileEngine.h Fri Nov 23 16:16:02 2012 +0400
+++ b/QTfrontend/util/FileEngine.h Fri Nov 23 16:17:06 2012 +0400
@@ -38,6 +38,7 @@
bool atEnd() const;
virtual qint64 read(char *data, qint64 maxlen);
+ virtual qint64 readLine(char *data, qint64 maxlen);
virtual qint64 write(const char *data, qint64 len);
bool isOpened() const;
@@ -53,6 +54,7 @@
FileFlags _flags;
QString _filename;
QDateTime _datetime;
+ bool m_bufferSet;
};
class FileEngineHandler : public QAbstractFileEngineHandler