X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=common%2Fmodules%2Fstorage.jsm;fp=common%2Fmodules%2Fstorage.jsm;h=896daf4461189867811231b5c916dba25887f93b;hb=70740024f9c028c1fd63e1a1850ab062ff956054;hp=28ad0e8dd0715d0b7b3ad2946c907806d8f7050f;hpb=718c614c183350706466e22939d0101ca4c87efe;p=dactyl.git diff --git a/common/modules/storage.jsm b/common/modules/storage.jsm index 28ad0e8..896daf4 100644 --- a/common/modules/storage.jsm +++ b/common/modules/storage.jsm @@ -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;