- Fix saving .ini files
authorunc0rr
Thu, 22 Nov 2012 15:24:10 +0400
changeset 8098 4efee370e2de
parent 8095 df61e150eb70
child 8101 6d1570061d19
- Fix saving .ini files - Fix frontend effects value loading - Fix some places working with files not via physfs
QTfrontend/gameuiconfig.cpp
QTfrontend/hwform.cpp
QTfrontend/main.cpp
QTfrontend/team.cpp
QTfrontend/ui/page/pageoptions.cpp
QTfrontend/ui/page/pagetraining.cpp
QTfrontend/util/FileEngine.cpp
--- a/QTfrontend/gameuiconfig.cpp	Thu Nov 22 02:15:23 2012 +0100
+++ b/QTfrontend/gameuiconfig.cpp	Thu Nov 22 15:24:10 2012 +0400
@@ -44,10 +44,12 @@
 
 
 GameUIConfig::GameUIConfig(HWForm * FormWidgets, const QString & fileName)
-    : QSettings(fileName, QSettings::IniFormat)
+    : QSettings(fileName, QSettings::IniFormat, FormWidgets)
 {
     Form = FormWidgets;
 
+    setIniCodec("UTF-8");
+
     connect(Form->ui.pageOptions->CBEnableFrontendMusic, SIGNAL(toggled(bool)), Form, SLOT(Music(bool)));
 
     //Form->resize(value("frontend/width", 640).toUInt(), value("frontend/height", 450).toUInt());
@@ -77,7 +79,7 @@
 
     Form->ui.pageOptions->SLQuality->setValue(value("video/quality", 5).toUInt());
     Form->ui.pageOptions->CBStereoMode->setCurrentIndex(value("video/stereo", 0).toUInt());
-    Form->ui.pageOptions->CBEnableFrontendSound->setChecked(value("frontend/effects", true).toBool());
+    Form->ui.pageOptions->CBFrontendEffects->setChecked(value("frontend/effects", true).toBool());
     Form->ui.pageOptions->CBEnableSound->setChecked(value("audio/sound", true).toBool());
     Form->ui.pageOptions->CBEnableFrontendSound->setChecked(value("frontend/sound", true).toBool());
     Form->ui.pageOptions->CBEnableMusic->setChecked(value("audio/music", true).toBool());
@@ -96,7 +98,7 @@
     if (savePwd == false) {
         Form->ui.pageOptions->editNetPassword->setEnabled(savePwd);
         Form->ui.pageOptions->editNetPassword->setText("");
-        setNetPasswordLength(0);        
+        setNetPasswordLength(0);
     }
 
     delete netHost;
--- a/QTfrontend/hwform.cpp	Thu Nov 22 02:15:23 2012 +0100
+++ b/QTfrontend/hwform.cpp	Thu Nov 22 15:24:10 2012 +0400
@@ -127,7 +127,7 @@
 #ifdef USE_XFIRE
     xfire_init();
 #endif
-    gameSettings = new QSettings(cfgdir->absolutePath() + "/hedgewars.ini", QSettings::IniFormat);
+    gameSettings = new QSettings("physfs://hedgewars.ini", QSettings::IniFormat);
     frontendEffects = gameSettings->value("frontend/effects", true).toBool();
     playerHash = QString(QCryptographicHash::hash(gameSettings->value("net/nick","").toString().toUtf8(), QCryptographicHash::Md5).toHex());
 
@@ -139,7 +139,7 @@
 
     ui.pageOptions->CBResolution->addItems(SDLInteraction::instance().getResolutions());
 
-    config = new GameUIConfig(this, cfgdir->absolutePath() + "/hedgewars.ini");
+    config = new GameUIConfig(this, "physfs://hedgewars.ini");
 
     ui.pageVideos->init(config);
 
@@ -636,8 +636,8 @@
 
    /* if (id == ID_PAGE_DRAWMAP || id == ID_PAGE_GAMESTATS)
         stopAnim = true;
-	This were disabled due to broken flake animations.  I believe the more general problems w/ opacity that forced its disable makes blocking these
-	unnecessary.
+    This were disabled due to broken flake animations.  I believe the more general problems w/ opacity that forced its disable makes blocking these
+    unnecessary.
    */
 
 #if (QT_VERSION >= 0x040600)
@@ -695,8 +695,8 @@
         animationOldSlide->start(QAbstractAnimation::DeleteWhenStopped);
         animationNewSlide->start(QAbstractAnimation::DeleteWhenStopped);
 
-    	/* this is for the situation when the animation below is interrupted by a new animation.  For some reason, finished is not being fired */ 	
-    	for(int i=0;i<MAX_PAGE;i++) if (i!=id && i!=lastid) ui.Pages->widget(i)->hide();
+        /* this is for the situation when the animation below is interrupted by a new animation.  For some reason, finished is not being fired */
+        for(int i=0;i<MAX_PAGE;i++) if (i!=id && i!=lastid) ui.Pages->widget(i)->hide();
     }
 #endif
 }
--- a/QTfrontend/main.cpp	Thu Nov 22 02:15:23 2012 +0100
+++ b/QTfrontend/main.cpp	Thu Nov 22 15:24:10 2012 +0400
@@ -228,13 +228,14 @@
     // setup PhysFS
     engine.mount(datadir->absolutePath());
     engine.mount(cfgdir->absolutePath() + "/Data");
-    engine.mount(cfgdir->absolutePath(), "/config");
+    engine.mount(cfgdir->absolutePath());
     engine.setWriteDir(cfgdir->absolutePath());
     engine.mountPacks();
