aboutsummaryrefslogtreecommitdiff
path: root/js
diff options
context:
space:
mode:
Diffstat (limited to 'js')
-rw-r--r--js/io/system/chromeapi.js342
-rwxr-xr-xjs/io/system/coreioapi.js167
-rwxr-xr-xjs/io/system/fileio.js15
-rw-r--r--js/io/system/ninjalibrary.js29
4 files changed, 446 insertions, 107 deletions
diff --git a/js/io/system/chromeapi.js b/js/io/system/chromeapi.js
new file mode 100644
index 00000000..04e62b11
--- /dev/null
+++ b/js/io/system/chromeapi.js
@@ -0,0 +1,342 @@
1/* <copyright>
2This file contains proprietary software owned by Motorola Mobility, Inc.<br/>
3No rights, expressed or implied, whatsoever to this software are provided by Motorola Mobility, Inc. hereunder.<br/>
4(c) Copyright 2011 Motorola Mobility, Inc. All Rights Reserved.
5</copyright> */
6
7/* /////////////////////////////////////////////////////////////////////
8////////////////////////////////////////////////////////////////////////
9NOTES:
10 The init function starts up the file system API, and a size must be
11 set, no unlimited available as of now.
12////////////////////////////////////////////////////////////////////////
13///////////////////////////////////////////////////////////////////// */
14//
15var Montage = require("montage/core/core").Montage;
16////////////////////////////////////////////////////////////////////////
17//
18exports.ChromeApi = Montage.create(Object.prototype, {
19 ////////////////////////////////////////////////////////////////////
20 //Needs size in MBs for fileSystem init
21 init: {
22 enumerable: true,
23 value: function(size) {
24 //
25 if (window.webkitRequestFileSystem) {
26 //Current way to init Chrome's fileSystem API
27 window.webkitRequestFileSystem(window.PERSISTENT, size*1024*1024, function (fs) {
28 this.fileSystem = fs;
29 }.bind(this));
30 return true;
31 } else {
32 //No fileSystem API
33 return false;
34 }
35 }
36 },
37 ////////////////////////////////////////////////////////////////////
38 //
39 _fileSystem: {
40 enumerable: false,
41 value: null
42 },
43 ////////////////////////////////////////////////////////////////////
44 //
45 fileSystem: {
46 enumerable: false,
47 get: function() {
48 return this._fileSystem;
49 },
50 set: function(value) {
51 this._fileSystem = value;
52 }
53 },
54 ////////////////////////////////////////////////////////////////////
55 //
56 directoryNew: {
57 enumerable: true,
58 value: function() {
59 }
60 },
61
62 ////////////////////////////////////////////////////////////////////
63 //
64 directoryDelete: {//TODO: Make sure it uses a force delete
65 enumerable: true,
66 value: function() {
67 }
68 },
69 ////////////////////////////////////////////////////////////////////
70 //
71 directoryContents: {
72 enumerable: true,
73 value: function() {
74 }
75 },
76 ////////////////////////////////////////////////////////////////////
77 //
78 directoryCopy: {
79 enumerable: true,
80 value: function() {
81 }
82 },
83 ////////////////////////////////////////////////////////////////////
84 //
85 directoryRename: {
86 enumerable: true,
87 value: function() {
88 }
89 },
90 ////////////////////////////////////////////////////////////////////
91 //
92 directoryMove: {
93 enumerable: true,
94 value: function() {
95 }
96 }
97 ////////////////////////////////////////////////////////////////////
98 ////////////////////////////////////////////////////////////////////
99});
100////////////////////////////////////////////////////////////////////////
101////////////////////////////////////////////////////////////////////////
102
103
104
105//window.webkitRequestFileSystem(window.PERSISTENT, 10*1024*1024 /*10MB*/, function (fs) {
106
107
108
109 /*
110for (var i=1; i<50; i++) {
111 fs.root.getDirectory('montage0.0.0.'+i, {}, function(dirEntry) {
112 //
113 dirEntry.removeRecursively(function() {
114 console.log('Directory removed.');
115 });
116 });
117 }
118*/
119
120
121
122
123
124
125 //
126 /*
127var xhr = new XMLHttpRequest(), dir, mjs;
128 //
129 xhr.open("GET", '/ninja-internal/node_modules/descriptor.json', false);
130 xhr.send();
131 //
132 if (xhr.readyState === 4) {
133 //
134 mjs = JSON.parse(xhr.response);
135 //
136 if (mjs.version) {
137 //Checking for version to exist
138 fs.root.getDirectory('montage'+mjs.version, {}, function(dirEntry) {
139 //Already copied, nothing
140 console.log('montage'+mjs.version+' has already been created');
141 }, function (e) {
142 //Not present, should be copied
143 createFolder(false, {name: 'montage'+mjs.version});
144 //
145 for (var i in mjs.directories) {
146 createFolder('montage'+mjs.version, mjs.directories[i]);
147 }
148 //
149
150
151 for (var j in mjs.files) {
152
153 var frqst = new XMLHttpRequest();
154 frqst.open("GET", '/ninja-internal/node_modules/montage/'+mjs.files[j], false);
155 frqst.send();
156
157 if (frqst.readyState === 4) {
158 createFile('montage'+mjs.version+'/'+mjs.files[j], frqst.response);
159 }
160 }
161
162 //
163 console.log('montage'+mjs.version+' was created');
164 }, folderError);
165 }
166
167 }
168 //
169 function createFile (path, content) {
170 //
171 fs.root.getFile(path, {create: true}, function(fileEntry) {
172 //
173 fileEntry.createWriter(function(fileWriter) {
174 //
175 //console.log(path);
176 var bb = new window.WebKitBlobBuilder;
177 bb.append(content);
178 fileWriter.write(bb.getBlob('text/plain'));
179 }, fileError);
180
181 }, fileError);
182 }
183 //
184 function createFolder(root, folder) {
185 if (folder.name) {
186 if (root) {
187 dir = root+'/'+folder.name;
188 } else {
189 dir = folder.name;
190 }
191 //
192 //console.log(dir);
193 //
194 fs.root.getDirectory(dir, {create: true}, function(dirEntry) {
195 //
196 }, folderError);
197 }
198 //
199 if (folder.children) {
200 for (var i in folder.children) {
201 if (root) {
202 createFolder(root+'/'+folder.name, folder.children[i]);
203 } else {
204 createFolder(folder.name, folder.children[i]);
205 }
206 }
207 }
208 }
209 //
210 function folderError (e) {
211 console.log(e);
212 }
213 function fileError (e) {
214 console.log(e);
215 }
216
217
218 setTimeout( function () {
219 for (var m in mjs.files) {
220
221 fs.root.getFile('montage'+mjs.version+'/'+mjs.files[m], {}, function(fileEntry) {
222
223 console.log(mjs.files[m]);
224
225 fileEntry.file(function(file) {
226
227 var reader = new FileReader();
228 reader.onloadend = function(e) {
229 //console.log(e.target.file.name);