Advertisement
Guest User

Untitled

a guest
Jan 5th, 2016
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.87 KB | None | 0 0
  1. console.log: link-firefox-addon: clicked file link: smb://diskstationwolf/photo/
  2. console.log: link-firefox-addon: smb/afp link
  3. console.log: link-firefox-addon: localpath smb://diskstationwolf/photo/
  4. console.error: link-firefox-addon:
  5. Message: [Exception... "Component returned failure code: 0x80520001 (NS_ERROR_FILE_UNRECOGNIZED_PATH) [nsILocalFile.initWithPath]" nsresult: "0x80520001 (NS_ERROR_FILE_UNRECOGNIZED_PATH)" location: "JS frame :: resource://gre/modules/commonjs/toolkit/loader.js -> resource://link-firefox-addon/lib/launchExplorer.js :: getNsIFileFromPath :: line 103" data: no]
  6. Stack:
  7. getNsIFileFromPath@resource://gre/modules/commonjs/toolkit/loader.js -> resource://link-firefox-addon/lib/launchExplorer.js:103:9
  8. start@resource://gre/modules/commonjs/toolkit/loader.js -> resource://link-firefox-addon/lib/launchExplorer.js:127:23
  9. onAttach/<@resource://gre/modules/commonjs/toolkit/loader.js -> resource://link-firefox-addon/lib/main.js:49:17
  10. emit@resource://gre/modules/commonjs/toolkit/loader.js -> resource://gre/modules/commonjs/sdk/event/core.js:104:9
  11. receive@resource://gre/modules/commonjs/toolkit/loader.js -> resource://gre/modules/commonjs/sdk/content/worker.js:76:18
  12. emit@resource://gre/modules/commonjs/toolkit/loader.js -> resource://gre/modules/commonjs/sdk/event/core.js:104:9
  13. emit@resource://gre/modules/commonjs/toolkit/loader.js -> resource://gre/modules/commonjs/sdk/event/core.js:104:9
  14. emit@resource://gre/modules/commonjs/toolkit/loader.js -> resource://gre/modules/commonjs/sdk/event/core.js:115:45
  15. processMessageReceived@resource://gre/modules/commonjs/toolkit/loader.js -> resource://gre/modules/commonjs/sdk/remote/parent.js:75:32
  16.  
  17. // url2path from here
  18. // http://sources.disruptive-innovations.com/bluegriffon/trunk/modules/urlHelper.jsm
  19. function url2path(url) {
  20. var path = url;
  21.  
  22. if (/^file/i.test(url)) {
  23. try {
  24. var uri = Cc['@mozilla.org/network/standard-url;1']
  25. .createInstance(Ci.nsIURL);
  26. var file = Cc['@mozilla.org/file/local;1']
  27. .createInstance(Ci.nsILocalFile);
  28. uri.spec = url;
  29.  
  30. try { // decent OS
  31. var unixPath = uri.path;
  32.  
  33. // hack to have ~ path working in Linux
  34. unixPath = unixPath.replace(/(/){1,2}~/, "~"); // one or two slashes before ~
  35.  
  36. file.initWithPath(unixPath);
  37. } catch (e) {}
  38. try { // Windows sucks
  39. file.initWithPath(uri.path.replace(/^//,"").replace(///g,"\"));
  40. } catch (e) {}
  41. path = decodeURI(file.path);
  42. } catch(e) {
  43. }
  44. }
  45. else if ( /^(smb|afp)/i.test(path) ) {
  46. console.log('smb/afp link');
  47. // how do we need to handle these links so nsiFile can open them?!
  48. /*
  49. var uri = Cc["@mozilla.org/network/standard-url;1"]
  50. .createInstance(Ci.nsIURI);
  51. uri.spec=path;
  52.  
  53. var file = uri.QueryInterface(Ci.nsIFileURL).file;
  54.  
  55. path = decodeURI(uri.spec);
  56. */
  57. }
  58.  
  59. return path;
  60. }
  61.  
  62. exports.url2path = url2path;
  63.  
  64. function getNsIFileFromPath ( path ) {
  65. var localPath = linkUtil.stripQuotes( path ),
  66. nsLocalFile, nsiFile;
  67.  
  68. // we need this because the nsILocalFile seems not happy with file:/// on Windows
  69. // (but Windows explorer would be)
  70.  
  71. localPath = url2path(localPath); //linkUtil.osSpecificLinkStringFix( localPath );
  72. console.log('localpath', localPath);
  73.  
  74.  
  75. //localPath = "smb://diskstationwolf/photo/"; //test
  76.  
  77. nsFile = Cc[ "@mozilla.org/file/local;1" ].createInstance( Ci.nsILocalFile );
  78. //nsiFile = new FileUtils.File( localPath ); // is doing the same as the code before, just a wrapper.
  79.  
  80. //nsLocalFile.initWithPath( localPath );
  81. //nsLocalFile.QueryInterface( Ci.nsIFile );
  82.  
  83. /*var ioSvc = Cc["@mozilla.org/network/io-service;1"]
  84. .getService(Ci.nsIIOService);
  85.  
  86. var uri = ioSvc.newURI(localPath, "", null); // create nsIURI instances!
  87.  
  88. nsiFile = uri.QueryInterface(Ci.nsIFileURL).file;
  89. */
  90.  
  91. // the following code works except smb/afp
  92.  
  93. //try {
  94. nsFile.initWithPath(localPath);
  95. //nsiFile = new FileUtils.File( localPath ); // is doing the same as the code before, just a wrapper.
  96. //}
  97. /*catch(e) {
  98. console.log('file error', e);
  99. nsiFile = null;
  100. }*/
  101.  
  102. return nsiFile//nsLocalFile;
  103. };
  104.  
  105. exports.getNsIFileFromPath = getNsIFileFromPath;
  106.  
  107.  
  108. function pathExists( localFile ) {
  109. //let localFile = getNsIFileFromPath( localPath );
  110.  
  111. return localFile && localFile.exists();
  112. }
  113.  
  114. exports.pathExists = pathExists;
  115.  
  116. function start( path, reveal ) {
  117.  
  118. var nsLocalFile = getNsIFileFromPath( path );
  119.  
  120. if ( pathExists( nsLocalFile ) ) {
  121. if ( reveal ) {
  122. nsLocalFile.reveal();
  123. } else {
  124. nsLocalFile.launch();
  125. }
  126. } else {
  127. notification.show( CONST.APP.name, CONST.MESSAGES.ERROR.BAD_LINK + path );
  128. }
  129. }
  130.  
  131. exports.start = start;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement