QTfrontend/util/FileEngine.cpp
branchphysfslayer
changeset 7955 85b3970b402a
parent 7931 5a27ed7f17b7
child 8052 845b5ae03841
equal deleted inserted replaced
7951:c64c0b413ff7 7955:85b3970b402a
     1 /* borrowed from https://github.com/skhaz/qt-physfs-wrapper
     1 /* borrowed from https://github.com/skhaz/qt-physfs-wrapper
     2  * TODO: add copyright header, determine license
     2  * TODO: add copyright header, determine license
     3  */
     3  */
       
     4 
     4 
     5 
     5 #include "FileEngine.h"
     6 #include "FileEngine.h"
     6 
     7 
     7 
     8 
     8 const QString FileEngineHandler::scheme = "physfs:/";
     9 const QString FileEngineHandler::scheme = "physfs:/";
   145 QString FileEngine::fileName(FileName file) const
   146 QString FileEngine::fileName(FileName file) const
   146 {
   147 {
   147     if (file == QAbstractFileEngine::AbsolutePathName)
   148     if (file == QAbstractFileEngine::AbsolutePathName)
   148         return PHYSFS_getWriteDir();
   149         return PHYSFS_getWriteDir();
   149 
   150 
   150     return _filename;
   151     return QString("physfs://%1").arg(_filename);
   151 }
   152 }
   152 
   153 
   153 QDateTime FileEngine::fileTime(FileTime time) const
   154 QDateTime FileEngine::fileTime(FileTime time) const
   154 {
   155 {
       
   156 
   155     switch (time)
   157     switch (time)
   156     {
   158     {
   157         case QAbstractFileEngine::ModificationTime:
   159         case QAbstractFileEngine::ModificationTime:
   158         default:
   160         default:
   159             return _datetime;
   161             return _datetime;
   170 
   172 
   171     PHYSFS_Stat stat;
   173     PHYSFS_Stat stat;
   172     if (PHYSFS_stat(_filename.toUtf8().constData(), &stat) != 0) {
   174     if (PHYSFS_stat(_filename.toUtf8().constData(), &stat) != 0) {
   173         _size = stat.filesize;
   175         _size = stat.filesize;
   174         _datetime = QDateTime::fromTime_t(stat.modtime);
   176         _datetime = QDateTime::fromTime_t(stat.modtime);
       
   177 //        _flags |= QAbstractFileEngine::WriteUserPerm;
   175         _flags |= QAbstractFileEngine::ReadUserPerm;
   178         _flags |= QAbstractFileEngine::ReadUserPerm;
   176         _flags |= QAbstractFileEngine::ExistsFlag;
   179         _flags |= QAbstractFileEngine::ExistsFlag;
   177 
   180 
   178         switch (stat.filetype)
   181         switch (stat.filetype)
   179         {
   182         {
   186                 break;
   189                 break;
   187             case PHYSFS_FILETYPE_SYMLINK:
   190             case PHYSFS_FILETYPE_SYMLINK:
   188                 _flags |= QAbstractFileEngine::LinkType;
   191                 _flags |= QAbstractFileEngine::LinkType;
   189                 break;
   192                 break;
   190             default: ;
   193             default: ;
   191         };
   194         }
   192     }
   195     }
   193 }
   196 }
   194 
   197 
   195 bool FileEngine::atEnd() const
   198 bool FileEngine::atEnd() const
   196 {
   199 {
   248 }
   251 }
   249 
   252 
   250 void FileEngineHandler::mount(const QString &path)
   253 void FileEngineHandler::mount(const QString &path)
   251 {
   254 {
   252     PHYSFS_mount(path.toUtf8().constData(), NULL, 1);
   255     PHYSFS_mount(path.toUtf8().constData(), NULL, 1);
       
   256 }
       
   257 
       
   258 void FileEngineHandler::mount(const QString & path, const QString & mountPoint)
       
   259 {
       
   260     PHYSFS_mount(path.toUtf8().constData(), mountPoint.toUtf8().constData(), 1);
   253 }
   261 }
   254 
   262 
   255 void FileEngineHandler::setWriteDir(const QString &path)
   263 void FileEngineHandler::setWriteDir(const QString &path)
   256 {
   264 {
   257     PHYSFS_setWriteDir(path.toUtf8().constData());
   265     PHYSFS_setWriteDir(path.toUtf8().constData());