]> git.donarmstrong.com Git - dactyl.git/blobdiff - common/modules/storage.jsm
Import 1.0b7.1 supporting Firefox up to 8.*
[dactyl.git] / common / modules / storage.jsm
index 28ad0e8dd0715d0b7b3ad2946c907806d8f7050f..896daf4461189867811231b5c916dba25887f93b 100644 (file)
@@ -150,6 +150,10 @@ var Storage = Module("Storage", {
 
     init: function () {
         this.cleanup();
+
+        if (services.bootstrap && !services.bootstrap.session)
+            services.bootstrap.session = {};
+        this.session = services.bootstrap ? services.bootstrap.session : {};
     },
 
     cleanup: function () {
@@ -294,9 +298,9 @@ var File = Class("File", {
         let file = services.File();
 
         if (path instanceof Ci.nsIFile)
-            file = path.QueryInterface(Ci.nsIFile).clone();
+            file = path.clone();
         else if (/file:\/\//.test(path))
-            file = services["file:"]().getFileFromURLSpec(path);
+            file = services["file:"].getFileFromURLSpec(path);
         else {
             try {
                 let expandedPath = File.expandPath(path);
@@ -316,14 +320,19 @@ var File = Class("File", {
         return self;
     },
 
+    /**
+     * @property {nsIFileURL} Returns the nsIFileURL object for this file.
+     */
+    get URI() services.io.newFileURI(this),
+
     /**
      * Iterates over the objects in this directory.
      */
     iterDirectory: function () {
         if (!this.exists())
-            throw Error("File does not exist");
+            throw Error(_("io.noSuchFile"));
         if (!this.isDirectory())
-            throw Error("Not a directory");
+            throw Error(_("io.eNotDir"));
         for (let file in iter(this.directoryEntries))
             yield File(file);
     },
@@ -358,11 +367,11 @@ var File = Class("File", {
      *
      * @param {boolean} sort Whether to sort the returned directory
      *     entries.
-     * @returns {nsIFile[]}
+     * @returns {[nsIFile]}
      */
     readDirectory: function (sort) {
         if (!this.isDirectory())
-            throw Error("Not a directory");
+            throw Error(_("io.eNotDir"));
 
         let array = [e for (e in this.iterDirectory())];
         if (sort)
@@ -426,14 +435,11 @@ var File = Class("File", {
 
         ofstream.init(this, mode, perms, 0);
         try {
-            if (callable(buf))
-                buf(ofstream.QueryInterface(Ci.nsIOutputStream));
-            else {
-                var ocstream = getStream(0);
-                ocstream.writeString(buf);
-            }
+            var ocstream = getStream(0);
+            ocstream.writeString(buf);
         }
-        catch (e if callable(buf) && e.result == Cr.NS_ERROR_LOSS_OF_SIGNIFICANT_DATA) {
+        catch (e if e.result == Cr.NS_ERROR_LOSS_OF_SIGNIFICANT_DATA) {
+            ocstream.close();
             ocstream = getStream("?".charCodeAt(0));
             ocstream.writeString(buf);
             return false;