Help with Java code

Hi,

the code below comes from http://www.inspiredgeek.com/2010/12/06/launch-windows-application-directly-from-firefox-a-retake/ and is used to launch windows executables from FireFox through Custom Buttons.

I'm running this on a thumbdrive (FireFox portable) and I need to code to point to the drive itself. In the first line I can set the path to the directory where the apps are found, but I don't know how to tell it to look in its own directory or one up, as the drive's letter changes from time to time.

Any ideas/

Thanks,
Jay
 
var sCuts=dirList("c:/");
var obj=this;
var nMItem=function(label,img,path){
try{
    path = path.replace(/\\/g,'\/');
  var m=document.createElement('menuitem');
  m.setAttribute('label',label);
  m.f=obj.startProcess.bind(obj);
  m.setAttribute('oncommand','this.f("'+path+'")');
  m.setAttribute('class','menuitem-iconic');
  m.setAttribute('image',img);
  m.tooltipText = "Shortcut to "+path;
  return m;
  }
    catch(ex)
    {
        window.alert("Error 1 : " + ex.message);
    }
}

this.startProcess=function(path){
try{
var file = Components.classes['@mozilla.org/file/local;1']
    .createInstance(Components.interfaces.nsILocalFile);
var process = Components.classes['@mozilla.org/process/util;1']
    .getService(Components.interfaces.nsIProcess);
 path = path.replace(/\//g,'\\');
 file.initWithPath(path);
 file.launch();
  }
    catch(ex)
    {
        window.alert("Error 2 : " + ex.message);
    }
}

var mP=createMenu(sCuts);

function createMenu(sCuts)
{
try
{
	var mP=document.createElement('menupopup');
	for (var i=0;i<sCuts.length;i++){
	 if (sCuts[i] =='separator'){
	  mP.appendChild(document.createElement('menuseparator'));
	 }else{
		//alert(sCuts.length);
	  mP.appendChild(nMItem(sCuts[i] [0],sCuts[i] [1],sCuts[i] [2]));
	 }
	}
	return mP;
  }
    catch(ex)
    {
        window.alert("Error : " + ex.message);
    }

}

function dirList(sFilePath)
{
    sFilePath = sFilePath.replace(/\//g,'\\');
	//alert(sFilePath);
    try
    {
        var dir = Components.classes["@mozilla.org/file/local;1"]
                    .createInstance(Components.interfaces.nsILocalFile);
	if (!dir) return false;
        dir.initWithPath(sFilePath);
	//mP.appendChild(file.);
		var contents=dir.directoryEntries;

		var apps=new Array;
	while(contents.hasMoreElements())
	{
	  var i= contents.getNext();
	  var file=i.QueryInterface(Components.interfaces.nsILocalFile);
		if(file.isSymlink())
		{
			apps.push([file.leafName,this.image,file.path]);		
		}
	}
	return apps;
    }
    catch(ex)
    {
        window.alert("Error : " + ex.message);
    }
}


try{
	this.orient="horizontal";
	this.appendChild(mP);
	this.type='menu';
}
catch(ex)
{
  window.alert("Error : " + ex.message);
}
	
	/*---------------------- Show Focus Block Start ------------------------*/

this.style.opacity = '.65';
this.setAttribute('onmouseover', 'custombuttons.ButtonBrt(event);' );
this.setAttribute('onmouseout', 'custombuttons.ButtonDim(event);' );

/*----------------------- Show Focus Block End -------------------------*/

Open in new window

jiiins2Asked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

for_yanCommented:
In JavaScript you can check for existence of a file
through FileSystemObject.
Below is an example of how you can do it.

You can make a loop through possible
drive letters of the thumbdrive and when you find
your filepath existing you'll find the letter of your thumbdrive.

You can probably use DriveType property of the
FileSystemObjecct
http://msdn.microsoft.com/en-us/library/ys4ctaz0%28v=vs.85%29.aspx#Y114
to check the letter before you chek the file existence.
I'm not sure of the syntax.

I guess not all browsers will allow you to use ActiveX though,
but at leats this is some way, maybe it could work.

<script type="text/javascript">

// initialize ActiveXObject and create an object of Scripting.FileSystemObject.

var fso = new ActiveXObject("Scripting.FileSystemObject");

 

// if condition to check whether the specified file exists or not.
if(fso.FileExists("C:\\Temp\\myFolder\\file.txt"))

{
document.write("File.txt exists.");

}

else

{
document.write("File.txt does not exist.");

}

 

fso = null;

</script>

Open in new window


0
jiiins2Author Commented:
Thanks. Or is there any chance that FireFox passes its own location to extensions and add-ons?
0
jiiins2Author Commented:
This does the trick:  
Components.classes["@mozilla.org/file/directory_service;1"].getService( Components.interfaces.nsIProperties).get("ProfD", Components.interfaces.nsIFile).path

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
jiiins2Author Commented:
It's exactly the answer to my question.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Java

From novice to tech pro — start learning today.