Create hedgewars.ini if not exists manually,
authorunc0rr
Mon, 03 Dec 2012 23:54:12 +0400
changeset 8206 1633a6510834
parent 8205 921e63507bea
child 8207 5f08609613fe
child 8208 171da01bd04d
Create hedgewars.ini if not exists manually, as QSettings uses QTemporaryFile for that, and QTemporaryFile doesn't respect custom file engines.
QTfrontend/gameuiconfig.cpp
QTfrontend/main.cpp
QTfrontend/util/FileEngine.cpp
--- a/QTfrontend/gameuiconfig.cpp	Mon Dec 03 18:08:19 2012 +0100
+++ b/QTfrontend/gameuiconfig.cpp	Mon Dec 03 23:54:12 2012 +0400
@@ -310,7 +310,6 @@
 
 void GameUIConfig::setValue(const QString &key, const QVariant &value)
 {
-    qDebug() << "[settings]" << key << value;
     QSettings::setValue(key, value);
 }
 
--- a/QTfrontend/main.cpp	Mon Dec 03 18:08:19 2012 +0100
+++ b/QTfrontend/main.cpp	Mon Dec 03 23:54:12 2012 +0400
@@ -90,9 +90,9 @@
 
 bool checkForDir(const QString & dir)
 {
-    QDir tmpdir;
-    if (!tmpdir.exists(dir))
-        if (!tmpdir.mkdir(dir))
+    QDir tmpdir(dir);
+    if (!tmpdir.exists())
+        if (!tmpdir.mkpath(dir))
         {
             QMessageBox directoryMsg(QApplication::activeWindow());
             directoryMsg.setIcon(QMessageBox::Warning);
@@ -105,6 +105,15 @@
     return true;
 }
 
+bool checkForFile(const QString & file)
+{
+    QFile tmpfile(file);
+    if (!tmpfile.exists())
+        return tmpfile.open(QFile::WriteOnly);
+    else
+        return true;
+}
+
 #ifdef __APPLE__
 static CocoaInitializer *cocoaInit = NULL;
 // Function to be called at end of program's termination on OS X to release
@@ -252,6 +261,8 @@
     engine.setWriteDir(cfgdir->absolutePath());
     engine.mountPacks();
 
+    checkForFile("physfs://hedgewars.ini");
+
     QTranslator Translator;
     {
         QSettings settings("physfs://hedgewars.ini", QSettings::IniFormat);
--- a/QTfrontend/util/FileEngine.cpp	Mon Dec 03 18:08:19 2012 +0100
+++ b/QTfrontend/util/FileEngine.cpp	Mon Dec 03 23:54:12 2012 +0400
@@ -10,6 +10,7 @@
 
 FileEngine::FileEngine(const QString& filename)
     : m_handle(NULL)
+    , m_size(0)
     , m_flags(0)
     , m_bufferSet(false)
     , m_readWrite(false)
@@ -28,8 +29,11 @@
 
     if ((openMode & QIODevice::ReadWrite) == QIODevice::ReadWrite) {
         m_handle = PHYSFS_openAppend(m_fileName.toUtf8().constData());
-        m_readWrite = true;
-        seek(0);
+        if(m_handle)
+        {
+            m_readWrite = true;
+            seek(0);
+        }
     }
 
     else if (openMode & QIODevice::WriteOnly) {
@@ -114,12 +118,14 @@
 bool FileEngine::mkdir(const QString &dirName, bool createParentDirectories) const
 {
     Q_UNUSED(createParentDirectories);
+
     return PHYSFS_mkdir(dirName.toUtf8().constData()) != 0;
 }
 
 bool FileEngine::rmdir(const QString &dirName, bool recurseParentDirectories) const
 {
     Q_UNUSED(recurseParentDirectories);
+
     return PHYSFS_delete(dirName.toUtf8().constData()) != 0;
 }
 
@@ -191,7 +197,6 @@
 
 QDateTime FileEngine::fileTime(FileTime time) const
 {
-
     switch (time)
     {
         case QAbstractFileEngine::ModificationTime:
@@ -207,21 +212,21 @@
         m_fileName = file.mid(FileEngineHandler::scheme.size());
     else
         m_fileName = file;
-
     PHYSFS_Stat stat;
     if (PHYSFS_stat(m_fileName.toUtf8().constData(), &stat) != 0) {        
         m_size = stat.filesize;
         m_date = QDateTime::fromTime_t(stat.modtime);
-//        _flags |= QAbstractFileEngine::WriteUserPerm;
+//        m_flags |= QAbstractFileEngine::WriteOwnerPerm;
+        m_flags |= QAbstractFileEngine::ReadOwnerPerm;
         m_flags |= QAbstractFileEngine::ReadUserPerm;
         m_flags |= QAbstractFileEngine::ExistsFlag;
+        m_flags |= QAbstractFileEngine::LocalDiskFlag;
 
         switch (stat.filetype)
         {
             case PHYSFS_FILETYPE_REGULAR:
                 m_flags |= QAbstractFileEngine::FileType;
                 break;
-
             case PHYSFS_FILETYPE_DIRECTORY:
                 m_flags |= QAbstractFileEngine::DirectoryType;
                 break;