]> _ Git - fluidbook-html5.git/commitdiff
(no commit message)
authorVincent Vanwaelscappel <vincent@cubedesigners.com>
Mon, 9 Sep 2013 10:17:44 +0000 (10:17 +0000)
committerVincent Vanwaelscappel <vincent@cubedesigners.com>
Mon, 9 Sep 2013 10:17:44 +0000 (10:17 +0000)
js/libs/gal/gal.filesystem.js
js/libs/gal/gal.js
js/main.js

index 70f061db2b777717b872aa2662808ebbf4049495..2685572c32723123e2b0389b548cdb1f66d10c90 100644 (file)
@@ -21,7 +21,7 @@
  */
 
 (function(gal) {
-       var ROOT_DIR = 'gal';
+       var ROOT_DIR;
        var DEFAULT_QUOTA = 1024 * 1024 * 100;
 
        function onError(error) {
         *    initialized.
         * @param {string} opt_quota The quota (in bytes) to request (optional).
         */
-       GALFS.prototype.init = function(callback, opt_quota) {
+       GALFS.prototype.init = function(fsprefix, callback, opt_quota) {
+               if (fsprefix == undefined) {
+                       fsprefix = '';
+               }
+               if (fsprefix != '') {
+                       fsprefix += '/';
+               }
+               ROOT_DIR = fsprefix + "gal";
                // requestFileSystem and storageInfo shims
                var requestFileSystem = window.requestFileSystem ||
                                window.webkitRequestFileSystem;
                var onInitFs = function(fs) {
                        that.fs = fs;
 
-                       // Create a directory for the root of the GAL
-                       fs.root.getDirectory(ROOT_DIR, {create: true}, function(dirEntry) {
-                               that.root = dirEntry;
-                               callback();
-                       }, onError);
+                       createDir_(fs.root, ROOT_DIR.split('/'), function(res) {
+                               // Create a directory for the root of the GAL
+                               fs.root.getDirectory(ROOT_DIR, {create: true}, function(dirEntry) {
+                                       that.root = dirEntry;
+                                       callback();
+                               }, onError);
+                       });
+
+
                };
 
                // Callback when the filesystem API has granted quota
        /**
         * Clears everything out of the root directory. Mostly for unit testing.
         */
-       GALFS.prototype.clear = function() {
+       GALFS.prototype.clear = function(cb) {
                // Remove the root directory
                this.root.removeRecursively(function() {
                }, onError);
 
                var that = this;
-               this.lookupTable = {};
                // And then recreate it
-               this.fs.root.getDirectory(ROOT_DIR, {create: true}, function(dirEntry) {
-                       that.root = dirEntry;
-               }, onError);
+               fs = this.fs;
+
+               createDir_(fs.root, ROOT_DIR.split('/'), function(res) {
+                       // Create a directory for the root of the GAL
+                       fs.root.getDirectory(ROOT_DIR, {create: true}, function(dirEntry) {
+                               that.root = dirEntry;
+                               callback();
+                       }, onError);
+               });
+
+               cb();
        };
 
        if (!gal) {
index 634d18109455a77643451aacb0c5b5db55c930b9..4848f28c825d27a9bde293d26076d4adc296ef71 100644 (file)
         * @constructor
         * @param {Object} manifest URL to manifest file.
         */
-       var GAL = function(manifest) {
+       var GAL = function(manifest, fsprefix) {
+               if (fsprefix == undefined) {
+                       fsprefix = '';
+               }
+
+               this._fsprefix = fsprefix;
                this._manifest = manifest;
                // Dictionary of arrays of all of the bundles contained in the manifest.
                this.bundles = {};
@@ -35,6 +40,7 @@
                this.loaded = {};
                this.progress = {};
                this.error = {};
+               this.adapter = null;
        };
 
        /**
                return this.adapter.root.toURL();
        };
 
+       GAL.prototype.initAdapter = function(callback) {
+               if (null == this.adapter) {
+                       initAdapter_(callback);
+               } else {
+                       callback(this.adapter);
+               }
+       };
        GAL.prototype.downloadAll = function() {
-               console.log('downloadAll');
                downloadAll_.call(this);
        };
 
+       GAL.prototype.clear = function(callback) {
+               var $this = this;
+
+               this.initAdapter(
+                               function(adapter) {
+                                       adapter.clear(callback);
+                               }
+               );
+       };
 
        /**
         * @private
         * @param {function} callback Called when the adapter has initialized.
         */
        function initAdapter_(callback) {
+               var $this = this;
+
+               if (this.adapter != null) {
+                       callback(this.adapter);
+                       return;
+               }
+
                this.adapter = new GAL.adapterClass();
-               this.adapter.init(function() {
-                       callback();
+               this.adapter.init(this._fsprefix, function() {
+                       callback($this.adapter);
                });
        }
 
                initAdapter_.call(context, function() {
                        setManifest_.call(context, manifest);
                        // Optionally, start auto-download.
+                       console.log('autodownload ' + manifest.autoDownload);
                        if (manifest.autoDownload && context.online()) {
                                downloadAll_.call(context);
                        }
        }
 
        /**
-        * 
+        * @private
         * Starts downloading all of the assets in the manifest, in order.
         */
        function downloadAll_() {
                var that = this;
                // Start by downloading the first bundle, then download subsequent ones.
                (function loop(bundleIndex) {
+                       console.log(bundleIndex);
                        if (bundleIndex == that.bundleOrder.length) {
                                // We're done downloading stuff!
+                               console.log('ok !');
                                return;
                        }
 
+
                        var bundleName = that.bundleOrder[bundleIndex];
+                       console.log('loading ' + bundleName);
                        that.onLoaded(bundleName, function() {
                                // Once bundle is loaded, load the next bundle.
                                loop(bundleIndex + 1);
index 1bab2dc17f58ce43ac38e9f235f7fa574276b552..2ab62ac0042388a03e15a67f2a941a9c9af93a31 100644 (file)
@@ -52,10 +52,12 @@ function onAppResume() {
 }
 
 function onDeviceReady() {
+
        var manifest = window.sessionStorage.getItem('manifest.' + DATAS.id);
+       var fsprefix = window.sessionStorage.getItem('galfsprefix');
        if (navigator.onLine && manifest) {
                gal = new GameAssetLoader(JSON.parse(manifest));
-               gal.init(function() {
+               gal.init(fsprefix, function() {
                        startAfterLoading = true;
                        init();
                });