aboutsummaryrefslogtreecommitdiff
path: root/js/io/system/chromeapi.js
diff options
context:
space:
mode:
Diffstat (limited to 'js/io/system/chromeapi.js')
-rw-r--r--js/io/system/chromeapi.js288
1 files changed, 44 insertions, 244 deletions
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, {
66 // 66 //
67 fileNew: { 67 fileNew: {
68 enumerable: true, 68 enumerable: true,
69 value: function(filePath, content, mime, callback) { 69 value: function(filePath, content, callback) {
70 // 70 //
71 this.fileSystem.root.getFile(filePath, {create: true}, function(f) { 71 this.fileSystem.root.getFile(filePath, {create: true}, function(f) {
72 // 72 //
73 f.createWriter(function(writer) { 73 f.createWriter(function(writer) {
74 // 74 //
75 var b = new window.WebKitBlobBuilder; 75 var b, mime, type = filePath.split('.');
76 type = type[type.length-1];
77 switch (type) {
78 case 'bmp':
79 mime = 'image/bmp';
80 break;
81 case 'gif':
82 mime = 'image/gif';
83 break;
84 case 'jpeg':
85 mime = 'image/jpeg';
86 break;
87 case 'jpg':
88 mime = 'image/jpeg';
89 break;
90 case 'png':
91 mime = 'image/png';
92 break;
93 case 'rtf':
94 mime = 'application/rtf';
95 break;
96 case 'tif':
97 mime = 'image/tiff';
98 break;
99 case 'tiff':
100 mime = 'image/tiff';
101 break;
102 case 'pdf':
103 mime = 'application/pdf';
104 break;
105 case 'zip':
106 mime = 'application/zip';
107 break;
108 case 'svg':
109 mime = 'image/svg+xml';
110 break;
111 default:
112 mime = 'text/'+type;
113 break;
114 }
115 //
116 b = new window.WebKitBlobBuilder;
76 b.append(content); 117 b.append(content);
77 writer.write(b.getBlob(mime)); 118 writer.write(b.getBlob(mime));
78 // 119 //
@@ -175,245 +216,4 @@ exports.ChromeApi = Montage.create(Object.prototype, {
175 //////////////////////////////////////////////////////////////////// 216 ////////////////////////////////////////////////////////////////////
176}); 217});
177//////////////////////////////////////////////////////////////////////// 218////////////////////////////////////////////////////////////////////////
178//////////////////////////////////////////////////////////////////////// 219//////////////////////////////////////////////////////////////////////// \ No newline at end of file
179
180
181
182//window.webkitRequestFileSystem(window.PERSISTENT, 10*1024*1024 /*10MB*/, function (fs) {
183
184
185
186 /*
187for (var i=1; i<50; i++) {
188 fs.root.getDirectory('montage0.0.0.'+i, {}, function(dirEntry) {
189 //
190 dirEntry.removeRecursively(function() {
191 console.log('Directory removed.');
192 });
193 });
194 }
195*/
196
197
198
199
200
201
202 //
203 /*
204var xhr = new XMLHttpRequest(), dir, mjs;
205 //
206 xhr.open("GET", '/ninja-internal/node_modules/descriptor.json', false);
207 xhr.send();
208 //
209 if (xhr.readyState === 4) {
210 //
211 mjs = JSON.parse(xhr.response);
212 //
213 if (mjs.version) {
214 //Checking for version to exist
215 fs.root.getDirectory('montage'+mjs.version, {}, function(dirEntry) {
216 //Already copied, nothing
217 console.log('montage'+mjs.version+' has already been created');
218 }, function (e) {
219 //Not present, should be copied
220 createFolder(false, {name: 'montage'+mjs.version});
221 //
222 for (var i in mjs.directories) {
223 createFolder('montage'+mjs.version, mjs.directories[i]);
224 }
225 //
226
227
228 for (var j in mjs.files) {
229
230 var frqst = new XMLHttpRequest();
231 frqst.open("GET", '/ninja-internal/node_modules/montage/'+mjs.files[j], false);
232 frqst.send();
233
234 if (frqst.readyState === 4) {
235 createFile('montage'+mjs.version+'/'+mjs.files[j], frqst.response);
236 }
237 }
238
239 //
240 console.log('montage'+mjs.version+' was created');
241 }, folderError);
242 }
243
244 }
245 //
246 function createFile (path, content) {
247 //
248 fs.root.getFile(path, {create: true}, function(fileEntry) {
249 //
250 fileEntry.createWriter(function(fileWriter) {
251 //
252 //console.log(path);
253 var bb = new window.WebKitBlobBuilder;
254 bb.append(content);
255 fileWriter.write(bb.getBlob('text/plain'));
256 }, fileError);
257
258 }, fileError);
259 }
260 //
261 function createFolder(root, folder) {
262 if (folder.name) {
263 if (root) {
264 dir = root+'/'+folder.name;
265 } else {
266 dir = folder.name;
267 }
268 //
269 //console.log(dir);
270 //
271 fs.root.getDirectory(dir, {create: true}, function(dirEntry) {
272 //
273 }, folderError);
274 }
275 //
276 if (folder.children) {
277 for (var i in folder.children) {
278 if (root) {
279 createFolder(root+'/'+folder.name, folder.children[i]);
280 } else {
281 createFolder(folder.name, folder.children[i]);
282 }
283 }
284 }
285 }
286 //
287 function folderError (e) {
288 console.log(e);
289 }
290 function fileError (e) {
291 console.log(e);
292 }
293
294
295 setTimeout( function () {
296 for (var m in mjs.files) {
297
298 fs.root.getFile('montage'+mjs.version+'/'+mjs.files[m], {}, function(fileEntry) {
299
300 console.log(mjs.files[m]);
301
302 fileEntry.file(function(file) {
303
304 var reader = new FileReader();
305 reader.onloadend = function(e) {
306 //console.log(e.target.file.name);
307 var test = this.createFile({uri: '/Users/kgq387/Desktop/Ninja Cloud/Disk/'+e.target.file.name, contents: e.target.result});
308 }.bind(this);
309
310 reader.file = file;
311 reader.readAsText(file);
312
313 }.bind(this));
314
315 }.bind(this));
316
317 }}.bind(this), 5000);
318*/
319
320
321
322
323
324 //}.bind(this));
325
326
327