2013-10-15 40 views
2

我們使用web IDE創建插件。我的test.dll位於數據文件夾中。如何通過js-ctypes加載它?如何從SDK插件數據文件夾加載dll?

有了這樣的「C:\ Test.dll的」絕對路徑都沒有問題,但對於分發,我不能使用此路徑。

var lib = ctypes.open("c:\\test.dll"); 
// works but how i get path to addon inner data directory? 

回答

5

我給你阻力最小的來這裏的路上......還有其他的方法,如手動拆包從安裝的XPI的DLL,但過於寬泛,容易出錯且複雜。

  1. 您需要在package.json中定義"unpack": true,以便在安裝時解壓XPI。
  2. 您需要使用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. 
    
+0

謝謝@nmaier!但是,{ 「解壓」:真正} '得到:錯誤403 FORBIDDEN 「無效的關鍵。 允許的鍵:貢獻者,主頁,圖標,圖標64,ID,偏好,許可證,許可權' – Alexufo

+0

嗯。我測試了一個來自[add-on SDK repository](https://github.com/mozilla/addon-sdk/)的克隆,這對我來說很合適......所以SDK有支持。當你說「web IDE」時,我認爲你的意思是http://builder.addons.mozilla.org/,所以也許你應該提交一個bug:https://bugzilla.mozilla.org/enter_bug.cgi?product=addons。 mozilla.org:成分=附加%20Builder – nmaier

+0

嘗試看看http://s2.ipicture.ru/uploads/20131017/0PJk3F92.jpg – Alexufo