Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- console.log: link-firefox-addon: clicked file link: smb://diskstationwolf/photo/
- console.log: link-firefox-addon: smb/afp link
- console.log: link-firefox-addon: localpath smb://diskstationwolf/photo/
- console.error: link-firefox-addon:
- 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]
- Stack:
- getNsIFileFromPath@resource://gre/modules/commonjs/toolkit/loader.js -> resource://link-firefox-addon/lib/launchExplorer.js:103:9
- start@resource://gre/modules/commonjs/toolkit/loader.js -> resource://link-firefox-addon/lib/launchExplorer.js:127:23
- onAttach/<@resource://gre/modules/commonjs/toolkit/loader.js -> resource://link-firefox-addon/lib/main.js:49:17
- emit@resource://gre/modules/commonjs/toolkit/loader.js -> resource://gre/modules/commonjs/sdk/event/core.js:104:9
- receive@resource://gre/modules/commonjs/toolkit/loader.js -> resource://gre/modules/commonjs/sdk/content/worker.js:76:18
- emit@resource://gre/modules/commonjs/toolkit/loader.js -> resource://gre/modules/commonjs/sdk/event/core.js:104:9
- emit@resource://gre/modules/commonjs/toolkit/loader.js -> resource://gre/modules/commonjs/sdk/event/core.js:104:9
- emit@resource://gre/modules/commonjs/toolkit/loader.js -> resource://gre/modules/commonjs/sdk/event/core.js:115:45
- processMessageReceived@resource://gre/modules/commonjs/toolkit/loader.js -> resource://gre/modules/commonjs/sdk/remote/parent.js:75:32
- // url2path from here
- // http://sources.disruptive-innovations.com/bluegriffon/trunk/modules/urlHelper.jsm
- function url2path(url) {
- var path = url;
- if (/^file/i.test(url)) {
- try {
- var uri = Cc['@mozilla.org/network/standard-url;1']
- .createInstance(Ci.nsIURL);
- var file = Cc['@mozilla.org/file/local;1']
- .createInstance(Ci.nsILocalFile);
- uri.spec = url;
- try { // decent OS
- var unixPath = uri.path;
- // hack to have ~ path working in Linux
- unixPath = unixPath.replace(/(/){1,2}~/, "~"); // one or two slashes before ~
- file.initWithPath(unixPath);
- } catch (e) {}
- try { // Windows sucks
- file.initWithPath(uri.path.replace(/^//,"").replace(///g,"\"));
- } catch (e) {}
- path = decodeURI(file.path);
- } catch(e) {
- }
- }
- else if ( /^(smb|afp)/i.test(path) ) {
- console.log('smb/afp link');
- // how do we need to handle these links so nsiFile can open them?!
- /*
- var uri = Cc["@mozilla.org/network/standard-url;1"]
- .createInstance(Ci.nsIURI);
- uri.spec=path;
- var file = uri.QueryInterface(Ci.nsIFileURL).file;
- path = decodeURI(uri.spec);
- */
- }
- return path;
- }
- exports.url2path = url2path;
- function getNsIFileFromPath ( path ) {
- var localPath = linkUtil.stripQuotes( path ),
- nsLocalFile, nsiFile;
- // we need this because the nsILocalFile seems not happy with file:/// on Windows
- // (but Windows explorer would be)
- localPath = url2path(localPath); //linkUtil.osSpecificLinkStringFix( localPath );
- console.log('localpath', localPath);
- //localPath = "smb://diskstationwolf/photo/"; //test
- nsFile = Cc[ "@mozilla.org/file/local;1" ].createInstance( Ci.nsILocalFile );
- //nsiFile = new FileUtils.File( localPath ); // is doing the same as the code before, just a wrapper.
- //nsLocalFile.initWithPath( localPath );
- //nsLocalFile.QueryInterface( Ci.nsIFile );
- /*var ioSvc = Cc["@mozilla.org/network/io-service;1"]
- .getService(Ci.nsIIOService);
- var uri = ioSvc.newURI(localPath, "", null); // create nsIURI instances!
- nsiFile = uri.QueryInterface(Ci.nsIFileURL).file;
- */
- // the following code works except smb/afp
- //try {
- nsFile.initWithPath(localPath);
- //nsiFile = new FileUtils.File( localPath ); // is doing the same as the code before, just a wrapper.
- //}
- /*catch(e) {
- console.log('file error', e);
- nsiFile = null;
- }*/
- return nsiFile//nsLocalFile;
- };
- exports.getNsIFileFromPath = getNsIFileFromPath;
- function pathExists( localFile ) {
- //let localFile = getNsIFileFromPath( localPath );
- return localFile && localFile.exists();
- }
- exports.pathExists = pathExists;
- function start( path, reveal ) {
- var nsLocalFile = getNsIFileFromPath( path );
- if ( pathExists( nsLocalFile ) ) {
- if ( reveal ) {
- nsLocalFile.reveal();
- } else {
- nsLocalFile.launch();
- }
- } else {
- notification.show( CONST.APP.name, CONST.MESSAGES.ERROR.BAD_LINK + path );
- }
- }
- exports.start = start;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement