Javascript 如何从SDK加载项数据文件夹加载dll?
我们使用WebIDE创建插件。我的test.dll位于数据文件夹中。如何通过js ctypes加载它 像“c:\test.dll”这样的绝对路径没有问题,但是我不能使用这个路径来分发它Javascript 如何从SDK加载项数据文件夹加载dll?,javascript,firefox-addon,firefox-addon-sdk,Javascript,Firefox Addon,Firefox Addon Sdk,我们使用WebIDE创建插件。我的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? 我在这里给你一条阻力最小的路。。。还有其他方法,比如从安装的XPI中手动解包DLL,但这会变得太广泛、容易出错和复
var lib = ctypes.open("c:\\test.dll");
// works but how i get path to addon inner data directory?
我在这里给你一条阻力最小的路。。。还有其他方法,比如从安装的XPI中手动解包DLL,但这会变得太广泛、容易出错和复杂
“unpack”:true
,以便XPI在安装时解包self.data.url()
和各种其他工具来计算DLL文件的实际路径。在成为文件URI之前,URI可能会多次包装在“资源:”和/或“浏览器:”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.
谢谢@nmaier!但是{“unpack”:true}
get:Error 403 limited'无效密钥。允许的密钥:贡献者、主页、图标、icon64、id、首选项、许可证、权限’
Hmm。我在一个来自的克隆上进行了测试,该克隆对我有效。。。所以SDK有支持。我想你的意思是当你说“web IDE”时,也许你应该提交一个bug:我最近遇到了这个问题,chrome://不起作用,我必须创建一个文件uri,或者一个常规的系统路径(所以file://或C:\\blah\\…)。所以我猜这仍然是真的?