
/****************************************************************************
 * 
 * External Support for Lyrics Master 2.0 - Version 1.0
 * Copyright (C) 2007, Kenichi Maehashi. All rights reserved.
 * 
 ***************************************************************************/

var searchMethod = "";
var searchKeyword1 = "";
var searchKeyword2 = "";
var targetDir = getScriptDirectory();

try
{
	searchMethod = WScript.Arguments( 0 );
	searchKeyword1 = WScript.Arguments( 1 );
	searchKeyword2 = WScript.Arguments( 2 );
}
catch (e)
{
	if (e.number != -2146828279)
	{
		WScript.Echo( "引数を取得できませんでした。\n\n" + e.description );
	}
}

if ((searchMethod == "title")||(searchMethod == "artist")||(searchMethod == "multi")||(searchMethod == "lyrics")||(searchMethod == "tv"))
{
	if (searchKeyword1 != "")
	{
		try
		{
			var myFso = WScript.CreateObject( "Scripting.FileSystemObject" );
			
			// Overwrite = true, Unicode = false
			var searchFileTS = myFso.CreateTextFile( targetDir + "search.lyricsmaster", true, false );
			searchFileTS.WriteLine(searchMethod);
			searchFileTS.WriteLine(searchKeyword1);
			searchFileTS.WriteLine(searchKeyword2);
			searchFileTS.Close();
		}
		catch (e)
		{
			WScript.Echo( "検索用のファイルを作成できませんでした。\n\n" + e.description );
		}
	}
}

		
try
{
	var myShell = WScript.CreateObject( "WScript.Shell" );
	var programToRun = String.fromCharCode(0x22) + targetDir + "LyricsMaster.exe" + String.fromCharCode(0x22);
	myShell.Run(programToRun);
}
catch (e)
{
	WScript.Echo( "Lyrics Master を起動できませんでした。\n\n" + e.description );
}


function getScriptDirectory()
{
	var scriptPath = WScript.ScriptFullName;
	var scriptDir = scriptPath.substr( 0, scriptPath.lastIndexOf("\\") + 1 );
	return scriptDir;
}