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.nsIXMLHttpRequest);
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);
精彩评论