QTfrontend/util/FileEngine.cpp
changeset 8112 d85dc8a8f41c
parent 8098 4efee370e2de
child 8115 ac1007c6dea8
--- 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);