+    qDebug() << datadir->absolutePath();
 
     QTranslator Translator;
     {
-        QSettings settings("physfs://config/hedgewars.ini", QSettings::IniFormat);
+        QSettings settings("physfs://hedgewars.ini", QSettings::IniFormat);
         QString cc = settings.value("misc/locale", QString()).toString();
         if(cc.isEmpty())
             cc = QLocale::system().name();
--- a/QTfrontend/team.cpp	Thu Nov 22 02:15:23 2012 +0100
+++ b/QTfrontend/team.cpp	Thu Nov 22 15:24:10 2012 +0400
@@ -169,7 +169,7 @@
 
 bool HWTeam::loadFromFile()
 {
-    QSettings teamfile(QString("physfs://config/Teams/%1.hwt").arg(m_name), QSettings::IniFormat, 0);
+    QSettings teamfile(QString("physfs://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(QString("physfs://config/Teams/%1.hwt").arg(m_name));
+    QFile f(QString("physfs://Teams/%1.hwt").arg(m_name));
     return f.exists();
 }
 
@@ -210,7 +210,7 @@
 {
     if(m_isNetTeam)
         return false;
-    QFile cfgfile(QString("physfs://config/Teams/%1.hwt").arg(m_name));
+    QFile cfgfile(QString("physfs://Teams/%1.hwt").arg(m_name));
     cfgfile.remove();
     return true;
 }
@@ -219,11 +219,12 @@
 {
     if (OldTeamName != m_name)
     {
-        QFile cfgfile(QString("physfs://config/Teams/%1.hwt").arg(OldTeamName));
+        QFile cfgfile(QString("physfs://Teams/%1.hwt").arg(OldTeamName));
         cfgfile.remove();
         OldTeamName = m_name;
     }
-    QSettings teamfile(QString("physfs://config/Teams/%1.hwt").arg(m_name), QSettings::IniFormat, 0);
+
+    QSettings teamfile(QString("physfs://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);
@@ -234,6 +235,7 @@
     teamfile.setValue("Team/Rounds", m_rounds);
     teamfile.setValue("Team/Wins", m_wins);
     teamfile.setValue("Team/CampaignProgress", m_campaignProgress);
+
     for(int i = 0; i < HEDGEHOGS_PER_TEAM; i++)
     {
         QString hh = QString("Hedgehog%1/").arg(i);
@@ -251,6 +253,7 @@
             teamfile.setValue(QString("Achievements/%1").arg(achievements[i][0]), AchievementProgress[i]);
         else
             break;
+
     return true;
 }
 
--- a/QTfrontend/ui/page/pageoptions.cpp	Thu Nov 22 02:15:23 2012 +0100
+++ b/QTfrontend/ui/page/pageoptions.cpp	Thu Nov 22 15:24:10 2012 +0400
@@ -191,11 +191,7 @@
 
             // List of installed languages
             CBLanguage = new QComboBox(groupMisc);
-            QDir tmpdir;
-            tmpdir.cd(cfgdir->absolutePath());
-            tmpdir.cd("Data/Locale");
-            tmpdir.setFilter(QDir::Files);
-            QStringList locs = tmpdir.entryList(QStringList("hedgewars_*.qm"));
+            QStringList locs = DataManager::instance().entryList("Locale", QDir::Files, QStringList("hedgewars_*.qm"));
             CBLanguage->addItem(QComboBox::tr("(System default)"), QString(""));
             for(int i = 0; i < locs.count(); i++)
             {
@@ -203,17 +199,6 @@
                 CBLanguage->addItem(QLocale::languageToString(loc.language()) + " (" + QLocale::countryToString(loc.country()) + ")", loc.name());
             }
 
-            tmpdir.cd(datadir->absolutePath());
-            tmpdir.cd("Locale");
-            tmpdir.setFilter(QDir::Files);
-            QStringList tmplist = tmpdir.entryList(QStringList("hedgewars_*.qm"));
-            for(int i = 0; i < tmplist.count(); i++)
-            {
-                if (locs.contains(tmplist[i])) continue;
-                QLocale loc(tmplist[i].replace(QRegExp("hedgewars_(.*)\\.qm"), "\\1"));
-                CBLanguage->addItem(QLocale::languageToString(loc.language()) + " (" + QLocale::countryToString(loc.country()) + ")", loc.name());
-            }
-
             MiscLayout->addWidget(CBLanguage, 0, 1);
 
             // Label and field for net nick
--- a/QTfrontend/ui/page/pagetraining.cpp	Thu Nov 22 02:15:23 2012 +0100
+++ b/QTfrontend/ui/page/pagetraining.cpp	Thu Nov 22 15:24:10 2012 +0400
@@ -118,7 +118,7 @@
     DataManager & dataMgr = DataManager::instance();
 
     // get locale
-    QSettings settings(cfgdir->absolutePath() + "/hedgewars.ini",
+    QSettings settings("physfs://hedgewars.ini",
                        QSettings::IniFormat);
 
     QString loc = settings.value("misc/locale", "").toString();
--- a/QTfrontend/util/FileEngine.cpp	Thu Nov 22 02:15:23 2012 +0100
+++ b/QTfrontend/util/FileEngine.cpp	Thu Nov 22 15:24:10 2012 +0400
@@ -38,11 +38,11 @@
     }
 
     else {
-        qWarning("Bad file open mode: %d", (int)openMode);
+        qWarning("[PHYSFS] Bad file open mode: %d", (int)openMode);
     }
 
     if (!_handler) {
-        qWarning("Failed to open %s, reason: %s", _filename.toUtf8().constData(), PHYSFS_getLastError());
+        qWarning("[PHYSFS] Failed to open %s, reason: %s", _filename.toUtf8().constData(), PHYSFS_getLastError());
         return false;
     }