From 295d72960cad391850803e8c4e83d5133bbe82f7 Mon Sep 17 00:00:00 2001 From: Jose Antonio Marquez Date: Mon, 6 Feb 2012 11:40:15 -0800 Subject: Setting up library detection for Chrome File System --- js/io/system/chromeapi.js | 30 ++++++++++++++++++++++++++---- js/io/system/coreioapi.js | 19 ++++++++++++++++++- 2 files changed, 44 insertions(+), 5 deletions(-) (limited to 'js/io') diff --git a/js/io/system/chromeapi.js b/js/io/system/chromeapi.js index 6bf6b9fe..f4e04a09 100644 --- a/js/io/system/chromeapi.js +++ b/js/io/system/chromeapi.js @@ -31,6 +31,8 @@ exports.ChromeApi = Montage.create(Object.prototype, { var readyEvent = document.createEvent("CustomEvent"); readyEvent.initEvent('ready', true, true); this.dispatchEvent(readyEvent); + //Building data of local Ninja Library + this._listNinjaChromeLibrary(); }.bind(this), function (e) {return false}); //Returns false on error (not able to init) // return true; @@ -73,10 +75,17 @@ exports.ChromeApi = Montage.create(Object.prototype, { } }, //////////////////////////////////////////////////////////////////// - // + //Returns the directory contents to a callback function directoryContents: { enumerable: true, - value: function() { + value: function(directory, callback) { + //Creating instance of directory reader + this.fileSystem.directoryReader = directory.createReader(); + //Getting directory contents and sending results to callback + this.fileSystem.directoryReader.readEntries(function(results) { + //Calling callback with results (null if invalid directory) + callback(results); + }, function (e) {callback(null)}); } }, //////////////////////////////////////////////////////////////////// @@ -102,11 +111,24 @@ exports.ChromeApi = Montage.create(Object.prototype, { }, //////////////////////////////////////////////////////////////////// // - getLocalLibrary: { + _listNinjaChromeLibrary: { enumerable: false, value: function () { + function parseLibrary (contents) { + // + var lib = []; + // + + + + //Dispatching action ready event + var libraryEvent = document.createEvent("CustomEvent"); + libraryEvent.initEvent('library', true, true); + libraryEvent.ninjaChromeLibrary = lib; + this.dispatchEvent(libraryEvent); + }; // - return {}; + this.directoryContents(this.fileSystem.root, parseLibrary.bind(this)); } } //////////////////////////////////////////////////////////////////// diff --git a/js/io/system/coreioapi.js b/js/io/system/coreioapi.js index 3fb9374a..3be6011d 100755 --- a/js/io/system/coreioapi.js +++ b/js/io/system/coreioapi.js @@ -55,8 +55,25 @@ exports.CoreIoApi = Montage.create(Component, { handleReady: { enumerable: false, value: function (e) { + // this.chromeFileSystem.removeEventListener('ready', this, false); - this.chromeNinjaLibrary = this.chromeFileSystem.getLocalLibrary(); + // + this.chromeFileSystem.addEventListener('library', this, false); + } + }, + //////////////////////////////////////////////////////////////////// + // + handleLibrary: { + enumerable: false, + value: function (e) { + // + this.chromeFileSystem.removeEventListener('library', this, false); + // + if (e._event.ninjaChromeLibrary.length < 1) { + console.log('no libraries'); + } else { + console.log('found libraries'); + } } }, //////////////////////////////////////////////////////////////////// -- cgit v1.2.3 From 0db246b19dc0b50f4f663a147ec92c49e656ae35 Mon Sep 17 00:00:00 2001 From: Jose Antonio Marquez Date: Mon, 6 Feb 2012 16:32:15 -0800 Subject: Adding logic to copy ninja libraries Setting up the logic to handling copying ninja required libraries into the app local file system sandbox to be used by cloud simulator. --- js/io/system/chromeapi.js | 11 +++++++++-- js/io/system/coreioapi.js | 37 +++++++++++++++++++++++++++++++------ js/io/system/ninjalibrary.json | 6 ++++++ 3 files changed, 46 insertions(+), 8 deletions(-) create mode 100644 js/io/system/ninjalibrary.json (limited to 'js/io') diff --git a/js/io/system/chromeapi.js b/js/io/system/chromeapi.js index f4e04a09..fb141687 100644 --- a/js/io/system/chromeapi.js +++ b/js/io/system/chromeapi.js @@ -69,9 +69,16 @@ exports.ChromeApi = Montage.create(Object.prototype, { //////////////////////////////////////////////////////////////////// // - directoryDelete: {//TODO: Make sure it uses a force delete + directoryDelete: { enumerable: true, - value: function() { + value: function(directoryPath, callback) { + // + this.fileSystem.getDirectory(directoryPath, {}, function(dirEntry) { + // + dirEntry.removeRecursively(function() { + callback(true); + }); + }, function (e) {callback(false)}); } }, //////////////////////////////////////////////////////////////////// diff --git a/js/io/system/coreioapi.js b/js/io/system/coreioapi.js index 3be6011d..b821936f 100755 --- a/js/io/system/coreioapi.js +++ b/js/io/system/coreioapi.js @@ -66,14 +66,39 @@ exports.CoreIoApi = Montage.create(Component, { handleLibrary: { enumerable: false, value: function (e) { - // + //Removing events this.chromeFileSystem.removeEventListener('library', this, false); // - if (e._event.ninjaChromeLibrary.length < 1) { - console.log('no libraries'); - } else { - console.log('found libraries'); - } + var xhr = new XMLHttpRequest(), libs, tocopylibs = []; + //Getting known json list of libraries to copy to chrome + xhr.open("GET", '/ninja-internal/js/io/system/ninjalibrary.json', false); + xhr.send(); + //Checkng for correct reponse + if (xhr.readyState === 4) { + //Parsing json libraries + libs = JSON.parse(xhr.response); + // + if (e._event.ninjaChromeLibrary.length > 0) { + //Compare + } else { + //No library is present, must copy all + for (var i in libs.libraries) { + if (libs.libraries[i].singular) { + tocopylibs.push({name: String(libs.libraries[i].name+libs.libraries[i].version).toLowerCase(), path: libs.libraries[i].path, singular: true}); + } else { + tocopylibs.push({name: String(libs.libraries[i].name+libs.libraries[i].version).toLowerCase(), path: libs.libraries[i].path, singular: false}); + } + } + } + // + if (tocopylibs.length > 0) { + //Copy libraries + } else { + //No libraries to copy + } + } else { + //Error + } } }, //////////////////////////////////////////////////////////////////// diff --git a/js/io/system/ninjalibrary.json b/js/io/system/ninjalibrary.json new file mode 100644 index 00000000..affb72a0 --- /dev/null +++ b/js/io/system/ninjalibrary.json @@ -0,0 +1,6 @@ +{ + "libraries": [ + {"name": "Montage", "path": "/ninja-internal/node_modules/descriptor.json", "version": "0.6.0"}, + {"name": "RDGE", "path": "/ninja-internal/js/helper-classes/RDGE/rdge-compiled.js", "version": "0.6.0", "singular": "true"} + ] +} \ No newline at end of file -- cgit v1.2.3 From ad85ff92ba44fb3c8ccf24c2f1b9296804dfa8ca Mon Sep 17 00:00:00 2001 From: Jose Antonio Marquez Date: Mon, 6 Feb 2012 22:33:42 -0800 Subject: Single file library syncing Added the ability to store locally in chrome single file libraries used by Ninja. Working on adding multi-file libraries. --- js/io/system/chromeapi.js | 51 +++++++++++++++++++---- js/io/system/coreioapi.js | 34 ++------------- js/io/system/ninjalibrary.js | 93 +++++++++++++++++++++++++++++++++++++++++- js/io/system/ninjalibrary.json | 2 +- 4 files changed, 138 insertions(+), 42 deletions(-) (limited to 'js/io') diff --git a/js/io/system/chromeapi.js b/js/io/system/chromeapi.js index fb141687..6df41fd3 100644 --- a/js/io/system/chromeapi.js +++ b/js/io/system/chromeapi.js @@ -9,6 +9,9 @@ No rights, expressed or implied, whatsoever to this software are provided by Mot NOTES: The init function starts up the file system API, and a size must be set, no unlimited available as of now. + + Core API reference in NINJA: this.application.ninja.coreIoApi + //////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////// */ // @@ -61,24 +64,51 @@ exports.ChromeApi = Montage.create(Object.prototype, { }, //////////////////////////////////////////////////////////////////// // + fileNew: { + enumerable: true, + value: function(filePath, content, mime, callback) { + // + this.fileSystem.root.getFile(filePath, {create: true}, function(f) { + // + f.createWriter(function(writer) { + // + var b = new window.WebKitBlobBuilder; + b.append(content); + writer.write(b.getBlob(mime)); + // + if (callback) callback(true); + }, function (e) {if (callback) callback(false)}); + }, function (e) {if (callback) callback(false)}); + } + }, + //////////////////////////////////////////////////////////////////// + //Creating directory from path, callback optional directoryNew: { enumerable: true, - value: function() { + value: function(directoryPath, callback) { + //Checking for directory not to already exist + this.fileSystem.root.getDirectory(directoryPath, {}, function(dir) { + if (callback) callback(false); + return; //Directory already exists + }); + //Creating new directory + this.fileSystem.root.getDirectory(directoryPath, {create: true}, function(dir) { + if (callback) callback(true); + }, function (e) {if (callback) callback(false)}); } }, - //////////////////////////////////////////////////////////////////// // directoryDelete: { enumerable: true, value: function(directoryPath, callback) { // - this.fileSystem.getDirectory(directoryPath, {}, function(dirEntry) { + this.fileSystem.root.getDirectory(directoryPath, {}, function(dir) { // - dirEntry.removeRecursively(function() { - callback(true); + dir.removeRecursively(function() { + if (callback) callback(true); }); - }, function (e) {callback(false)}); + }, function (e) {if (callback) callback(false)}); } }, //////////////////////////////////////////////////////////////////// @@ -125,9 +155,12 @@ exports.ChromeApi = Montage.create(Object.prototype, { // var lib = []; // - - - + for(var i=0; contents[i]; i++) { + // + if (contents[i].isDirectory) { + lib.push(contents[i].name); + } + } //Dispatching action ready event var libraryEvent = document.createEvent("CustomEvent"); libraryEvent.initEvent('library', true, true); diff --git a/js/io/system/coreioapi.js b/js/io/system/coreioapi.js index b821936f..9836f33f 100755 --- a/js/io/system/coreioapi.js +++ b/js/io/system/coreioapi.js @@ -17,6 +17,7 @@ var Montage = require("montage/core/core").Montage, Popup = require("js/components/popup.reel").Popup, CloudPopup = require("js/io/ui/cloudpopup.reel").CloudPopup, ChromeApi = require("js/io/system/chromeapi").ChromeApi; + NinjaLibrary = require("js/io/system/ninjalibrary").NinjaLibrary; //////////////////////////////////////////////////////////////////////// //Exporting as Project I/O exports.CoreIoApi = Montage.create(Component, { @@ -37,6 +38,8 @@ exports.CoreIoApi = Montage.create(Component, { this.ioServiceDetected = false; } //////////////////////////////////////////////////////////// + //Instance of ninja library + this.ninjaLibrary = NinjaLibrary; //Getting reference of chrome file system API this.chromeFileSystem = ChromeApi; //Sending size in MBs for file system storage @@ -69,36 +72,7 @@ exports.CoreIoApi = Montage.create(Component, { //Removing events this.chromeFileSystem.removeEventListener('library', this, false); // - var xhr = new XMLHttpRequest(), libs, tocopylibs = []; - //Getting known json list of libraries to copy to chrome - xhr.open("GET", '/ninja-internal/js/io/system/ninjalibrary.json', false); - xhr.send(); - //Checkng for correct reponse - if (xhr.readyState === 4) { - //Parsing json libraries - libs = JSON.parse(xhr.response); - // - if (e._event.ninjaChromeLibrary.length > 0) { - //Compare - } else { - //No library is present, must copy all - for (var i in libs.libraries) { - if (libs.libraries[i].singular) { - tocopylibs.push({name: String(libs.libraries[i].name+libs.libraries[i].version).toLowerCase(), path: libs.libraries[i].path, singular: true}); - } else { - tocopylibs.push({name: String(libs.libraries[i].name+libs.libraries[i].version).toLowerCase(), path: libs.libraries[i].path, singular: false}); - } - } - } - // - if (tocopylibs.length > 0) { - //Copy libraries - } else { - //No libraries to copy - } - } else { - //Error - } + this.ninjaLibrary.synchronize(e._event.ninjaChromeLibrary, this.chromeFileSystem); } }, //////////////////////////////////////////////////////////////////// diff --git a/js/io/system/ninjalibrary.js b/js/io/system/ninjalibrary.js index 3f8585ed..e3d855f1 100644 --- a/js/io/system/ninjalibrary.js +++ b/js/io/system/ninjalibrary.js @@ -7,6 +7,9 @@ No rights, expressed or implied, whatsoever to this software are provided by Mot /* ///////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////// NOTES: + + Core API reference in NINJA: this.application.ninja.coreIoApi + //////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////// */ // @@ -16,12 +19,98 @@ var Montage = require("montage/core/core").Montage; exports.NinjaLibrary = Montage.create(Object.prototype, { //////////////////////////////////////////////////////////////////// // - init: { + _chromeApi: { + enumerable: false, + value: null + }, + //////////////////////////////////////////////////////////////////// + // + chromeApi: { + enumerable: false, + get: function() { + return this._chromeApi; + }, + set: function(value) { + this._chromeApi = value; + } + }, + //////////////////////////////////////////////////////////////////// + // + synchronize: { + enumerable: true, + value: function(chromeLibs, chrome) { + // + this.chromeApi = chrome; + // + var i, libs, xhr = new XMLHttpRequest(), tocopylibs = []; + //Getting known json list of libraries to copy to chrome + xhr.open("GET", '/ninja-internal/js/io/system/ninjalibrary.json', false); + xhr.send(); + //Checkng for correct reponse + if (xhr.readyState === 4) { + //Parsing json libraries + libs = JSON.parse(xhr.response); + // + if (chromeLibs.length > 0) { + //Compare (always deleting for testing) + for (i=0; chromeLibs[i]; i++) { + this.chromeApi.directoryDelete(chromeLibs[i]); + } + } else { + //No library is present, must copy all + for (var j in libs.libraries) { + //name: used to folder container contents + //path: url of descriptor json or single file to load (descriptor has list of files) + //singular: indicates the path is the file to be loaded into folder + if (libs.libraries[j].file) { + tocopylibs.push({name: String(libs.libraries[j].name+libs.libraries[j].version).toLowerCase(), path: libs.libraries[j].path, file: libs.libraries[j].file}); + } else { + tocopylibs.push({name: String(libs.libraries[j].name+libs.libraries[j].version).toLowerCase(), path: libs.libraries[j].path}); + } + } + } + // + if (tocopylibs.length > 0) { + for (i=0; tocopylibs[i]; i++) { + //Checking for library to be single file + if (tocopylibs[i].file) { + //Creating root folder + this.chromeApi.directoryNew('/'+tocopylibs[i].name); + //Getting file contents + xhr = new XMLHttpRequest(); + xhr.open("GET", tocopylibs[i].path, false); + xhr.send(); + //Checking for status + if (xhr.readyState === 4) { //TODO: add check for mime type + //Creating new file from loaded content + this.chromeApi.fileNew('/'+tocopylibs[i].name+'/'+tocopylibs[i].file, xhr.response, 'text/plain'); + //this.chromeApi.fileNew('/'+tocopylibs[i].name+'/'+tocopylibs[i].file, xhr.response, 'text/plain', function (v){console.log(v)}); + } else { + //Error + } + } else { + // + } + } + } else { + //No libraries to copy + } + } else { + //Error + } + } + }/* +, + //////////////////////////////////////////////////////////////////// + // + createFolder: { enumerable: true, - value: function() { + value: function(name) { // + this.chromeApi.directoryNew(name); } } +*/ //////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////// }); diff --git a/js/io/system/ninjalibrary.json b/js/io/system/ninjalibrary.json index affb72a0..87dff7f6 100644 --- a/js/io/system/ninjalibrary.json +++ b/js/io/system/ninjalibrary.json @@ -1,6 +1,6 @@ { "libraries": [ {"name": "Montage", "path": "/ninja-internal/node_modules/descriptor.json", "version": "0.6.0"}, - {"name": "RDGE", "path": "/ninja-internal/js/helper-classes/RDGE/rdge-compiled.js", "version": "0.6.0", "singular": "true"} + {"name": "RDGE", "path": "/ninja-internal/js/helper-classes/RDGE/rdge-compiled.js", "version": "0.6.0", "file": "rdge-compiled.js"} ] } \ No newline at end of file -- cgit v1.2.3 From c4c5a8b49bb26d6344edceba73834754bb9930cf Mon Sep 17 00:00:00 2001 From: Jose Antonio Marquez Date: Tue, 7 Feb 2012 11:14:57 -0800 Subject: Adding ability to copy an entire library for Ninja Added the functionality to copy an entire directory/library from a JSON descriptor file into the app sandbox. Need to add logic to dispatch a 'synchronized' event for Ninja to know everything is up to date. --- js/io/system/ninjalibrary.js | 88 +++++++++++++++++++++++++++++++++++++------- 1 file changed, 75 insertions(+), 13 deletions(-) (limited to 'js/io') diff --git a/js/io/system/ninjalibrary.js b/js/io/system/ninjalibrary.js index e3d855f1..09cf7407 100644 --- a/js/io/system/ninjalibrary.js +++ b/js/io/system/ninjalibrary.js @@ -42,7 +42,7 @@ exports.NinjaLibrary = Montage.create(Object.prototype, { // this.chromeApi = chrome; // - var i, libs, xhr = new XMLHttpRequest(), tocopylibs = []; + var i, l, libs, libjson, xhr = new XMLHttpRequest(), tocopylibs = []; //Getting known json list of libraries to copy to chrome xhr.open("GET", '/ninja-internal/js/io/system/ninjalibrary.json', false); xhr.send(); @@ -52,9 +52,9 @@ exports.NinjaLibrary = Montage.create(Object.prototype, { libs = JSON.parse(xhr.response); // if (chromeLibs.length > 0) { - //Compare (always deleting for testing) - for (i=0; chromeLibs[i]; i++) { - this.chromeApi.directoryDelete(chromeLibs[i]); + //TODO: Remove + for (i=0; chromeLibs[i]; i++) { + this.chromeApi.directoryDelete(chromeLibs[i]); } } else { //No library is present, must copy all @@ -84,12 +84,58 @@ exports.NinjaLibrary = Montage.create(Object.prototype, { if (xhr.readyState === 4) { //TODO: add check for mime type //Creating new file from loaded content this.chromeApi.fileNew('/'+tocopylibs[i].name+'/'+tocopylibs[i].file, xhr.response, 'text/plain'); - //this.chromeApi.fileNew('/'+tocopylibs[i].name+'/'+tocopylibs[i].file, xhr.response, 'text/plain', function (v){console.log(v)}); } else { - //Error + //Error creating single file library } } else { - // + //Creating root folder + this.chromeApi.directoryNew('/'+tocopylibs[i].name); + //Getting file contents + xhr = new XMLHttpRequest(); + xhr.open("GET", tocopylibs[i].path, false); + xhr.send(); + //Checking for status + if (xhr.readyState === 4) { + // + libjson = JSON.parse(xhr.response); + // + for (l=0; libjson.directories[l]; l++) { + libjson.dirsToCreate = libjson.directories.length; + libjson.dirsCreated = 0; + libjson.filesToCreate = libjson.files.length; + libjson.filesCreated = 0; + libjson.api = this.chromeApi; + libjson.local = tocopylibs[i].name; + this.createDirectory(tocopylibs[i].name, libjson.directories[l], function (status) { + //Checking for success on directories created + if (status) { + this.dirsCreated++; + } + //All directories created + if (this.dirsCreated === this.dirsToCreate) { + var xhr, i; + for (i=0; this.files[i]; i++) { + xhr = new XMLHttpRequest(); + xhr.open("GET", this.root+this.files[i], false); + xhr.send(); + //Checking for status + if (xhr.readyState === 4) { + this.api.fileNew(this.local+'/'+this.files[i], xhr.response, 'text/plain', function (status) { + if (status) { + this.filesCreated++; + } + if (this.filesCreated === this.filesToCreate) { + //TODO: Add logic for task completed + } + }.bind(this)); + } + } + } + }.bind(libjson)); + } + } else { + //Error + } } } } else { @@ -99,18 +145,34 @@ exports.NinjaLibrary = Montage.create(Object.prototype, { //Error } } - }/* -, + }, //////////////////////////////////////////////////////////////////// // - createFolder: { + createDirectory: { enumerable: true, - value: function(name) { + value: function(root, folder, callback) { // - this.chromeApi.directoryNew(name); + if (folder.name) { + if (root) { + dir = root+'/'+folder.name; + } else { + dir = folder.name; + } + // + this.chromeApi.directoryNew(dir, function (status) {if (callback)callback(status)}); + } + // + if (folder.children) { + for (var j in folder.children) { + if (root) { + this.createDirectory(root+'/'+folder.name, folder.children[j]); + } else { + this.createDirectory(folder.name, folder.children[j]); + } + } + } } } -*/ //////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////// }); -- cgit v1.2.3 From 111509d5cbbd54b11afbc49f7c78d0c0548bb617 Mon Sep 17 00:00:00 2001 From: Jose Antonio Marquez Date: Tue, 7 Feb 2012 12:06:21 -0800 Subject: Adding mime-type detection for new file --- js/io/system/chromeapi.js | 288 +++++++------------------------------------ js/io/system/ninjalibrary.js | 4 +- 2 files changed, 46 insertions(+), 246 deletions(-) (limited to 'js/io') diff --git a/js/io/system/chromeapi.js b/js/io/system/chromeapi.js index 6df41fd3..2fc8769c 100644 --- a/js/io/system/chromeapi.js +++ b/js/io/system/chromeapi.js @@ -66,13 +66,54 @@ exports.ChromeApi = Montage.create(Object.prototype, { // fileNew: { enumerable: true, - value: function(filePath, content, mime, callback) { + value: function(filePath, content, callback) { // this.fileSystem.root.getFile(filePath, {create: true}, function(f) { // f.createWriter(function(writer) { // - var b = new window.WebKitBlobBuilder; + var b, mime, type = filePath.split('.'); + type = type[type.length-1]; + switch (type) { + case 'bmp': + mime = 'image/bmp'; + break; + case 'gif': + mime = 'image/gif'; + break; + case 'jpeg': + mime = 'image/jpeg'; + break; + case 'jpg': + mime = 'image/jpeg'; + break; + case 'png': + mime = 'image/png'; + break; + case 'rtf': + mime = 'application/rtf'; + break; + case 'tif': + mime = 'image/tiff'; + break; + case 'tiff': + mime = 'image/tiff'; + break; + case 'pdf': + mime = 'application/pdf'; + break; + case 'zip': + mime = 'application/zip'; + break; + case 'svg': + mime = 'image/svg+xml'; + break; + default: + mime = 'text/'+type; + break; + } + // + b = new window.WebKitBlobBuilder; b.append(content); writer.write(b.getBlob(mime)); // @@ -175,245 +216,4 @@ exports.ChromeApi = Montage.create(Object.prototype, { //////////////////////////////////////////////////////////////////// }); //////////////////////////////////////////////////////////////////////// -//////////////////////////////////////////////////////////////////////// - - - -//window.webkitRequestFileSystem(window.PERSISTENT, 10*1024*1024 /*10MB*/, function (fs) { - - - - /* -for (var i=1; i<50; i++) { - fs.root.getDirectory('montage0.0.0.'+i, {}, function(dirEntry) { - // - dirEntry.removeRecursively(function() { - console.log('Directory removed.'); - }); - }); - } -*/ - - - - - - - // - /* -var xhr = new XMLHttpRequest(), dir, mjs; - // - xhr.open("GET", '/ninja-internal/node_modules/descriptor.json', false); - xhr.send(); - // - if (xhr.readyState === 4) { - // - mjs = JSON.parse(xhr.response); - // - if (mjs.version) { - //Checking for version to exist - fs.root.getDirectory('montage'+mjs.version, {}, function(dirEntry) { - //Already copied, nothing - console.log('montage'+mjs.version+' has already been created'); - }, function (e) { - //Not present, should be copied - createFolder(false, {name: 'montage'+mjs.version}); - // - for (var i in mjs.directories) { - createFolder('montage'+mjs.version, mjs.directories[i]); - } - // - - - for (var j in mjs.files) { - - var frqst = new XMLHttpRequest(); - frqst.open("GET", '/ninja-internal/node_modules/montage/'+mjs.files[j], false); - frqst.send(); - - if (frqst.readyState === 4) { - createFile('montage'+mjs.version+'/'+mjs.files[j], frqst.response); - } - } - - // - console.log('montage'+mjs.version+' was created'); - }, folderError); - } - - } - // - function createFile (path, content) { - // - fs.root.getFile(path, {create: true}, function(fileEntry) { - // - fileEntry.createWriter(function(fileWriter) { - // - //console.log(path); - var bb = new window.WebKitBlobBuilder; - bb.append(content); - fileWriter.write(bb.getBlob('text/plain')); - }, fileError); - - }, fileError); - } - // - function createFolder(root, folder) { - if (folder.name) { - if (root) { - dir = root+'/'+folder.name; - } else { - dir = folder.name; - } - // - //console.log(dir); - // - fs.root.getDirectory(dir, {create: true}, function(dirEntry) { - // - }, folderError); - } - // - if (folder.children) { - for (var i in folder.children) { - if (root) { - createFolder(root+'/'+folder.name, folder.children[i]); - } else { - createFolder(folder.name, folder.children[i]); - } - } - } - } - // - function folderError (e) { - console.log(e); - } - function fileError (e) { - console.log(e); - } - - - setTimeout( function () { - for (var m in mjs.files) { - - fs.root.getFile('montage'+mjs.version+'/'+mjs.files[m], {}, function(fileEntry) { - - console.log(mjs.files[m]); - - fileEntry.file(function(file) { - - var reader = new FileReader(); - reader.onloadend = function(e) { - //console.log(e.target.file.name); - var test = this.createFile({uri: '/Users/kgq387/Desktop/Ninja Cloud/Disk/'+e.target.file.name, contents: e.target.result}); - }.bind(this); - - reader.file = file; - reader.readAsText(file); - - }.bind(this)); - - }.bind(this)); - - }}.bind(this), 5000); -*/ - - - - - - //}.bind(this)); - - - - - - - - //////////////////////////////////////////////////////////// - //////////////////////////////////////////////////////////// - //TODO: Remove, this is only for testing - - - /* -window.webkitRequestFileSystem(window.PERSISTENT, 10*1024*1024 , function (fs) { - - - var start = new Date().getTime(); - - for (var i=0; i<250; i++) { - - fs.root.getFile('test'+i+'.txt', {create: true}, function(fileEntry) { - - fileEntry.createWriter(function(fileWriter) { - - - var xhr = new XMLHttpRequest(); - // - xhr.open("GET", '/ninja-internal/js/io/templates/descriptor.json', false); - xhr.send(); - // - if (xhr.readyState === 4) { - var bb = new window.WebKitBlobBuilder; - bb.append(xhr.response); - fileWriter.write(bb.getBlob('text/plain')); - } - - }); - - }); - - } - - var end = new Date().getTime(); - var time = end - start; - console.log('Create execution time: ' + time); - - start = new Date().getTime(); - - for (var j=0; j<250; j++) { - - fs.root.getFile('test'+j+'.txt', {create: true}, function(fileEntry) { - - - - fileEntry.file(function(file) { - - var reader = new FileReader(); - reader.onloadend = function(e) { - //console.log(this, e.target); - var test = this.createFile({uri: '/Users/kgq387/Desktop/Ninja Cloud/Disk/'+e.target.file.name, contents: e.target.result}); - console.log(e.target.file.name); - - }.bind(this); - - reader.file = file; - reader.readAsText(file); - - }.bind(this)); - - }.bind(this)); - - } - - - end = new Date().getTime(); - time = end - start; - console.log('Read execution time: ' + time); - - for (var k=0; k<250; k++) { - - fs.root.getFile('test'+k+'.txt', {create: true}, function(fileEntry) { - - fileEntry.remove(function(fileWriter) { - - - }); - - }); - - } - - - - }.bind(this)); -*/ \ No newline at end of file +//////////////////////////////////////////////////////////////////////// \ No newline at end of file diff --git a/js/io/system/ninjalibrary.js b/js/io/system/ninjalibrary.js index 09cf7407..658ce589 100644 --- a/js/io/system/ninjalibrary.js +++ b/js/io/system/ninjalibrary.js @@ -83,7 +83,7 @@ exports.NinjaLibrary = Montage.create(Object.prototype, { //Checking for status if (xhr.readyState === 4) { //TODO: add check for mime type //Creating new file from loaded content - this.chromeApi.fileNew('/'+tocopylibs[i].name+'/'+tocopylibs[i].file, xhr.response, 'text/plain'); + this.chromeApi.fileNew('/'+tocopylibs[i].name+'/'+tocopylibs[i].file, xhr.response); } else { //Error creating single file library } @@ -120,7 +120,7 @@ exports.NinjaLibrary = Montage.create(Object.prototype, { xhr.send(); //Checking for status if (xhr.readyState === 4) { - this.api.fileNew(this.local+'/'+this.files[i], xhr.response, 'text/plain', function (status) { + this.api.fileNew(this.local+'/'+this.files[i], xhr.response, function (status) { if (status) { this.filesCreated++; } -- cgit v1.2.3 From 516e04ab45ca1dbad9c2847a9a213919d6e812f5 Mon Sep 17 00:00:00 2001 From: Jose Antonio Marquez Date: Tue, 7 Feb 2012 14:50:48 -0800 Subject: Adding library synced events Added an event that will be dispatched when Ninja loads and the local chrome Ninja library is fully synced with all required libs. --- js/io/system/coreioapi.js | 20 +++++++++++-- js/io/system/ninjalibrary.js | 69 +++++++++++++++++++++++++++++++++++++++----- 2 files changed, 78 insertions(+), 11 deletions(-) (limited to 'js/io') diff --git a/js/io/system/coreioapi.js b/js/io/system/coreioapi.js index 9836f33f..005eabf2 100755 --- a/js/io/system/coreioapi.js +++ b/js/io/system/coreioapi.js @@ -58,9 +58,9 @@ exports.CoreIoApi = Montage.create(Component, { handleReady: { enumerable: false, value: function (e) { - // + //Removing events this.chromeFileSystem.removeEventListener('ready', this, false); - // + //Listening for library to be copied event (builds list) this.chromeFileSystem.addEventListener('library', this, false); } }, @@ -71,10 +71,24 @@ exports.CoreIoApi = Montage.create(Component, { value: function (e) { //Removing events this.chromeFileSystem.removeEventListener('library', this, false); - // + //Listening for synced library event + this.ninjaLibrary.addEventListener('sync', this, false); + //Sending library to be synced to chrome this.ninjaLibrary.synchronize(e._event.ninjaChromeLibrary, this.chromeFileSystem); + } }, + //////////////////////////////////////////////////////////////////// + // + handleSync: { + enumerable: false, + value: function (e) { + //Removing events + console.log('Ninja Local Library: Ready'); + this.ninjaLibrary.removeEventListener('sync', this, false); + //TODO: Add sync loading screen logic + } + }, //////////////////////////////////////////////////////////////////// // _chromeNinjaLibrary: { diff --git a/js/io/system/ninjalibrary.js b/js/io/system/ninjalibrary.js index 658ce589..fa2e7d1f 100644 --- a/js/io/system/ninjalibrary.js +++ b/js/io/system/ninjalibrary.js @@ -33,6 +33,18 @@ exports.NinjaLibrary = Montage.create(Object.prototype, { set: function(value) { this._chromeApi = value; } + }, + //////////////////////////////////////////////////////////////////// + // + _libsToSync: { + enumerable: false, + value: 0 + }, + //////////////////////////////////////////////////////////////////// + // + _syncedLibs: { + enumerable: false, + value: 0 }, //////////////////////////////////////////////////////////////////// // @@ -42,7 +54,7 @@ exports.NinjaLibrary = Montage.create(Object.prototype, { // this.chromeApi = chrome; // - var i, l, libs, libjson, xhr = new XMLHttpRequest(), tocopylibs = []; + var i, l, libs, libjson, xhr = new XMLHttpRequest(), tocopylibs = [], copied; //Getting known json list of libraries to copy to chrome xhr.open("GET", '/ninja-internal/js/io/system/ninjalibrary.json', false); xhr.send(); @@ -52,10 +64,27 @@ exports.NinjaLibrary = Montage.create(Object.prototype, { libs = JSON.parse(xhr.response); // if (chromeLibs.length > 0) { - //TODO: Remove + // for (i=0; chromeLibs[i]; i++) { - this.chromeApi.directoryDelete(chromeLibs[i]); + copied = false; + for (var j in libs.libraries) { + if (String(libs.libraries[j].name+libs.libraries[j].version).toLowerCase() === chromeLibs[i]) { + copied = true; + } + } + // + if (!copied) { + if (libs.libraries[j].file) { + tocopylibs.push({name: String(libs.libraries[j].name+libs.libraries[j].version).toLowerCase(), path: libs.libraries[j].path, file: libs.libraries[j].file}); + } else { + tocopylibs.push({name: String(libs.libraries[j].name+libs.libraries[j].version).toLowerCase(), path: libs.libraries[j].path}); + } + } else { + //TODO: Remove, currently manually removing copied libraries + this.chromeApi.directoryDelete(chromeLibs[i]); + } } + } else { //No library is present, must copy all for (var j in libs.libraries) { @@ -70,6 +99,8 @@ exports.NinjaLibrary = Montage.create(Object.prototype, { } } // + this._libsToSync = tocopylibs.length; + // if (tocopylibs.length > 0) { for (i=0; tocopylibs[i]; i++) { //Checking for library to be single file @@ -83,7 +114,7 @@ exports.NinjaLibrary = Montage.create(Object.prototype, { //Checking for status if (xhr.readyState === 4) { //TODO: add check for mime type //Creating new file from loaded content - this.chromeApi.fileNew('/'+tocopylibs[i].name+'/'+tocopylibs[i].file, xhr.response); + this.chromeApi.fileNew('/'+tocopylibs[i].name+'/'+tocopylibs[i].file, xhr.response, function (status) {if(status) this.libraryCopied()}.bind(this)); } else { //Error creating single file library } @@ -104,8 +135,8 @@ exports.NinjaLibrary = Montage.create(Object.prototype, { libjson.dirsCreated = 0; libjson.filesToCreate = libjson.files.length; libjson.filesCreated = 0; - libjson.api = this.chromeApi; libjson.local = tocopylibs[i].name; + libjson.main = this; this.createDirectory(tocopylibs[i].name, libjson.directories[l], function (status) { //Checking for success on directories created if (status) { @@ -120,12 +151,12 @@ exports.NinjaLibrary = Montage.create(Object.prototype, { xhr.send(); //Checking for status if (xhr.readyState === 4) { - this.api.fileNew(this.local+'/'+this.files[i], xhr.response, function (status) { + this.main.chromeApi.fileNew(this.local+'/'+this.files[i], xhr.response, function (status) { if (status) { this.filesCreated++; } if (this.filesCreated === this.filesToCreate) { - //TODO: Add logic for task completed + this.main.libraryCopied(); } }.bind(this)); } @@ -139,7 +170,8 @@ exports.NinjaLibrary = Montage.create(Object.prototype, { } } } else { - //No libraries to copy + //Dispatching ready event since nothing to copy + this._dispatchEvent(); } } else { //Error @@ -172,6 +204,27 @@ exports.NinjaLibrary = Montage.create(Object.prototype, { } } } + }, + //////////////////////////////////////////////////////////////////// + // + libraryCopied: { + enumerable: true, + value: function() { + this._syncedLibs++; + if (this._syncedLibs === this._libsToSync) { + this._dispatchEvent(); + } + } + }, + //////////////////////////////////////////////////////////////////// + // + _dispatchEvent: { + enumerable: true, + value: function () { + var syncEvent = document.createEvent("CustomEvent"); + syncEvent.initEvent('sync', true, true); + this.dispatchEvent(syncEvent); + } } //////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////// -- cgit v1.2.3 From af58afcffff5ac556d16f050a325ac0406897fcd Mon Sep 17 00:00:00 2001 From: Jose Antonio Marquez Date: Tue, 7 Feb 2012 17:03:44 -0800 Subject: Copy local library to cloud Adding functionality to copy a local library to the cloud. Currently creating directory structure. Need to add ability to copy files and ensure proper mime-type is set. --- js/io/system/chromeapi.js | 43 +++++++++++++++++++++++-- js/io/system/coreioapi.js | 13 +++++++- js/io/system/ninjalibrary.js | 77 ++++++++++++++++++++++++++++++++++++++++++-- 3 files changed, 127 insertions(+), 6 deletions(-) (limited to 'js/io') diff --git a/js/io/system/chromeapi.js b/js/io/system/chromeapi.js index 2fc8769c..fc93b22a 100644 --- a/js/io/system/chromeapi.js +++ b/js/io/system/chromeapi.js @@ -7,11 +7,10 @@ No rights, expressed or implied, whatsoever to this software are provided by Mot /* ///////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////// NOTES: + The init function starts up the file system API, and a size must be set, no unlimited available as of now. - Core API reference in NINJA: this.application.ninja.coreIoApi - //////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////// */ // @@ -123,6 +122,46 @@ exports.ChromeApi = Montage.create(Object.prototype, { } }, //////////////////////////////////////////////////////////////////// + // + fileDelete: { + enumerable: true, + value: function(filePath, callback) { + this.fileSystem.root.getFile(filePath, {create: false}, function(file) { + file.remove(function() { + if (callback) callback(true); + }); + }, function (e) {if (callback) callback(false)}); + } + }, + //////////////////////////////////////////////////////////////////// + // + fileContent: { + enumerable: true, + value: function() { + } + }, + //////////////////////////////////////////////////////////////////// + // + fileCopy: { + enumerable: true, + value: function() { + } + }, + //////////////////////////////////////////////////////////////////// + // + fileRename: { + enumerable: true, + value: function() { + } + }, + //////////////////////////////////////////////////////////////////// + // + fileMove: { + enumerable: true, + value: function() { + } + }, + //////////////////////////////////////////////////////////////////// //Creating directory from path, callback optional directoryNew: { enumerable: true, diff --git a/js/io/system/coreioapi.js b/js/io/system/coreioapi.js index 005eabf2..7edb469b 100755 --- a/js/io/system/coreioapi.js +++ b/js/io/system/coreioapi.js @@ -83,10 +83,21 @@ exports.CoreIoApi = Montage.create(Component, { handleSync: { enumerable: false, value: function (e) { - //Removing events console.log('Ninja Local Library: Ready'); + //Removing events this.ninjaLibrary.removeEventListener('sync', this, false); + this.ninjaLibrary.coreApi = this; //TODO: Add sync loading screen logic + + + + + //TODO: Remove test + this.ninjaLibrary.copyLibToCloud('Users/kgq387/Desktop/Ninja Cloud/Disk', 'montage0.6.0'); + + + + } }, //////////////////////////////////////////////////////////////////// diff --git a/js/io/system/ninjalibrary.js b/js/io/system/ninjalibrary.js index fa2e7d1f..0ab19401 100644 --- a/js/io/system/ninjalibrary.js +++ b/js/io/system/ninjalibrary.js @@ -8,8 +8,6 @@ No rights, expressed or implied, whatsoever to this software are provided by Mot //////////////////////////////////////////////////////////////////////// NOTES: - Core API reference in NINJA: this.application.ninja.coreIoApi - //////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////// */ // @@ -36,6 +34,23 @@ exports.NinjaLibrary = Montage.create(Object.prototype, { }, //////////////////////////////////////////////////////////////////// // + _coreApi: { + enumerable: false, + value: null + }, + //////////////////////////////////////////////////////////////////// + // + coreApi: { + enumerable: false, + get: function() { + return this._coreApi; + }, + set: function(value) { + this._coreApi = value; + } + }, + //////////////////////////////////////////////////////////////////// + // _libsToSync: { enumerable: false, value: 0 @@ -45,6 +60,62 @@ exports.NinjaLibrary = Montage.create(Object.prototype, { _syncedLibs: { enumerable: false, value: 0 + }, + //////////////////////////////////////////////////////////////////// + // + copyLibToCloud: { + enumerable: false, + value: function (path, libName) { + // + if(this.coreApi.directoryExists({uri: '/'+path+'/'+libName+'/'}).status === 404) { + this.chromeApi.directoryContents(this.chromeApi.fileSystem.root, function (contents) { + for (var i in contents) { + if (libName === contents[i].name) { + //Getting contents of library to be copied + this.chromeApi.directoryContents(contents[i], function (lib) { + //Creating directory structure from subfolders + this.copyDirectoryToCloud(path, contents[i], function (status) {console.log(status)}); + }.bind(this)); + break; + } + } + }.bind(this)); + } else { + //Error + } + } + }, + //////////////////////////////////////////////////////////////////// + // + copyDirectoryToCloud: { + enumerable: true, + value: function(root, folder, callback) { + if (folder.name) { + var dir; + if (root) { + dir = root+'/'+folder.name; + } else { + dir = folder.name; + } + // + if (!this.coreApi.createDirectory({uri: '/'+dir+'/'})) { + //Error occured while creating folders + return; + } + } + // + if (folder.isDirectory) { + this.chromeApi.directoryContents(folder, function (contents) { + for (var i in contents) { + if (contents[i].isDirectory) { + this.copyDirectoryToCloud(dir, contents[i]); + } else if (contents[i].isFile){ + //File to copy + } + } + }.bind(this)); + } + } }, //////////////////////////////////////////////////////////////////// // @@ -81,7 +152,7 @@ exports.NinjaLibrary = Montage.create(Object.prototype, { } } else { //TODO: Remove, currently manually removing copied libraries - this.chromeApi.directoryDelete(chromeLibs[i]); + //this.chromeApi.directoryDelete(chromeLibs[i]); } } -- cgit v1.2.3 From 687cfbbae1df2392267e9602f955f6eadd5b339d Mon Sep 17 00:00:00 2001 From: Jose Antonio Marquez Date: Tue, 7 Feb 2012 23:13:15 -0800 Subject: Mime type fixes Trying to fix mime type issues in FileSystem, Chrome does not support reponseType 'blob', so looking at alternatives. --- js/io/system/chromeapi.js | 21 ++++++++++++++++----- js/io/system/ninjalibrary.js | 14 ++++++++++---- 2 files changed, 26 insertions(+), 9 deletions(-) (limited to 'js/io') diff --git a/js/io/system/chromeapi.js b/js/io/system/chromeapi.js index fc93b22a..c19a7d3b 100644 --- a/js/io/system/chromeapi.js +++ b/js/io/system/chromeapi.js @@ -71,7 +71,7 @@ exports.ChromeApi = Montage.create(Object.prototype, { // f.createWriter(function(writer) { // - var b, mime, type = filePath.split('.'); + var mime, blob = new window.WebKitBlobBuilder, type = filePath.split('.'); type = type[type.length-1]; switch (type) { case 'bmp': @@ -112,9 +112,8 @@ exports.ChromeApi = Montage.create(Object.prototype, { break; } // - b = new window.WebKitBlobBuilder; - b.append(content); - writer.write(b.getBlob(mime)); + blob.append(content); + writer.write(blob.getBlob(mime)); // if (callback) callback(true); }, function (e) {if (callback) callback(false)}); @@ -137,7 +136,19 @@ exports.ChromeApi = Montage.create(Object.prototype, { // fileContent: { enumerable: true, - value: function() { + value: function(filePath, callback) { + // + this.fileSystem.root.getFile(filePath, {}, function(f) { + f.file(function(file) { + var reader = new FileReader(); + reader.onloadend = function(e) { + if (callback) { + callback({content: this.result, data: file, file: f, url: f.toURL()}); + } + }; + reader.readAsText(file); + }, function (e) {if (callback) callback(false)}); + }, function (e) {if (callback) callback(false)}); } }, //////////////////////////////////////////////////////////////////// diff --git a/js/io/system/ninjalibrary.js b/js/io/system/ninjalibrary.js index 0ab19401..3914ec29 100644 --- a/js/io/system/ninjalibrary.js +++ b/js/io/system/ninjalibrary.js @@ -74,7 +74,7 @@ exports.NinjaLibrary = Montage.create(Object.prototype, { //Getting contents of library to be copied this.chromeApi.directoryContents(contents[i], function (lib) { //Creating directory structure from subfolders - this.copyDirectoryToCloud(path, contents[i], function (status) {console.log(status)}); + this.copyDirectoryToCloud(path, contents[i], '/'+path, function (status) {console.log(status)}); }.bind(this)); break; } @@ -89,7 +89,8 @@ exports.NinjaLibrary = Montage.create(Object.prototype, { // copyDirectoryToCloud: { enumerable: true, - value: function(root, folder, callback) { + value: function(root, folder, fileRoot, callback) { + // if (folder.name) { var dir; if (root) { @@ -108,9 +109,14 @@ exports.NinjaLibrary = Montage.create(Object.prototype, { this.chromeApi.directoryContents(folder, function (contents) { for (var i in contents) { if (contents[i].isDirectory) { - this.copyDirectoryToCloud(dir, contents[i]); + this.copyDirectoryToCloud(dir, contents[i], fileRoot); } else if (contents[i].isFile){ //File to copy + this.chromeApi.fileContent(contents[i].fullPath, function (result) { + // + this.coreApi.createFile({uri: fileRoot+result.file.fullPath, contents: result.content, contentType: result.data.type}); + //this.coreApi.createFile({uri: fileRoot+result.file.fullPath, contents: result.content}); + }.bind(this)); } } }.bind(this)); @@ -185,7 +191,7 @@ exports.NinjaLibrary = Montage.create(Object.prototype, { //Checking for status if (xhr.readyState === 4) { //TODO: add check for mime type //Creating new file from loaded content - this.chromeApi.fileNew('/'+tocopylibs[i].name+'/'+tocopylibs[i].file, xhr.response, function (status) {if(status) this.libraryCopied()}.bind(this)); + //this.chromeApi.fileNew('/'+tocopylibs[i].name+'/'+tocopylibs[i].file, xhr.response, function (status) {if(status) this.libraryCopied()}.bind(this)); } else { //Error creating single file library } -- cgit v1.2.3 From 4bfac53c9a77a3af35d029757eece53f4b7212ed Mon Sep 17 00:00:00 2001 From: Jose Antonio Marquez Date: Wed, 8 Feb 2012 13:11:48 -0800 Subject: Fixed data type issue on copying library files Fixed the methods to allow for ArrayBuffer data to be sent, fixes saving files that are not plain text. --- js/io/system/chromeapi.js | 2 +- js/io/system/coreioapi.js | 5 +++-- js/io/system/ninjalibrary.js | 18 +++++++++++++++--- 3 files changed, 19 insertions(+), 6 deletions(-) (limited to 'js/io') diff --git a/js/io/system/chromeapi.js b/js/io/system/chromeapi.js index c19a7d3b..eee7409d 100644 --- a/js/io/system/chromeapi.js +++ b/js/io/system/chromeapi.js @@ -146,7 +146,7 @@ exports.ChromeApi = Montage.create(Object.prototype, { callback({content: this.result, data: file, file: f, url: f.toURL()}); } }; - reader.readAsText(file); + reader.readAsArrayBuffer(file); }, function (e) {if (callback) callback(false)}); }, function (e) {if (callback) callback(false)}); } diff --git a/js/io/system/coreioapi.js b/js/io/system/coreioapi.js index 7edb469b..e2c2e4dd 100755 --- a/js/io/system/coreioapi.js +++ b/js/io/system/coreioapi.js @@ -402,15 +402,16 @@ exports.CoreIoApi = Montage.create(Component, { xhr = new XMLHttpRequest(); // xhr.open("POST", serviceURL, false); + xhr.responseType = "arraybuffer"; if(file.contentType && file.contentType.length) xhr.setRequestHeader("Content-Type", file.contentType); else xhr.setRequestHeader("Content-Type", "text/plain"); - if(file.contents && file.contents.length) + if (file.contents) xhr.send(file.contents); else - xhr.send(); + xhr.send(); if (xhr.readyState === 4) { retValue.status = xhr.status; diff --git a/js/io/system/ninjalibrary.js b/js/io/system/ninjalibrary.js index 3914ec29..7b524189 100644 --- a/js/io/system/ninjalibrary.js +++ b/js/io/system/ninjalibrary.js @@ -114,8 +114,18 @@ exports.NinjaLibrary = Montage.create(Object.prototype, { //File to copy this.chromeApi.fileContent(contents[i].fullPath, function (result) { // - this.coreApi.createFile({uri: fileRoot+result.file.fullPath, contents: result.content, contentType: result.data.type}); - //this.coreApi.createFile({uri: fileRoot+result.file.fullPath, contents: result.content}); + + /* +var ui8a = new Uint8Array(result.content); + console.log(ui8a); + + var blob = new window.WebKitBlobBuilder; + blob.append(result.content); +*/ + //console.log(blob.getBlob(result.data.type)); + //this.coreApi.createFile({uri: fileRoot+result.file.fullPath, contents: result.content, contentType: result.data.type}); + //this.coreApi.createFile({uri: fileRoot+result.file.fullPath, contents: blob.getBlob(result.data.type), contentType: result.data.type}); + this.coreApi.createFile({uri: fileRoot+result.file.fullPath, contents: result.content}); }.bind(this)); } } @@ -187,11 +197,12 @@ exports.NinjaLibrary = Montage.create(Object.prototype, { //Getting file contents xhr = new XMLHttpRequest(); xhr.open("GET", tocopylibs[i].path, false); + xhr.responseType = "arraybuffer"; xhr.send(); //Checking for status if (xhr.readyState === 4) { //TODO: add check for mime type //Creating new file from loaded content - //this.chromeApi.fileNew('/'+tocopylibs[i].name+'/'+tocopylibs[i].file, xhr.response, function (status) {if(status) this.libraryCopied()}.bind(this)); + this.chromeApi.fileNew('/'+tocopylibs[i].name+'/'+tocopylibs[i].file, xhr.response, function (status) {if(status) this.libraryCopied()}.bind(this)); } else { //Error creating single file library } @@ -225,6 +236,7 @@ exports.NinjaLibrary = Montage.create(Object.prototype, { for (i=0; this.files[i]; i++) { xhr = new XMLHttpRequest(); xhr.open("GET", this.root+this.files[i], false); + xhr.responseType = "arraybuffer"; xhr.send(); //Checking for status if (xhr.readyState === 4) { -- cgit v1.2.3 From 2133bd1e74864b4b69d824ba7977fa07034af962 Mon Sep 17 00:00:00 2001 From: Jose Antonio Marquez Date: Wed, 8 Feb 2012 14:38:20 -0800 Subject: Setting up packaged app --- js/io/system/ninjalibrary.js | 12 +----------- 1 file changed, 1 insertion(+), 11 deletions(-) (limited to 'js/io') diff --git a/js/io/system/ninjalibrary.js b/js/io/system/ninjalibrary.js index 7b524189..c85de3b0 100644 --- a/js/io/system/ninjalibrary.js +++ b/js/io/system/ninjalibrary.js @@ -114,16 +114,6 @@ exports.NinjaLibrary = Montage.create(Object.prototype, { //File to copy this.chromeApi.fileContent(contents[i].fullPath, function (result) { // - - /* -var ui8a = new Uint8Array(result.content); - console.log(ui8a); - - var blob = new window.WebKitBlobBuilder; - blob.append(result.content); -*/ - //console.log(blob.getBlob(result.data.type)); - //this.coreApi.createFile({uri: fileRoot+result.file.fullPath, contents: result.content, contentType: result.data.type}); //this.coreApi.createFile({uri: fileRoot+result.file.fullPath, contents: blob.getBlob(result.data.type), contentType: result.data.type}); this.coreApi.createFile({uri: fileRoot+result.file.fullPath, contents: result.content}); }.bind(this)); @@ -143,7 +133,7 @@ var ui8a = new Uint8Array(result.content); // var i, l, libs, libjson, xhr = new XMLHttpRequest(), tocopylibs = [], copied; //Getting known json list of libraries to copy to chrome - xhr.open("GET", '/ninja-internal/js/io/system/ninjalibrary.json', false); + xhr.open("GET", '/js/io/system/ninjalibrary.json', false); xhr.send(); //Checkng for correct reponse if (xhr.readyState === 4) { -- cgit v1.2.3