netpanzer-cvs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[netPanzer-CVS] netpanzer/src NetPanzer/Interfaces/GameConfig.c...


From: Matthias Braun
Subject: [netPanzer-CVS] netpanzer/src NetPanzer/Interfaces/GameConfig.c...
Date: Mon, 22 Sep 2003 11:15:52 -0400

CVSROOT:        /cvsroot/netpanzer
Module name:    netpanzer
Branch:         
Changes by:     Matthias Braun <address@hidden> 03/09/22 11:15:51

Modified files:
        src/NetPanzer/Interfaces: GameConfig.cpp 
        src/Lib/Xml    : XmlConfig.cpp XmlParser.cpp XmlStore.cpp 
                         XmlStore.hpp 

Log message:
        conerted xmlstore to really use physfs, unfortunately I wasn't able 
todo the same for the parser since it seems to use some libxml internals...

Patches:
Index: netpanzer/src/Lib/Xml/XmlConfig.cpp
diff -u netpanzer/src/Lib/Xml/XmlConfig.cpp:1.1 
netpanzer/src/Lib/Xml/XmlConfig.cpp:1.2
--- netpanzer/src/Lib/Xml/XmlConfig.cpp:1.1     Sat Sep 20 18:40:15 2003
+++ netpanzer/src/Lib/Xml/XmlConfig.cpp Mon Sep 22 11:15:50 2003
@@ -15,6 +15,7 @@
 along with this program; if not, write to the Free Software
 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 */
+#include <config.h>
 
 #include "XmlConfig.hpp"
 #include "XmlParser.hpp"
Index: netpanzer/src/Lib/Xml/XmlParser.cpp
diff -u netpanzer/src/Lib/Xml/XmlParser.cpp:1.1 
netpanzer/src/Lib/Xml/XmlParser.cpp:1.2
--- netpanzer/src/Lib/Xml/XmlParser.cpp:1.1     Sat Sep 20 18:40:15 2003
+++ netpanzer/src/Lib/Xml/XmlParser.cpp Mon Sep 22 11:15:51 2003
@@ -15,6 +15,7 @@
 along with this program; if not, write to the Free Software
 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 */
+#include <config.h>
 
 #include <string>
 #include <libxml/parser.h>
Index: netpanzer/src/Lib/Xml/XmlStore.cpp
diff -u netpanzer/src/Lib/Xml/XmlStore.cpp:1.1 
netpanzer/src/Lib/Xml/XmlStore.cpp:1.2
--- netpanzer/src/Lib/Xml/XmlStore.cpp:1.1      Sat Sep 20 18:40:15 2003
+++ netpanzer/src/Lib/Xml/XmlStore.cpp  Mon Sep 22 11:15:51 2003
@@ -15,9 +15,11 @@
 along with this program; if not, write to the Free Software
 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 */
+#include <config.h>
 
 #include "XmlStore.hpp"
 #include "XmlParser.hpp"
+#include "FileSystem.hpp"
 #include "Exception.hpp"
 #include "Log.hpp"
 
@@ -84,6 +86,51 @@
 {
     xmlSetProp(m_node, (const xmlChar*)name, (const xmlChar*)value);
 }
+
+class XMLPhysfsWriter
+{
+public:
+    XMLPhysfsWriter(WriteFile* newfile)
+        : file(newfile)
+    {
+        buffer = xmlOutputBufferCreateIO(write, close, file, 0);
+    }
+
+    ~XMLPhysfsWriter()
+    {
+        delete file;
+    }
+
+    xmlOutputBufferPtr getXMLBuffer()
+    { return buffer; }
+        
+
+private:
+    static int write(void* context, const char* buffer, int len)
+    {
+        WriteFile* file = (WriteFile*) context;
+
+        try {
+            if(file->write(buffer, len, 1) != 1) {
+                LOGGER.warning("Write error while saving xml");
+                return 0;
+            }
+        } catch(...) {
+            LOGGER.warning("Write error while saving xml");
+            return 0;
+        }
+        return len;
+    }
+    
+    static int close(void*)
+    {
+        return 0;
+    }
+    
+    xmlOutputBufferPtr buffer;
+    WriteFile* file;
+};
+
 //-----------------------------------------------------------------
 /**
  * Save configuration on disk.
@@ -92,12 +139,16 @@
 void
 XmlStore::save(const char *filename)
 {
+    WriteFile* file = FileSystem::openWrite(filename);
+    XMLPhysfsWriter xmlio(file);
+    
     if (m_doc == 0) {
         throw Exception("xml store: child cannot save document");
     }
-    if (xmlSaveFormatFile(filename, m_doc, 1) == -1) {
+    if (xmlSaveFormatFileTo(xmlio.getXMLBuffer(), m_doc, 0, 1) == -1) {
         throw Exception("xml store: cannot save xml to file '%s'", filename);
     }
+
     LOGGER.debug("saved xml config '%s'", filename);
 }
 
Index: netpanzer/src/Lib/Xml/XmlStore.hpp
diff -u netpanzer/src/Lib/Xml/XmlStore.hpp:1.1 
netpanzer/src/Lib/Xml/XmlStore.hpp:1.2
--- netpanzer/src/Lib/Xml/XmlStore.hpp:1.1      Sat Sep 20 18:40:15 2003
+++ netpanzer/src/Lib/Xml/XmlStore.hpp  Mon Sep 22 11:15:51 2003
@@ -15,7 +15,6 @@
 along with this program; if not, write to the Free Software
 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 */
-
 #ifndef XMLSTORE_H
 #define XMLSTORE_H
 
Index: netpanzer/src/NetPanzer/Interfaces/GameConfig.cpp
diff -u netpanzer/src/NetPanzer/Interfaces/GameConfig.cpp:1.8 
netpanzer/src/NetPanzer/Interfaces/GameConfig.cpp:1.9
--- netpanzer/src/NetPanzer/Interfaces/GameConfig.cpp:1.8       Sat Sep 20 
18:40:15 2003
+++ netpanzer/src/NetPanzer/Interfaces/GameConfig.cpp   Mon Sep 22 11:15:49 2003
@@ -200,12 +200,7 @@
     visuals.writeInt("unit_flags", display_unit_flags);
     visuals.writeInt("unit_color", UnitColor);
 
-    if (!FileSystem::exists(configfile.c_str())) {
-        // hack, touch file
-        delete FileSystem::openWrite(configfile.c_str());
-    }
-    const char *xmlfile = FileSystem::getRealName(configfile.c_str()).c_str();
-    xmlStore.save(xmlfile);
+    xmlStore.save(configfile.c_str());
 }
 
 void GameConfig::setGameMapName( char *map_name )




reply via email to

[Prev in Thread] Current Thread [Next in Thread]