我们使用 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?
最佳答案
我在这里为您提供阻力最小的方法...还有其他方法,例如从安装的 XPI 中手动解压 DLL,但这过于广泛、容易出错且复杂。
- 您需要在 package.json 中定义
"unpack": true
,以便 XPI 在安装时解压。 您需要使用
self.data.url()
和各种其他工具来找出DLL文件的实际路径。在成为文件 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.
关于javascript - 如何从 SDK 插件数据文件夹加载 dll?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19382201/