]> git.mxchange.org Git - simgear.git/blobdiff - simgear/io/sg_binobj.cxx
Use the new SGPath::create_dir function
[simgear.git] / simgear / io / sg_binobj.cxx
index dc951830fcaec958f3da10bb1e4edb6c84313593..9a6c3268eb91754998e1b581a667ad1ef527361a 100644 (file)
@@ -36,6 +36,7 @@
 #include STL_STRING
 
 #include <simgear/bucket/newbucket.hxx>
+#include <simgear/misc/sg_path.hxx>
 
 #include "lowlevel.hxx"
 #include "sg_binobj.hxx"
@@ -45,7 +46,7 @@ SG_USING_STD( string );
 SG_USING_STD( vector );
 
 
-enum {
+static enum {
     SG_BOUNDING_SPHERE = 0,
 
     SG_VERTEX_LIST = 1,
@@ -60,14 +61,14 @@ enum {
     SG_TRIANGLE_FANS = 12
 } sgObjectTypes;
 
-enum {
+static enum {
     SG_IDX_VERTICES =  0x01,
     SG_IDX_NORMALS =   0x02,
     SG_IDX_COLORS =    0x04,
     SG_IDX_TEXCOORDS = 0x08
 } sgIndexTypes;
 
-enum {
+static enum {
     SG_MATERIAL = 0,
     SG_INDEX_TYPES = 1
 } sgPropertyTypes;
@@ -620,20 +621,13 @@ bool SGBinObject::write_bin( const string& base, const string& name,
     unsigned char idx_mask;
     int idx_size;
 
-    string dir = base + "/" + b.gen_base_path();
-    string command = "mkdir -p " + dir;
-#if defined(_MSC_VER) || defined(__MINGW32__)
-    system( (string("mkdir ") + dir).c_str() );
-#else
-    system(command.c_str());
-#endif
-
-    string file = dir + "/" + name + ".gz";
-    cout << "Output file = " << file << endl;
+    SGPath file = base + "/" + b.gen_base_path() + "/" + name + ".gz";
+    file.create_dir( 0755 );
+    cout << "Output file = " << file.str() << endl;
 
     gzFile fp;
     if ( (fp = gzopen( file.c_str(), "wb9" )) == NULL ) {
-       cout << "ERROR: opening " << file << " for writing!" << endl;
+       cout << "ERROR: opening " << file.str() << " for writing!" << endl;
        return false;
     }
 
@@ -858,7 +852,8 @@ bool SGBinObject::write_bin( const string& base, const string& name,
            // find next group
            material = tri_materials[start];
            while ( (end < (int)tri_materials.size()) && 
-                   (material == tri_materials[end]) )
+                   (material == tri_materials[end]) &&
+                   3*(end-start) < 32760 )
            {
                // cout << "end = " << end << endl;
                end++;
@@ -1051,21 +1046,13 @@ bool SGBinObject::write_ascii( const string& base, const string& name,
     Point3D p;
     int i, j;
 
-    string dir = base + "/" + b.gen_base_path();
-    string command = "mkdir -p " + dir;
-#if defined(_MSC_VER) || defined(__MINGW32__)
-    system( (string("mkdir ") + dir).c_str() );
-#else
-    system(command.c_str());
-#endif
-
-    // string file = dir + "/" + b.gen_index_str();
-    string file = dir + "/" + name;
-    cout << "Output file = " << file << endl;
+    SGPath file = base + "/" + b.gen_base_path() + "/" + name;
+    file.create_dir( 0755 );
+    cout << "Output file = " << file.str() << endl;
 
     FILE *fp;
     if ( (fp = fopen( file.c_str(), "w" )) == NULL ) {
-       cout << "ERROR: opening " << file << " for writing!" << endl;
+       cout << "ERROR: opening " << file.str() << " for writing!" << endl;
        return false;
     }
 
@@ -1224,7 +1211,7 @@ bool SGBinObject::write_ascii( const string& base, const string& name,
     // close the file
     fclose(fp);
 
-    command = "gzip --force --best " + file;
+    string command = "gzip --force --best " + file.str();
     system(command.c_str());
 
     return true;