From 23d958580a785ae265bb0a78f238093cc93cee85 Mon Sep 17 00:00:00 2001
From: Jose Antonio Marquez
Date: Sat, 4 Feb 2012 22:32:18 -0800
Subject: Setting up Chrome File System API class
Chrome file system API will be used to copy over files from the sandboxed app into the sandboxed file system directory (in Chrome) to then be used by the core API and the cloud.
---
js/io/system/chromeapi.js | 295 ++++++++++++++++++++++++++++++++++++++++++++++
js/io/system/coreioapi.js | 161 +++++++++----------------
js/io/system/fileio.js | 2 +-
3 files changed, 351 insertions(+), 107 deletions(-)
create mode 100644 js/io/system/chromeapi.js
(limited to 'js/io/system')
diff --git a/js/io/system/chromeapi.js b/js/io/system/chromeapi.js
new file mode 100644
index 00000000..d1ff6da3
--- /dev/null
+++ b/js/io/system/chromeapi.js
@@ -0,0 +1,295 @@
+/*
+This file contains proprietary software owned by Motorola Mobility, Inc.
+No rights, expressed or implied, whatsoever to this software are provided by Motorola Mobility, Inc. hereunder.
+(c) Copyright 2011 Motorola Mobility, Inc. All Rights Reserved.
+ */
+
+/* /////////////////////////////////////////////////////////////////////
+////////////////////////////////////////////////////////////////////////
+NOTES:
+////////////////////////////////////////////////////////////////////////
+///////////////////////////////////////////////////////////////////// */
+//
+var Montage = require("montage/core/core").Montage;
+////////////////////////////////////////////////////////////////////////
+//
+exports.ChromeApi = Montage.create(Object.prototype, {
+ ////////////////////////////////////////////////////////////////////
+ //Needs size in MBs for fileSystem init
+ init: {
+ enumerable: true,
+ value: function(size) {
+ //
+ if (window.webkitRequestFileSystem) {
+ //Current way to init Chrome's fileSystem API
+ window.webkitRequestFileSystem(window.PERSISTENT, size*1024*1024, function (fs) {
+ this.fileSystem = fs;
+ }).bind(this);
+ } else {
+ //No fileSystem API
+ }
+ }
+ },
+ ////////////////////////////////////////////////////////////////////
+ //
+ _fileSystem: {
+ enumerable: false,
+ value: null
+ },
+ ////////////////////////////////////////////////////////////////////
+ //
+ fileSystem: {
+ enumerable: false,
+ get: function() {
+ return this._fileSystem;
+ },
+ set: function(value) {
+ this._fileSystem = value;
+ }
+ }
+ ////////////////////////////////////////////////////////////////////
+ ////////////////////////////////////////////////////////////////////
+});
+////////////////////////////////////////////////////////////////////////
+////////////////////////////////////////////////////////////////////////
+
+
+
+//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
diff --git a/js/io/system/coreioapi.js b/js/io/system/coreioapi.js
index 99f46fd7..fa6c4cf6 100755
--- a/js/io/system/coreioapi.js
+++ b/js/io/system/coreioapi.js
@@ -15,89 +15,20 @@ NOTES:
var Montage = require("montage/core/core").Montage,
Component = require("montage/ui/component").Component,
Popup = require("js/components/popup.reel").Popup,
- CloudPopup = require("js/io/ui/cloudpopup.reel").CloudPopup;
+ CloudPopup = require("js/io/ui/cloudpopup.reel").CloudPopup,
+ ChromeApi = require("js/io/system/chromeapi").ChromeApi;
////////////////////////////////////////////////////////////////////////
//Exporting as Project I/O
exports.CoreIoApi = Montage.create(Component, {
- ////////////////////////////////////////////////////////////////////
+ ////////////////////////////////////////////////////////////////////
//
deserializedFromTemplate: {
enumerable: false,
value: function () {
-
-
-
- ////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////
- //TODO: Remove, this is only for testing
-
-
- window.webkitRequestFileSystem(window.PERSISTENT, 10*1024*1024 /*10MB*/, function (fs) {
-
-
- console.log(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 bb = new window.WebKitBlobBuilder;
- bb.append('In condimentum facilisis porta. Sed nec diam eu diam mattis viverra. Nulla fringilla, orci ac euismod semper, magna diam porttitor mauris, quis sollicitudin sapien justo in libero. Vestibulum mollis mauris enim. Morbi euismod magna ac lorem rutrum elementum. Donec viverra auctor lobortis. Pellentesque eu est a nulla placerat dignissim. Morbi a enim in magna semper bibendum. Etiam scelerisque, nunc ac egestas consequat, odio nibh euismod nulla, eget auctor orci nibh vel nisi. Aliquam erat volutpat. Mauris vel neque sit amet nunc gravida congue sed sit amet purus. Quisque lacus quam, egestas ac tincidunt a, lacinia vel velit. Aenean facilisis nulla vitae urna tincidunt congue sed ut dui. Morbi malesuada nulla nec purus convallis consequat. Vivamus id mollis quam. Morbi ac commodo nulla. In condimentum orci id nisl volutpat bibendum. Quisque commodo hendrerit lorem quis egestas. Maecenas quis tortor arcu. Vivamus rutrum nunc non neque consectetur quis placerat neque lobortis. Nam vestibulum, arcu sodales feugiat consectetur, nisl orci bibendum elit, eu euismod magna sapien ut nibh. Donec semper quam scelerisque tortor dictum gravida. In hac habitasse platea dictumst. Nam pulvinar, odio sed rhoncus suscipit, sem diam ultrices mauris, eu consequat purus metus eu velit. Proin metus odio, aliquam eget molestie nec, gravida ut sapien. Phasellus quis est sed turpis sollicitudin venenatis sed eu odio. Praesent eget neque eu eros interdum malesuada non vel leo. Sed fringilla porta ligula egestas tincidunt. Nullam risus magna, ornare vitae varius eget, scelerisque a libero. Morbi eu porttitor ipsum. Nullam lorem nisi, posuere quis volutpat eget, luctus nec massa. Pellentesque aliquam lacinia tellus sit amet bibendum. Ut posuere justo in enim pretium scelerisque. Etiam ornare vehicula euismod. Vestibulum at risus augue. Sed non semper dolor. Sed fringilla consequat velit a porta. Pellentesque sed lectus pharetra ipsum ultricies commodo non sit amet velit. Suspendisse volutpat lobortis ipsum, in scelerisque nisi iaculis a. Duis pulvinar lacinia commodo. Integer in lorem id nibh luctus aliquam. Sed elementum, est ac sagittis porttitor, neque metus ultricies ante, in accumsan massa nisl non metus. Vivamus sagittis quam a lacus dictum tempor. Nullam in semper ipsum. Cras a est id massa malesuada tincidunt. Etiam a urna tellus. Ut rutrum vehicula dui, eu cursus magna tincidunt pretium. Donec malesuada accumsan quam, et commodo orci viverra et. Integer tincidunt sagittis lectus. Mauris ac ligula quis orci auctor tincidunt. Suspendisse odio justo, varius id posuere sit amet, iaculis sit amet orci. Suspendisse potenti. Suspendisse potenti. Aliquam erat volutpat. Sed posuere dignissim odio, nec cursus odio mollis et. Praesent cursus, orci ut dictum adipiscing, tellus ante porttitor leo, vel gravida lacus lorem vitae est. Duis ultricies feugiat ante nec aliquam. Maecenas varius, nulla vel fermentum semper, metus nibh bibendum nunc, vitae suscipit mauris velit ac nunc. Mauris nunc eros, egestas at vehicula tincidunt, commodo ac mauris. Nulla facilisi. Nunc eros sem, lobortis non pulvinar id, blandit in eros. In bibendum suscipit');
- 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.result);
- };
-
- reader.readAsText(file);
-
- });
-
- });
-
- }
-
-
- end = new Date().getTime();
- time = end - start;
- console.log('Read execution time: ' + time);
-
-
-
-
-
-
- }.bind(this));
-
-
+ //Getting reference of chrome file system API
+ this.chromeFileSystem = ChromeApi;
////////////////////////////////////////////////////////////
- ////////////////////////////////////////////////////////////
-
-
-
//Checking for local storage of URL for IO
if (window.localStorage['ioRootUrl']) {
//Getting URL from local storage
@@ -108,46 +39,25 @@ exports.CoreIoApi = Montage.create(Component, {
//IO API to be inactive
this.ioServiceDetected = false;
}
+ ////////////////////////////////////////////////////////////
}
},
- ////////////////////////////////////////////////////////////////////
- //Method to check status of I/O API, will return false if not active
- cloudAvailable: {
- enumerable: false,
- value: function () {
- var cloud = this.getCloudStatus();
- //
- if (this.rootUrl && cloud.status === 200) {
- //Active
- this.cloudData.name = cloud.response['name'];
- this.cloudData.root = cloud.response['server-root'];
- return true;
- } else {
- //Inactive
- if (!this._cloudDialogOpen && this.application.ninja) {
- this.showCloudDialog();
- }
- return false;
- }
- }
- },
- ////////////////////////////////////////////////////////////////////
- //
- _cloudDialogOpen: {
- enumerable: false,
- value: false
- },
////////////////////////////////////////////////////////////////////
//
- cloudData: {
- enumerable: false,
- value: {name: null, root: ''}
+ _chromeFileSystem: {
+ enumerable: false,
+ value: null
},
////////////////////////////////////////////////////////////////////
//
- _cloudDialogComponents: {
+ chromeFileSystem: {
enumerable: false,
- value: {blackout: null, popup: null, dialog: null}
+ get: function() {
+ return this._chromeFileSystem;
+ },
+ set: function(value) {
+ this._chromeFileSystem = value;
+ }
},
////////////////////////////////////////////////////////////////////
//
@@ -255,6 +165,45 @@ exports.CoreIoApi = Montage.create(Component, {
}
},
////////////////////////////////////////////////////////////////////
+ //Method to check status of I/O API, will return false if not active
+ cloudAvailable: {
+ enumerable: false,
+ value: function () {
+ var cloud = this.getCloudStatus();
+ //
+ if (this.rootUrl && cloud.status === 200) {
+ //Active
+ this.cloudData.name = cloud.response['name'];
+ this.cloudData.root = cloud.response['server-root'];
+ return true;
+ } else {
+ //Inactive
+ if (!this._cloudDialogOpen && this.application.ninja) {
+ this.showCloudDialog();
+ }
+ return false;
+ }
+ }
+ },
+ ////////////////////////////////////////////////////////////////////
+ //
+ _cloudDialogOpen: {
+ enumerable: false,
+ value: false
+ },
+ ////////////////////////////////////////////////////////////////////
+ //
+ cloudData: {
+ enumerable: false,
+ value: {name: null, root: ''}
+ },
+ ////////////////////////////////////////////////////////////////////
+ //
+ _cloudDialogComponents: {
+ enumerable: false,
+ value: {blackout: null, popup: null, dialog: null}
+ },
+ ////////////////////////////////////////////////////////////////////
//
showCloudDialog: {
enumerable: false,
diff --git a/js/io/system/fileio.js b/js/io/system/fileio.js
index 4ab98606..355812da 100755
--- a/js/io/system/fileio.js
+++ b/js/io/system/fileio.js
@@ -17,7 +17,7 @@ NOTES:
////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////// */
//
-var Montage = require("montage/core/core").Montage;
+var Montage = require("montage/core/core").Montage;
////////////////////////////////////////////////////////////////////////
//Exporting as File I/O
exports.FileIo = Montage.create(Object.prototype, {
--
cgit v1.2.3
From 8c530e9291721083ba11746fc5b3da66dc692120 Mon Sep 17 00:00:00 2001
From: Jose Antonio Marquez
Date: Sun, 5 Feb 2012 10:42:58 -0800
Subject: Setting up IO Ninja Library
This class will be used to copy locally the library needed for Ninja's IO.
---
js/io/system/chromeapi.js | 49 +++++++++++++++++++++++++++++++++++++++++++-
js/io/system/coreioapi.js | 6 ++++++
js/io/system/fileio.js | 13 ++++++++++++
js/io/system/ninjalibrary.js | 29 ++++++++++++++++++++++++++
4 files changed, 96 insertions(+), 1 deletion(-)
create mode 100644 js/io/system/ninjalibrary.js
(limited to 'js/io/system')
diff --git a/js/io/system/chromeapi.js b/js/io/system/chromeapi.js
index d1ff6da3..04e62b11 100644
--- a/js/io/system/chromeapi.js
+++ b/js/io/system/chromeapi.js
@@ -7,6 +7,8 @@ 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.
////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////// */
//
@@ -24,9 +26,11 @@ exports.ChromeApi = Montage.create(Object.prototype, {
//Current way to init Chrome's fileSystem API
window.webkitRequestFileSystem(window.PERSISTENT, size*1024*1024, function (fs) {
this.fileSystem = fs;
- }).bind(this);
+ }.bind(this));
+ return true;
} else {
//No fileSystem API
+ return false;
}
}
},
@@ -46,6 +50,49 @@ exports.ChromeApi = Montage.create(Object.prototype, {
set: function(value) {
this._fileSystem = value;
}
+ },
+ ////////////////////////////////////////////////////////////////////
+ //
+ directoryNew: {
+ enumerable: true,
+ value: function() {
+ }
+ },
+
+ ////////////////////////////////////////////////////////////////////
+ //
+ directoryDelete: {//TODO: Make sure it uses a force delete
+ enumerable: true,
+ value: function() {
+ }
+ },
+ ////////////////////////////////////////////////////////////////////
+ //
+ directoryContents: {
+ enumerable: true,
+ value: function() {
+ }
+ },
+ ////////////////////////////////////////////////////////////////////
+ //
+ directoryCopy: {
+ enumerable: true,
+ value: function() {
+ }
+ },
+ ////////////////////////////////////////////////////////////////////
+ //
+ directoryRename: {
+ enumerable: true,
+ value: function() {
+ }
+ },
+ ////////////////////////////////////////////////////////////////////
+ //
+ directoryMove: {
+ enumerable: true,
+ value: function() {
+ }
}
////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////
diff --git a/js/io/system/coreioapi.js b/js/io/system/coreioapi.js
index c34e0736..73d9fa76 100755
--- a/js/io/system/coreioapi.js
+++ b/js/io/system/coreioapi.js
@@ -28,6 +28,12 @@ exports.CoreIoApi = Montage.create(Component, {
////////////////////////////////////////////////////////////
//Getting reference of chrome file system API
this.chromeFileSystem = ChromeApi;
+ //Sending size in MBs for file system storage
+ if (this.chromeFileSystem.init(20)) {
+ //Available
+ } else {
+ //Not available
+ }
////////////////////////////////////////////////////////////
//Checking for local storage of URL for IO
if (window.localStorage['ioRootUrl']) {
diff --git a/js/io/system/fileio.js b/js/io/system/fileio.js
index 355812da..2c49e849 100755
--- a/js/io/system/fileio.js
+++ b/js/io/system/fileio.js
@@ -91,6 +91,19 @@ exports.FileIo = Montage.create(Object.prototype, {
},
////////////////////////////////////////////////////////////////////
//
+ deleteFile: {
+ enumerable: true,
+ value: function() {
+ //Checking for API to be available
+ if (!this.application.ninja.coreIoApi.cloudAvailable()) {
+ //API not available, no IO action taken
+ return null;
+ }
+ //
+ }
+ },
+ ////////////////////////////////////////////////////////////////////
+ //
copyFile: {
enumerable: true,
value: function() {
diff --git a/js/io/system/ninjalibrary.js b/js/io/system/ninjalibrary.js
new file mode 100644
index 00000000..3f8585ed
--- /dev/null
+++ b/js/io/system/ninjalibrary.js
@@ -0,0 +1,29 @@
+/*
+This file contains proprietary software owned by Motorola Mobility, Inc.
+No rights, expressed or implied, whatsoever to this software are provided by Motorola Mobility, Inc. hereunder.
+(c) Copyright 2011 Motorola Mobility, Inc. All Rights Reserved.
+ */
+
+/* /////////////////////////////////////////////////////////////////////
+////////////////////////////////////////////////////////////////////////
+NOTES:
+////////////////////////////////////////////////////////////////////////
+///////////////////////////////////////////////////////////////////// */
+//
+var Montage = require("montage/core/core").Montage;
+////////////////////////////////////////////////////////////////////////
+//
+exports.NinjaLibrary = Montage.create(Object.prototype, {
+ ////////////////////////////////////////////////////////////////////
+ //
+ init: {
+ enumerable: true,
+ value: function() {
+ //
+ }
+ }
+ ////////////////////////////////////////////////////////////////////
+ ////////////////////////////////////////////////////////////////////
+});
+////////////////////////////////////////////////////////////////////////
+////////////////////////////////////////////////////////////////////////
\ No newline at end of file
--
cgit v1.2.3