开发者

Firefox extension: download and unpack ZIP

How can I download and unpack ZIP file to extension folder?

Need to update my resources/config from ZIP package stored online.

Is this possible?

开发者_开发知识库

Please point me over to documentation or examples

Thanks


In Firefox 4+ you can get the directory of your extension like this:

Components.utils.import("resource://gre/modules/AddonManager.jsm");
Components.utils.import("resource://gre/modules/Services.jsm");
AddonManager.getAddonByID(extensionID, function(addon) {
  var extensionDir =
    Services.io.getProtocolHandler("file").QueryInterface(Ci.nsIFileProtocolHandler).
      getFileFromURLSpec(addon.getResourceURI(null).spec);
}

To download the file from an extension, create an XMLHttpRequest using:

var xhr = Cc["@mozilla.org/xmlextras/xmlhttprequest;1"].createInstance(Ci.nsIXMLHttpReques‌​t);

You can read the ZIP file using the nsIZipReader XPCOM interface (see http://mxr.mozilla.org/mozilla-central/source/modules/libjar/nsIZipReader.idl). Instantiate the component like this:

var zipReader = Cc["@mozilla.org/libjar/zip-reader;1"].createInstance(Ci.nsIZipReader);
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