2013-07-29 110 views
0

荫试图建立在我的扩展目录中的文件,我有这样的代码:创建文件使用扩展的Firefox

AddonManager.getAddonByID(" extension id here ", function(addon) 
{ 
    var uri = addon.getResourceURI("hello.txt"); 
    var file = Components.classes["@mozilla.org/file/local;1"] 
      .createInstance(Components.interfaces.nsILocalFile); 
    var stringUri = uri.asciiSpec; 
    stringUri = stringUri.replace(new RegExp(/\//g), '\\'); 
    stringUri = stringUri.slice(8); 
    alert(stringUri); 
    try{ 
     file.initWithPath(stringUri); 
    } catch(e) { 
     alert(e); 
    } 
    alert(addon.hasResource("hello.txt")); 
}); 

但由于某些原因最后警报显示总是假的,文件不存在。我究竟做错了什么?

我也把解压缩到的install.rdf真正解包的标签,看看纽约的扩展目录中晚期

感谢。

+0

什么config.json URI,'file'或'jar'的方案的转换? – paa

+0

file ................ – Tony

回答

0

initWithPath只接受本地文件系统路径。假设uri是一个文件的URL,你可以这样做

var path = uri.QueryInterface(Components.interfaces.nsIFileURL).file.path