diff --git a/iguana/example.js b/iguana/example.js index e6eba07a5..d8d59f6a8 100755 --- a/iguana/example.js +++ b/iguana/example.js @@ -46,23 +46,98 @@ function errorHandler(e,callback,name) { } var fileSystem=null; var files={}; -function onInitFs(fs) { - console.log('Opened file system: ' + fs.name); - fileSystem = fs; +function copyHelpFiles(callback) { + var helpFiles = [ + 'agent.md', + 'bootstrap-theme.min.css', + 'bootstrap.min.css', + 'bootstrap.min.js', + 'field.html', + 'field.md', + 'footer.html', + 'footer.md', + 'formfooter.html', + 'formfooter.md', + 'formheader.html', + 'formheader.md', + 'header.html', + 'header.md', + 'html5shiv.min.js', + 'jquery-ui.css', + 'jquery-ui.min.js', + 'jquery.min.js', + 'mime.json', + 'respond.min.js' + ]; + var rootDir='help'; + var $dfds = $.map(helpFiles,function(fname){ + var $dfd=$.Deferred(); + $.get(chrome.runtime.getURL(rootDir+'/'+fname)) + .done(function(str){ + fileSystem.root.getFile('/'+rootDir+'/'+fname, { + create: true + }, function(fileEntry) { + // Create a FileWriter object for our FileEntry (log.txt). + fileEntry.createWriter(function(fileWriter) { + fileWriter.onwriteend = function() { + console.log('Write completed.',fname,str.length); + $dfd.resolve(true); + }; + + fileWriter.onerror = function(e) { + console.log('Write failed: ',fname, e.toString()); + $dfd.resolve(false); + }; + + // Create a new Blob and write it to log.txt. + var blob = new Blob([str], { + type: 'text/plain' + }); + + fileWriter.write(blob); + // $dfd.resolve(true); + + }, function(createWriterErr){ + console.log('createWriterErr for',fname,createWriterErr); + $dfd.resolve(false); + }); + + }, function(createFileErr){ + console.log('createFileErr for',fname,createFileErr); + $dfd.resolve(false); + }); + }); + return $dfd; + }); + return $.when.apply($,$dfds); } + + // Called by the common.js module. function domContentLoaded(name, tc, config, width, height) { - navigator.webkitPersistentStorage.requestQuota(10000000000, - function(bytes){ - window.requestFileSystem(PERSISTENT, bytes, onInitFs, errorHandler); - common.updateStatus( + navigator.webkitPersistentStorage.requestQuota(10000000000, + function(bytes) { + window.requestFileSystem(PERSISTENT, bytes, function(fs) { + console.log('Opened file system: ' + fs.name); + fileSystem = fs; + copyHelpFiles().done(function() { + common.updateStatus( 'Allocated ' + bytes + ' bytes of persistent storage. Running the first time will take 17 seconds to load'); - common.attachDefaultListeners(); - common.createNaClModule(name, tc, config, width, height); - }, function(e){ - console.log('Error', e); -}); + common.attachDefaultListeners(); + common.createNaClModule(name, tc, config, width, height); + }); + /*dirReader = fs.root.createReader(); + dirReader.readEntries(function(results) { + console.log(results); + }, function(){ + console.log('File IO error'); + });*/ + }, errorHandler); + }, + function(e) { + console.log('Error', e); + }); } diff --git a/iguana/iguana_rpc.c b/iguana/iguana_rpc.c index a8b86fe8e..ba52faaee 100755 --- a/iguana/iguana_rpc.c +++ b/iguana/iguana_rpc.c @@ -822,7 +822,7 @@ cJSON *SuperNET_urlconv(char *value,int32_t bufsize,char *urlstr) char *SuperNET_rpcparse(struct supernet_info *myinfo,char *retbuf,int32_t bufsize,int32_t *jsonflagp,int32_t *postflagp,char *urlstr,char *remoteaddr,char *filetype,uint16_t port) { cJSON *tokens,*argjson,*origargjson,*json = 0; long filesize; - char symbol[16],buf[4096],urlmethod[16],*data,url[1024],*retstr,*filestr,*token = 0; int32_t i,j,n,num=0; + char symbol[16],buf[4096],urlmethod[16],*data,url[1024],furl[1024],*retstr,*filestr,*token = 0; int32_t i,j,n,num=0; //printf("rpcparse.(%s)\n",urlstr); for (i=0; i0; i--) diff --git a/iguana/manifest.json b/iguana/manifest.json index 678efe67b..ff1e6a9a2 100755 --- a/iguana/manifest.json +++ b/iguana/manifest.json @@ -16,6 +16,9 @@ "128": "icon128.png" }, "minimum_chrome_version": "36", + "web_accessible_resources":[ + "help/*" + ], "permissions": [ { "socket": [ "tcp-listen:*:*", @@ -26,7 +29,9 @@ ] }, "unlimitedStorage", - {"fileSystem": ["write"]}, + {"fileSystem": ["write", + "retainEntries", + "directory"]}, "storage", "system.storage", "system.display",