- Load teams via physfs physfslayer
authorunc0rr
Mon, 05 Nov 2012 23:03:01 +0400
branchphysfslayer
changeset 7955 85b3970b402a
parent 7951 c64c0b413ff7
child 7959 644b757d20e6
- Load teams via physfs - Some fixes which allow Qt to load ini files and icons via physfs
QTfrontend/main.cpp
QTfrontend/model/ThemeModel.cpp
QTfrontend/team.cpp
QTfrontend/util/FileEngine.cpp
QTfrontend/util/FileEngine.h
--- a/QTfrontend/main.cpp	Mon Nov 05 00:32:41 2012 +0400
+++ b/QTfrontend/main.cpp	Mon Nov 05 23:03:01 2012 +0400
@@ -224,14 +224,14 @@
     // setup PhysFS
     engine.mount(datadir->absolutePath());
     engine.mount(cfgdir->absolutePath() + "/Data");
-    engine.mount(cfgdir->absolutePath());
+    engine.mount(cfgdir->absolutePath(), "/config");
     engine.setWriteDir(cfgdir->absolutePath());
 
     DataManager & dataMgr = DataManager::instance();
 
     QTranslator Translator;
     {
-        QSettings settings("physfs://hedgewars.ini", QSettings::IniFormat);
+        QSettings settings("physfs://config/hedgewars.ini", QSettings::IniFormat);
         QString cc = settings.value("misc/locale", QString()).toString();
         if(cc.isEmpty())
             cc = QLocale::system().name();
--- a/QTfrontend/model/ThemeModel.cpp	Mon Nov 05 00:32:41 2012 +0400
+++ b/QTfrontend/model/ThemeModel.cpp	Mon Nov 05 23:03:01 2012 +0400
@@ -78,15 +78,12 @@
         dataset.insert(Qt::DisplayRole, theme);
 
         // load and set icon
-
-        QPixmap pix(iconpath); // workaround, as QIcon(iconpath) and even QIcon(QPixmap(iconpath)) don't work
-        QIcon icon(pix);
+        QIcon icon(iconpath);
 
         dataset.insert(Qt::DecorationRole, icon);
 
         // load and set preview icon
-        pix.load(datamgr.findFileForRead(QString("Themes/%1/icon@2x.png").arg(theme)));
-        QIcon preview(pix);
+        QIcon preview(datamgr.findFileForRead(QString("Themes/%1/icon@2x.png").arg(theme)));
         dataset.insert(Qt::UserRole, preview);
 
         m_data.append(dataset);
--- a/QTfrontend/team.cpp	Mon Nov 05 00:32:41 2012 +0400
+++ b/QTfrontend/team.cpp	Mon Nov 05 23:03:01 2012 +0400
@@ -169,7 +169,7 @@
 
 bool HWTeam::loadFromFile()
 {
-    QSettings teamfile(cfgdir->absolutePath() + "/Teams/" + m_name + ".hwt", QSettings::IniFormat, 0);
+    QSettings teamfile(QString("physfs://config/Teams/%1.hwt").arg(m_name), QSettings::IniFormat, 0);
     teamfile.setIniCodec("UTF-8");
     m_name = teamfile.value("Team/Name", m_name).toString();
     m_grave = teamfile.value("Team/Grave", "Statue").toString();
@@ -202,7 +202,7 @@
 
 bool HWTeam::fileExists()
 {
-    QFile f(cfgdir->absolutePath() + "/Teams/" + m_name + ".hwt");
+    QFile f(QString("physfs://config/Teams/%1.hwt").arg(m_name));
     return f.exists();
 }
 
@@ -210,7 +210,7 @@
 {
     if(m_isNetTeam)
         return false;
-    QFile cfgfile(cfgdir->absolutePath() + "/Teams/" + m_name + ".hwt");
+    QFile cfgfile(QString("physfs://config/Teams/%1.hwt").arg(m_name));
     cfgfile.remove();
     return true;
 }
@@ -219,11 +219,11 @@
 {
     if (OldTeamName != m_name)
     {
-        QFile cfgfile(cfgdir->absolutePath() + "/Teams/" + OldTeamName + ".hwt");
+        QFile cfgfile(QString("physfs://config/Teams/%1.hwt").arg(OldTeamName));
         cfgfile.remove();
         OldTeamName = m_name;
     }
-    QSettings teamfile(cfgdir->absolutePath() + "/Teams/" + m_name + ".hwt", QSettings::IniFormat, 0);
+    QSettings teamfile(QString("physfs://config/Teams/%1.hwt").arg(m_name), QSettings::IniFormat, 0);
     teamfile.setIniCodec("UTF-8");
     teamfile.setValue("Team/Name", m_name);
     teamfile.setValue("Team/Grave", m_grave);
--- a/QTfrontend/util/FileEngine.cpp	Mon Nov 05 00:32:41 2012 +0400
+++ b/QTfrontend/util/FileEngine.cpp	Mon Nov 05 23:03:01 2012 +0400
@@ -2,6 +2,7 @@
  * TODO: add copyright header, determine license
  */
 
+
 #include "FileEngine.h"
 
 
@@ -147,11 +148,12 @@
     if (file == QAbstractFileEngine::AbsolutePathName)
         return PHYSFS_getWriteDir();
 
-    return _filename;
+    return QString("physfs://%1").arg(_filename);
 }
 
 QDateTime FileEngine::fileTime(FileTime time) const
 {
+
     switch (time)
     {
         case QAbstractFileEngine::ModificationTime:
@@ -172,6 +174,7 @@
     if (PHYSFS_stat(_filename.toUtf8().constData(), &stat) != 0) {
         _size = stat.filesize;
         _datetime = QDateTime::fromTime_t(stat.modtime);
+//        _flags |= QAbstractFileEngine::WriteUserPerm;
         _flags |= QAbstractFileEngine::ReadUserPerm;
         _flags |= QAbstractFileEngine::ExistsFlag;
 
@@ -188,7 +191,7 @@
                 _flags |= QAbstractFileEngine::LinkType;
                 break;
             default: ;
-        };
+        }
     }
 }
 
@@ -252,6 +255,11 @@
     PHYSFS_mount(path.toUtf8().constData(), NULL, 1);
 }
 
+void FileEngineHandler::mount(const QString & path, const QString & mountPoint)
+{
+    PHYSFS_mount(path.toUtf8().constData(), mountPoint.toUtf8().constData(), 1);
+}
+
 void FileEngineHandler::setWriteDir(const QString &path)
 {
     PHYSFS_setWriteDir(path.toUtf8().constData());
--- a/QTfrontend/util/FileEngine.h	Mon Nov 05 00:32:41 2012 +0400
+++ b/QTfrontend/util/FileEngine.h	Mon Nov 05 23:03:01 2012 +0400
@@ -64,6 +64,7 @@
         QAbstractFileEngine *create(const QString &filename) const;
 
         void mount(const QString & path);
+        void mount(const QString & path, const QString & mountPoint);
         void setWriteDir(const QString & path);
 
 //    private: