Running a packaged exe in the same folder as the installed firefox add-on
I have read this thread, and some other How to run a local exe in my firefox extension
The problem is, at deployment and using firefox 4.0.1, if I install the .xpi extension, the xpi is put inside the \Profiles...\extensions as ****.xpi, which is a compressed format
All the solutions assume that the the extension is put in a folder, thus they are accessing the folder as is, which I cannot do
for example this guy says
//**** get profile folder path ****
var dsprops = Components.classes['@mozilla.org/file/directory_service;1']
.getService(Components.interfaces.nsIProperties);
var ProfilePath = dsprops.get("ProfD", Components.interfaces.nsIFile).path;
//**** initialize file ****
var file = Components.classes["@mozilla.org/file/local;1"]
.createInstance(Components.inter开发者_StackOverflowfaces.nsILocalFile);
file.initWithPath(ProfilePath);
//**** append each step in the path ****
file.append("extensions");
file.append("guid");
file.append("sample.exe");
guid in my case is installed as {f13b157f-b174-47e7-a34d-4815ddfdfeb8}.xpi which cannot be accessible this way
First of all, please do not locate files like this - you are making lots of assumptions about the directory structure of the Firefox profile, any of those could turn out false in a future Firefox version (or even in uncommon extension setup scenarios). See Reference a binary-component to js-ctypes instead for code to locate a file in your extension install directory, simply replace components/linux/myLib.so
by sample.exe
and execute uri.file
.
Second: that's a scenario where packed XPI installation won't work unless you want to extract your executable into a temporary file before running it (which will be complicated). Windows doesn't support running executables from ZIP archives. So you need to add <em:unpack>true</em:unpack>
to your extension's install.rdf to ensure that it is installed as an unpacked directory.
The best answer is to get flashgot Firefox addon , which contanins already executable inside , and is open source , and , study it , this is great way to observe how this actually works. Based on this , You can make as much as You wish addons with executable inside , or add entire program as FF addon. I hope this helps , even if this answer is rather than outdated.
精彩评论