Ale*_*ufo 2 javascript firefox-addon firefox-addon-sdk
我们使用Web IDE创建插件.我的test.dll位于数据文件夹中.如何通过js-ctypes加载它?
像"c:\ test.dll"这样的绝对路径没有问题,但我不能用这个路径来分发它.
var lib = ctypes.open("c:\\test.dll");
// works but how i get path to addon inner data directory?
Run Code Online (Sandbox Code Playgroud)
我给你的阻力最小的方式......还有其他方法,比如从已安装的XPI中手动解压缩DLL,但这样做太宽泛,容易出错且复杂.
"unpack": true在package.json中定义,以便在安装时解压缩XPI.您需要使用self.data.url()各种其他工具来确定DLL文件的实际路径.在URI成为文件URI之前,URI可能会在"resource:"和/或"chrome:"URI中被多次包装.所以这也需要打开.
const {Cc, Cu, Ci} = require("chrome");
Cu.import("resource://gre/modules/Services.jsm");
const ResProtocolHandler = Services.io.getProtocolHandler("resource").
QueryInterface(Ci.nsIResProtocolHandler);
const ChromeRegistry = Cc["@mozilla.org/chrome/chrome-registry;1"].
getService(Ci.nsIChromeRegistry);
function resolveToFile(uri) {
switch (uri.scheme) {
case "chrome":
return resolveToFile(ChromeRegistry.convertChromeURL(uri));
case "resource":
return resolveToFile(Services.io.newURI(ResProtocolHandler.resolveURI(uri), null, null));
case "file":
return uri.QueryInterface(Ci.nsIFileURL).file;
default:
throw new Error("Cannot resolve");
}
}
const {data} = require("self");
let dll = data.url("test.dll");
dll = resolveToFile(Services.io.newURI(dll, null, null));
console.log(dll.path); // dll.path is the full, platform-dependent path for the file.
Run Code Online (Sandbox Code Playgroud)| 归档时间: |
|
| 查看次数: |
812 次 |
| 最近记录: |