JSDOC/Packer.vala
[gnome.introspection-doc-generator] / JSDOC / Packer.vala
index 49c6ac2..3a6f406 100644 (file)
@@ -67,7 +67,7 @@ namespace JSDOC
                /**
                 * @cfg {String} debugTarget target to write files debug version to (uncompacted)- must be full path.
                 */
-               string debugTarget;
+               string targetDebug;
        
                /**
                 * @cfg {String} tmpDir  (optional) where to put the temporary files. 
@@ -97,10 +97,10 @@ namespace JSDOC
                
                public  string out = ""; // if no target is specified - then this will contain the result
     
-               public Packer(string target, string debugTarget)
+               public Packer(string target, string targetDebug = "")
                {
                        this.target = target;
-                       this.debugTarget  = debugTarget;
+                       this.targetDebug  = targetDebug;
                
                }
                
@@ -117,12 +117,20 @@ namespace JSDOC
                                this.files.add(f); //?? easier way?
                        }
                }
+               FileOutputStream targetStream = null;
+               FileOutputStream targetDebugStream  = null;
                
                public void pack()
                {
                    if (!this.files) {
                                throw new Packer.ArgumentError("No Files loaded before pack() called");
                        }
+                       if (this.target.length > 0 ) {
+                               this.targetStream = File.new_for_path(this.target).replace(null, false,FileCreateFlags.NONE);
+                       }
+                       if (this.targetDebug.length > 0 ) {
+                               this.targetDebugStream = File.new_for_path(this.targetDebug).replace(null, false,FileCreateFlags.NONE);
+                       }
                        this.packAll();
                }
                
@@ -172,37 +180,35 @@ namespace JSDOC
                        
                    }
                }
-    
+               
     
                private void packAll()  // do the packing (run from constructor)
                {
                    
                    //this.transOrigFile= bpath + '/../lang.en.js'; // needs better naming...
                    //File.write(this.transfile, "");
-                   if (this.target) {
-                       File.write(this.target, "");
+                   if (this.target.length > 0) {
+                       this.targetStream.write("");
                    }
                    
-                   if (this.debugTarget) {
-                       File.write(this.debugTarget, "");
-                   }
-                   if (this.debugTranslateTarget) {
-                       File.write(this.debugTarget, "");
+                   if (this.debugTarget > 0) {
+                           this.targetDebugStream.write("");
                    }
-                   
-                   for(var i=0; i < this.files.length; i++)  {
-                       var file = this.files[i];
+                   foreach(var file in this.files) {
                        
-                       print("reading " +file );
-                       if (!File.isFile(file)) {
-                           print("SKIP (is not a file) " + file);
+                       print("reading %s\n",file );
+                       
+                       if (FileUtils.test (file, FileTest.EXISTS) && ! FileUtils.test (file, FileTest.IS_DIR)) {
+                           print("SKIP (is not a file) %s\n ", file);
                            continue;
                        }
                       
                        // debug Target
                        
-                       if (this.debugTarget) {
-                           File.append(this.debugTarget, File.read(file));
+                       if (this.debugTargetStream !=null) {
+                               string str;
+                               FileUtils.get_contents(file,out str);
+                           this.debugTarget.write(str);
                        }
                        // it's a good idea to check with 0 compression to see if the code can parse!!
                        
@@ -211,12 +217,13 @@ namespace JSDOC
                        
                   
                        
-                       var minfile = this.tmpDir + '/' +file.replace(/\//g, '.');
+                       var minfile = this.tmpDir + '/' + file.replace("/", '.');
                        
                        
                        // let's see if we have a min file already?
                        // this might happen if tmpDir is set .. 
-                       if (true && File.exists(minfile)) {
+                       
+                       if (true && FileUtils.test (minfile, FileTest.EXISTS)) {
                            var mt = File.mtime(minfile);
                            var ot = File.mtime(file);
                            print("compare : " + mt + "=>" + ot);