Get rid of DataManager::findFileForRead physfslayer
authorunc0rr
Sat, 17 Nov 2012 22:45:30 +0400
branchphysfslayer
changeset 8049 133e22b5c410
parent 8046 4d3415927d2c
child 8052 845b5ae03841
Get rid of DataManager::findFileForRead
QTfrontend/campaign.cpp
QTfrontend/hwform.cpp
QTfrontend/main.cpp
QTfrontend/model/GameStyleModel.cpp
QTfrontend/model/HatModel.cpp
QTfrontend/model/MapModel.cpp
QTfrontend/model/ThemeModel.cpp
QTfrontend/ui/mouseoverfilter.cpp
QTfrontend/ui/page/pageeditteam.cpp
QTfrontend/ui/page/pagetraining.cpp
QTfrontend/ui/widget/chatwidget.cpp
QTfrontend/ui/widget/mapContainer.cpp
QTfrontend/ui/widget/qpushbuttonwithsound.cpp
QTfrontend/util/DataManager.cpp
QTfrontend/util/DataManager.h
QTfrontend/util/namegen.cpp
--- a/QTfrontend/campaign.cpp	Sat Nov 17 22:07:17 2012 +0400
+++ b/QTfrontend/campaign.cpp	Sat Nov 17 22:45:30 2012 +0400
@@ -56,7 +56,7 @@
 
 QStringList getCampMissionList(QString & campaign)
 {
-    QSettings campfile(DataManager::instance().findFileForRead("Missions/Campaign/" + campaign + "/campaign.ini"), QSettings::IniFormat, 0);
+    QSettings campfile("physfs://Missions/Campaign/" + campaign + "/campaign.ini", QSettings::IniFormat, 0);
     campfile.setIniCodec("UTF-8");
     unsigned int mNum = campfile.value("MissionNum", 0).toInt();
     
@@ -77,7 +77,7 @@
 
 QString getCampaignScript(QString campaign, unsigned int mNum)
 {
-    QSettings campfile(DataManager::instance().findFileForRead("Missions/Campaign/" + campaign + "/campaign.ini"), QSettings::IniFormat, 0);
+    QSettings campfile("physfs://Missions/Campaign/" + campaign + "/campaign.ini", QSettings::IniFormat, 0);
     campfile.setIniCodec("UTF-8");
     return campfile.value(QString("Mission %1/Script").arg(mNum)).toString();
 }
--- a/QTfrontend/hwform.cpp	Sat Nov 17 22:07:17 2012 +0400
+++ b/QTfrontend/hwform.cpp	Sat Nov 17 22:45:30 2012 +0400
@@ -122,9 +122,7 @@
     , hwnet(0)
 {
     // set music track
-    SDLInteraction::instance().setMusicTrack(
-        DataManager::instance().findFileForRead("Music/main_theme.ogg")
-    );
+    SDLInteraction::instance().setMusicTrack("/Music/main_theme.ogg");
 
 #ifdef USE_XFIRE
     xfire_init();
--- a/QTfrontend/main.cpp	Sat Nov 17 22:07:17 2012 +0400
+++ b/QTfrontend/main.cpp	Sat Nov 17 22:45:30 2012 +0400
@@ -227,8 +227,6 @@
     engine.mount(cfgdir->absolutePath(), "/config");
     engine.setWriteDir(cfgdir->absolutePath());
 
-    DataManager & dataMgr = DataManager::instance();
-
     QTranslator Translator;
     {
         QSettings settings("physfs://config/hedgewars.ini", QSettings::IniFormat);
@@ -280,7 +278,7 @@
     }
 
     // load external stylesheet if there is any
-    QFile extFile(dataMgr.findFileForRead("css/" + fname));
+    QFile extFile("physfs://css/" + fname);
 
     QFile resFile(":/res/css/" + fname);
 
--- a/QTfrontend/model/GameStyleModel.cpp	Sat Nov 17 22:07:17 2012 +0400
+++ b/QTfrontend/model/GameStyleModel.cpp	Sat Nov 17 22:45:30 2012 +0400
@@ -55,8 +55,7 @@
     {
         script = script.remove(".lua", Qt::CaseInsensitive);
 
-        QFile scriptCfgFile(DataManager::instance().findFileForRead(
-                            QString("Scripts/Multiplayer/%2.cfg").arg(script)));
+        QFile scriptCfgFile(QString("physfs://Scripts/Multiplayer/%2.cfg").arg(script));
 
         QString name = script;
         name = name.replace("_", " ");
--- a/QTfrontend/model/HatModel.cpp	Sat Nov 17 22:07:17 2012 +0400
+++ b/QTfrontend/model/HatModel.cpp	Sat Nov 17 22:45:30 2012 +0400
@@ -46,9 +46,7 @@
 
     DataManager & dataMgr = DataManager::instance();
 
-    QPixmap hhpix = QPixmap(
-                        dataMgr.findFileForRead("Graphics/Hedgehog/Idle.png")
-                    ).copy(0, 0, 32, 32);
+    QPixmap hhpix = QPixmap("physfs://Graphics/Hedgehog/Idle.png").copy(0, 0, 32, 32);
 
     // my reserved hats
     QStringList hatsList = dataMgr.entryList(
@@ -76,11 +74,9 @@
 
         QString str = hatsList.at(i);
         str = str.remove(QRegExp("\\.png$"));
-        QPixmap pix(
-            dataMgr.findFileForRead(
-                "Graphics/Hats/" + QString(isReserved?"Reserved/":"") + str +
-                ".png"
-            )
+        QPixmap pix(            
+                "physfs://Graphics/Hats/" + QString(isReserved?"Reserved/":"") + str +
+                ".png"           
         );
 
         // rename properly
--- a/QTfrontend/model/MapModel.cpp	Sat Nov 17 22:07:17 2012 +0400
+++ b/QTfrontend/model/MapModel.cpp	Sat Nov 17 22:45:30 2012 +0400
@@ -62,10 +62,8 @@
     // add mission/static maps to lists
     foreach (QString map, maps)
     {
-        mapCfgFile.setFileName(
-            datamgr.findFileForRead(QString("Maps/%1/map.cfg").arg(map)));
-        mapLuaFile.setFileName(
-            datamgr.findFileForRead(QString("Maps/%1/map.lua").arg(map)));
+        mapCfgFile.setFileName(QString("physfs://Maps/%1/map.cfg").arg(map));
+        mapLuaFile.setFileName(QString("physfs://Maps/%1/map.lua").arg(map));
 
 
         if (mapCfgFile.open(QFile::ReadOnly))
--- a/QTfrontend/model/ThemeModel.cpp	Sat Nov 17 22:07:17 2012 +0400
+++ b/QTfrontend/model/ThemeModel.cpp	Sat Nov 17 22:45:30 2012 +0400
@@ -66,8 +66,7 @@
     foreach (QString theme, themes)
     {
         // themes without icon are supposed to be hidden
-        QString iconpath =
-            datamgr.findFileForRead(QString("Themes/%1/icon.png").arg(theme));
+        QString iconpath = QString("physfs://Themes/%1/icon.png").arg(theme);
 
         if (!QFile::exists(iconpath))
             continue;
@@ -83,7 +82,7 @@
         dataset.insert(Qt::DecorationRole, icon);
 
         // load and set preview icon
-        QIcon preview(datamgr.findFileForRead(QString("Themes/%1/icon@2x.png").arg(theme)));
+        QIcon preview(QString("physfs://Themes/%1/icon@2x.png").arg(theme));
         dataset.insert(Qt::UserRole, preview);
 
         m_data.append(dataset);
--- a/QTfrontend/ui/mouseoverfilter.cpp	Sat Nov 17 22:07:17 2012 +0400
+++ b/QTfrontend/ui/mouseoverfilter.cpp	Sat Nov 17 22:45:30 2012 +0400
@@ -41,8 +41,7 @@
         QTabWidget * tab = dynamic_cast<QTabWidget*>(dist);
         if (HWForm::config->isFrontendSoundEnabled() && (button || textfield || checkbox || droplist || slider || tab))
         {
-            DataManager & dataMgr = DataManager::instance();
-            SDLInteraction::instance().playSoundFile(dataMgr.findFileForRead("Sounds/steps.ogg"));
+            SDLInteraction::instance().playSoundFile("/Sounds/steps.ogg");
         }
 
         return true;
--- a/QTfrontend/ui/page/pageeditteam.cpp	Sat Nov 17 22:07:17 2012 +0400
+++ b/QTfrontend/ui/page/pageeditteam.cpp	Sat Nov 17 22:45:30 2012 +0400
@@ -270,7 +270,7 @@
 
     foreach (QString file, list)
     {
-        QPixmap pix(dataMgr.findFileForRead("Graphics/Graves/" + file));
+        QPixmap pix("physfs://Graphics/Graves/" + file);
         if ((pix.height() > 32) || pix.width() > 32)
             pix = pix.copy(0, 0, 32, 32);
         QIcon icon(pix);
@@ -297,7 +297,7 @@
         list.removeAt(idx);
 
     // add the default flag
-    QPixmap hwFlag(dataMgr.findFileForRead("Graphics/Flags/hedgewars.png"));
+    QPixmap hwFlag("physfs://Graphics/Flags/hedgewars.png");
     CBFlag->addItem(QIcon(hwFlag.copy(0, 0, 22, 15)), "Hedgewars", "hedgewars");
 
     // add seperator after
@@ -308,7 +308,7 @@
     // add all country flags
     foreach (const QString & file, list)
     {
-        QIcon icon(QPixmap(dataMgr.findFileForRead("Graphics/Flags/" + file)));
+        QIcon icon(QPixmap("physfs://Graphics/Flags/" + file));
 
         QString flag = QString(file).remove(pngSuffix);
 
@@ -337,8 +337,7 @@
 
 void PageEditTeam::CBFort_activated(const QString & fortname)
 {
-    DataManager & dataMgr = DataManager::instance();
-    QPixmap pix(dataMgr.findFileForRead("Forts/" + fortname + "L.png"));
+    QPixmap pix("physfs://Forts/" + fortname + "L.png");
     FortPreview->setPixmap(pix);
 }
 
@@ -360,10 +359,8 @@
                        );
 
     if (!list.isEmpty())
-        SDLInteraction::instance().playSoundFile(
-            dataMgr.findFileForRead(voiceDir + "/" +
-                                    list[rand() % list.size()])
-        );
+        SDLInteraction::instance().playSoundFile("physfs://" + voiceDir + "/" +
+                                    list[rand() % list.size()]);
 }
 
 void PageEditTeam::createTeam(const QString & name, const QString & playerHash)
--- a/QTfrontend/ui/page/pagetraining.cpp	Sat Nov 17 22:07:17 2012 +0400
+++ b/QTfrontend/ui/page/pagetraining.cpp	Sat Nov 17 22:45:30 2012 +0400
@@ -125,17 +125,15 @@
     if (loc.isEmpty())
         loc = QLocale::system().name();
 
-    QString infoFile = dataMgr.findFileForRead(
-                           QString("Locale/missions_" + loc + ".txt"));
+    QString infoFile = QString("physfs://Locale/missions_" + loc + ".txt");
 
     // if file is non-existant try with language only
     if (!QFile::exists(infoFile))
-        infoFile = dataMgr.findFileForRead(QString(
-                                               "Locale/missions_" + loc.remove(QRegExp("_.*$")) + ".txt"));
+        infoFile = QString("physfs://Locale/missions_" + loc.remove(QRegExp("_.*$")) + ".txt");
 
     // fallback if file for current locale is non-existant
     if (!QFile::exists(infoFile))
-        infoFile = dataMgr.findFileForRead(QString("Locale/missions_en.txt"));
+        infoFile = QString("physfs://Locale/missions_en.txt");
 
 
     // preload mission info for current locale
@@ -186,15 +184,12 @@
 
 void PageTraining::updateInfo()
 {
-    DataManager & dataMgr = DataManager::instance();
-
     if (lstMissions->currentItem())
     {
         // TODO also use .pngs in userdata folder
-        QString thumbFile = dataMgr.findFileForRead(
-                                "Graphics/Missions/Training/" +
+        QString thumbFile =     "physfs://Graphics/Missions/Training/" +
                                 lstMissions->currentItem()->data(Qt::UserRole).toString() +
-                                "@2x.png");
+                                "@2x.png";
 
         if (QFile::exists(thumbFile))
             btnPreview->setIcon(QIcon(thumbFile));
--- a/QTfrontend/ui/widget/chatwidget.cpp	Sat Nov 17 22:07:17 2012 +0400
+++ b/QTfrontend/ui/widget/chatwidget.cpp	Sat Nov 17 22:45:30 2012 +0400
@@ -64,7 +64,7 @@
     if (orgStyleSheet.isEmpty())
     {
         // load external stylesheet if there is any
-        QFile extFile(DataManager::instance().findFileForRead("css/chat.css"));
+        QFile extFile("physfs://css/chat.css");
 
         QFile resFile(":/res/css/chat.css");
 
@@ -194,12 +194,10 @@
 
         foreach (QString vp, vpList)
         {
-            m_helloSounds.append(DataManager::instance().findFileForRead(
-                               QString("Sounds/voices/%1/Hello.ogg").arg(vp)));
+            m_helloSounds.append(QString("physfs://Sounds/voices/%1/Hello.ogg").arg(vp));
         }
 
-        m_hilightSound = DataManager::instance().findFileForRead(
-                             "Sounds/beep.ogg");
+        m_hilightSound = "physfs://Sounds/beep.ogg";
 
     }
 
@@ -762,8 +760,7 @@
 
 void HWChatWidget::saveStyleSheet()
 {
-    QString dest =
-        DataManager::instance().findFileForWrite("css/chat.css");
+    QString dest = "physfs://css/chat.css";
 
     QFile file(dest);
     if (file.open(QIODevice::WriteOnly | QIODevice::Text))
--- a/QTfrontend/ui/widget/mapContainer.cpp	Sat Nov 17 22:07:17 2012 +0400
+++ b/QTfrontend/ui/widget/mapContainer.cpp	Sat Nov 17 22:45:30 2012 +0400
@@ -606,10 +606,7 @@
             break;
         default:
             QPixmap mapImage;
-            bool success = mapImage.load(
-                DataManager::instance().findFileForRead(
-                    "Maps/" + m_mapInfo.name + "/preview.png")
-            );
+            bool success = mapImage.load("physfs://Maps/" + m_mapInfo.name + "/preview.png");
 
             if(!success)
             {
--- a/QTfrontend/ui/widget/qpushbuttonwithsound.cpp	Sat Nov 17 22:07:17 2012 +0400
+++ b/QTfrontend/ui/widget/qpushbuttonwithsound.cpp	Sat Nov 17 22:45:30 2012 +0400
@@ -36,8 +36,6 @@
     if ( !isSoundEnabled || !HWForm::config->isFrontendSoundEnabled())
         return;
 
-    DataManager & dataMgr = DataManager::instance();
-
     if (this->isEnabled())
-        SDLInteraction::instance().playSoundFile(dataMgr.findFileForRead("Sounds/roperelease.ogg"));
+        SDLInteraction::instance().playSoundFile("/Sounds/roperelease.ogg");
 }
--- a/QTfrontend/util/DataManager.cpp	Sat Nov 17 22:07:17 2012 +0400
+++ b/QTfrontend/util/DataManager.cpp	Sat Nov 17 22:45:30 2012 +0400
@@ -74,28 +74,6 @@
     return result;
 }
 
-
-QString DataManager::findFileForRead(
-    const QString & relativeDataFilePath) const
-{
-    QString path("physfs://%1");
-
-    return path.arg(relativeDataFilePath);
-}
-
-
-QString DataManager::findFileForWrite(
-    const QString & relativeDataFilePath) const
-{
-    QString path("physfs://%1");
-
-    // create folders if needed
-    QDir tmp;
-    tmp.mkpath(QFileInfo(path.arg(relativeDataFilePath)).absolutePath());
-
-    return path;
-}
-
 GameStyleModel * DataManager::gameStyleModel()
 {
     if (m_gameStyleModel == NULL) {
--- a/QTfrontend/util/DataManager.h	Sat Nov 17 22:07:17 2012 +0400
+++ b/QTfrontend/util/DataManager.h	Sat Nov 17 22:45:30 2012 +0400
@@ -70,28 +70,6 @@
                              ) const;
 
         /**
-         * @brief Returns the path for the desires data file.
-         *
-         * Use this method if you want to read an existing data file.
-         *
-         * @param relativeDataFilePath relative path of the data file.
-         * @return real path to the file.
-         */
-        QString findFileForRead(const QString & relativeDataFilePath) const;
-
-
-        /**
-         * @brief Returns the path for the data file that is to be written.
-         *
-         * Use this method if you want to create or write into a data file.
-         *
-         * @param relativeDataFilePath relative path of data file write path.
-         * @return destination of path data file.
-         */
-        QString findFileForWrite(const QString & relativeDataFilePath) const;
-
-
-        /**
          * @brief Returns pointer to a model of available game styles.
          *
          * The model is updated automatically on data reload.
--- a/QTfrontend/util/namegen.cpp	Sat Nov 17 22:07:17 2012 +0400
+++ b/QTfrontend/util/namegen.cpp	Sat Nov 17 22:45:30 2012 +0400
@@ -125,8 +125,7 @@
     QStringList list;
 
     // find .txt to load the names from
-    QFile * file = new QFile(DataManager::instance().findFileForRead(QString(
-                                 "Names/%1.txt").arg(filename)));
+    QFile * file = new QFile(QString("physfs://Names/%1.txt").arg(filename));
 
     if (file->exists() && file->open(QIODevice::ReadOnly | QIODevice::Text))
     {
@@ -154,8 +153,7 @@
     QStringList list;
 
     // find .cfg to load the dicts from
-    QFile * file = new QFile(DataManager::instance().findFileForRead(QString(
-                                 "Names/%1.cfg").arg(hatname)));
+    QFile * file = new QFile(QString("physfs://Names/%1.cfg").arg(hatname));
 
     if (file->exists() && file->open(QIODevice::ReadOnly | QIODevice::Text))
     {
@@ -183,8 +181,7 @@
     typesAvailable = false;
 
     // find .ini to load the names from
-    QFile * file = new QFile(
-        DataManager::instance().findFileForRead(QString("Names/types.ini")));
+    QFile * file = new QFile(QString("physfs://Names/types.ini"));
 
 
     if (file->exists() && file->open(QIODevice::ReadOnly | QIODevice::Text))