Merge branch 'master' of http://git.roojs.com/roobuilder
[roobuilder] / src / Resources.vala
index 682559c..6dceca7 100644 (file)
@@ -39,20 +39,24 @@ public class ResourcesItem : Object {
                }
                uint8[] data;
                uint8[] zero = { 0 };
-               GLib.FileUtils.get_data(tfn, out data);
-               
-               var  file = File.new_for_path (tfn);
-                
-               var info = file.query_info(
-                                "standard::*",
-                               FileQueryInfoFlags.NONE
-               );
-               var csdata = new GLib.ByteArray.take("blob %s".printf(info.get_size().to_string()).data);
-               csdata.append(zero);
-               csdata.append(data);
-                
-               // git method... blob %d\0...string...
-               this.cur_sha = GLib.Checksum.compute_for_data(GLib.ChecksumType.SHA1, csdata.data       );
+               try {
+                       GLib.FileUtils.get_data(tfn, out data);
+                       
+                       var  file = File.new_for_path (tfn);
+                        
+                       var info = file.query_info(
+                                        "standard::*",
+                                       FileQueryInfoFlags.NONE
+                       );
+                       var csdata = new GLib.ByteArray.take("blob %s".printf(info.get_size().to_string()).data);
+                       csdata.append(zero);
+                       csdata.append(data);
+                        
+                       // git method... blob %d\0...string...
+                       this.cur_sha = GLib.Checksum.compute_for_data(GLib.ChecksumType.SHA1, csdata.data       );
+               } catch (GLib.Error e) {
+                       GLib.debug("Failed to update SHA: %s", e.message);
+               }
        }
        
 }
@@ -86,10 +90,11 @@ public class Resources : Object
        public void initFiles()
        {       
                string[] avail_files = { 
-                       "roodata.json",
-                       "*",
-                       "Editors/*.js",
-                       "vapi/*"
+                       "roodata.json", /// << this is the only one we get now..
+//                     "flutter_tree.json",
+//                     "*",
+       //              "Editors/*.js",
+//                     "vapi/*"
                        
                };
                this.fetch_files = new Gee.ArrayList<ResourcesItem>();
@@ -99,8 +104,11 @@ public class Resources : Object
                         
                        if (target == "roodata.json") {
                                src = "https://raw.githubusercontent.com/roojs/roojs1/master/docs/json/roodata.json";
-                               //src = "http://git.roojs.org/?p=roojs1;a=blob_plain;f=docs/json/roodata.json";
                        }
+                       if (target == "flutter_tree.json") {
+                               src = "https://raw.githubusercontent.com/roojs/flutter-docs-json/master/tree.json";
+                       }
+                       /*
                        if (target.contains("*")) {
                                var split = target.split("*");
                                
@@ -111,7 +119,7 @@ public class Resources : Object
                                }
                                
                        }
-                       
+                       */
                        this.fetch_files.add(new ResourcesItem(src,target, ""));
                }
        
@@ -156,14 +164,19 @@ public class Resources : Object
                
                // this has to check the required files, not the list...
                string[] required =  {
-                       "bootstrap.builder.html",
-                       "Gir.overides",
-                       "GtkUsage.txt",
+                       /*"bootstrap.builder.html",
+                       "bootstrap4.builder.html",
+                        
                        "mailer.builder.html",
                        "roo.builder.html",
                        "roo.builder.js",
+                       */
+                       
                        "roodata.json",
-                       "RooUsage.txt"
+                       
+                       //"RooUsage.txt" ?? not needed it's doen from roodata.
+               //      "Gir.overides" //?? needed anymnore?
+                       
                };
 
                for (var i = 0; i <  required.length; i++ ) { 
@@ -183,9 +196,14 @@ public class Resources : Object
                 
        public void parseDirectory(string json, string target)
        {
-               print("%s\n", json);
+               GLib.debug("%s\n", json);
                var pa = new Json.Parser();
-               pa.load_from_data(json);
+               try {
+                       pa.load_from_data(json);
+               } catch (GLib.Error e) {
+                       GLib.debug("Faile dto load json file %s", e.message);
+                       return;
+               }
                var node = pa.get_root();
                if (node.get_node_type () != Json.NodeType.ARRAY) {
                        return;
@@ -244,46 +262,68 @@ public class Resources : Object
                var session = new Soup.Session ();
                session.user_agent = "App Builder ";
            var message = new Soup.Message ("GET",  item.src );
-        session.queue_message (message, (sess, mess) => {
+        session.send_and_read_async.begin( message, 0,  null, (obj, res) => {
+               GLib.Bytes bytes;
+                try {
+                               bytes = session.send_and_read_async.end(res);
+                         } catch (GLib.Error e) {
+                               GLib.debug("Failed to fetch stream %s" , e.message);
+                               this.fetchNext();
+                               return;
+                       }
+                               
                        
+               
                        if (item.target.contains("*")) {
                                // then it's a directory listing in JSON, and we need to add any new items to our list..
                                // it's used to fetch Editors (and maybe other stuff..)
-                               this.parseDirectory((string) message.response_body.data,item.target );
+                               this.parseDirectory( (string) bytes.get_data(),item.target );
                                this.fetchNext();
                                return;
                        }
                        
-                       
+                        
                        var tfn = BuilderApplication.configDirectory() + "/resources/" + item.target;
                        
                        
                        // create parent directory if needed
                        if (!GLib.FileUtils.test (GLib.Path.get_dirname(tfn), FileTest.IS_DIR)) {
                                var f =  GLib.File.new_for_path(GLib.Path.get_dirname(tfn));
-                               f.make_directory_with_parents ();
+                               try {
+                                       f.make_directory_with_parents ();
+                               } catch(GLib.Error e) {
+                                       GLib.error("Problem creating directory %s", e.message);
+                               }
                        }
                        
                        
-                       
-                       
                        // set data??? - if it's binary?
-            FileUtils.set_contents(  tfn, (string) message.response_body.data );
-            
+                       try {
+                        FileUtils.set_contents(  tfn,  (string) bytes.get_data());
+            } catch(GLib.Error e) {
+                                       GLib.error("Problem writing data %s", e.message);
+                               }
             switch (item.target) {
+            /*
                                case "Gir.overides":
                                        // clear all the project caches....
-                                       
-                                       Palete.Gir.factory("Gtk").loadOverrides(true);
-                                       break;
-                                       
-                               case "GtkUsage.txt":
-                                       Palete.factory("Gtk").load();
+                                       foreach(var p in Project.Project.allProjectsByName()) { 
+                                               if (p is Project.Gtk) {
+                                                       ((Project.Gtk)p).gir_cache = new Gee.HashMap<string,Palete.Gir>();
+                                               }
+                                       }
+
                                        break;
+                               */ 
                                        
                                case "roodata.json":
-                                       Palete.factory("Roo").classes  = null;
-                                       Palete.factory("Roo").load();
+                                       Palete.Roo.classes_cache = null; // clear the cache.
+                                       foreach(var p in Project.Project.allProjectsByName()) { 
+                                               if (p is Project.Roo) {
+                                                       p.palete = new Palete.Roo(p);
+                                                       //p.palete.load();
+                                               }
+                                       }
                                        break;
                                        
                                default: