// Moonlight|3D start script, exits with 1 on errors // Virtual memory of the JVM. // Check Sun's docs for values above 4GB. var mem="1G"; // Set to true to show the java console var showConsole = false; var sh = new ActiveXObject("WScript.Shell"); var env = sh.Environment("PROCESS"); var fso = WScript.CreateObject("Scripting.FileSystemObject"); var moonlightInstDir=WScript.ScriptFullName.substring(0,WScript.ScriptFullName.length-WScript.ScriptName.length-1); logFile = fso.createTextFile(moonlightInstDir + "/mlbatch.out",true,false); logFile.writeLine("Installation Directory: " + moonlightInstDir); /** * Reads a registry entry. * * @param sh An Instance of WScript.Shell. * @param key The name of the key including the complete path. * @return The string representation of the registry value or null if it does not exist. */ function readReg(sh, key) { var res; try { res = sh.RegRead(key); } catch (e) { // Key nonexistant res = null; } return res; } // Is the server VM present? var serverVM = true; // Name of the Java executable, without path var javaExec = showConsole ? "java" : "javaw"; // Is the path already complete (including the exec)? var pathComplete = false; // Path of java directory var javaPath = null; // If you want to override automatic detection (old batfile behaviour), uncomment the following line (remove the slashes). // javaPath = "YOURJAVADIR"; // JAVA_HOME environment variable if (javaPath == null) { var javaHome = env("JAVA_HOME"); if ((javaHome != null) && (javaHome != "")) { if (fso.FolderExists(javaHome)) { javaPath = javaHome; } } } // Probe for JDK if (javaPath == null) { var javaVers = readReg(sh, "HKEY_LOCAL_MACHINE\\SOFTWARE\\JavaSoft\\Java Development Kit\\CurrentVersion"); if (javaVers != null) { javaPath = readReg(sh, "HKEY_LOCAL_MACHINE\\SOFTWARE\\JavaSoft\\Java Development Kit\\" + javaVers + "\\JavaHome"); if (javaPath != null) { serverVM = true; } } } // JRE if (javaPath == null) { var javaVers = readReg(sh, "HKEY_LOCAL_MACHINE\\SOFTWARE\\JavaSoft\\Java Runtime Environment\\CurrentVersion"); if (javaVers != null) { javaPath = readReg(sh, "HKEY_LOCAL_MACHINE\\SOFTWARE\\JavaSoft\\Java Runtime Environment\\" + javaVers + "\\JavaHome"); if (javaPath != null) { serverVM = false; } } } // Java interpreter already in path? (JRE does that by copying the files to C:\Windows\System32) if (javaPath == null) { try { var tph = sh.exec("cmd /c " + javaExec + " -server -version > \\.\nul 2> \\.\nul"); // Wait for termination while (tph.Status == 0) { WScript.sleep(50); } javaPath = javaExec; pathComplete = true; // Likely server VM not found if (tph.ExitCode != 0) { serverVM = false; } } catch (e) { ; // Java not found } } // Guess if (javaPath == null) { var guessedPath = "\\java"; if (fso.FolderExists(guessedPath)) { javaPath = guessedPath; // Assume server VM serverVM = true; } } if (javaPath == null) { WScript.echo("No Java Installation could be found. Please download and install the JDK from http://java.sun.com/javase/downloads/ ."); WScript.quit(1); } // Gather jar files in library directories to assemble class path function getJars(folderName) { var folderObject = fso.getFolder(folderName) var result = ""; for (var enumerator = new Enumerator( folderObject.files ); !enumerator.atEnd(); enumerator.moveNext() ) { var filename=enumerator.item().name; if(filename.substring(filename.length-4,filename.length)==".jar") { if(result == "") { result = folderName + filename; } else { result = result + ";" + folderName + filename; } } } return result; } var libClassPath = getJars(moonlightInstDir + "/lib/jar/") libClassPath = libClassPath + ";" + getJars(moonlightInstDir + "/lib/Win32/i686/") logFile.writeLine("Lib CLASSPATH: " + libClassPath); var options = " -Xdebug -Xmx" + mem + (serverVM ? " -server" : "") + " -Dcom.trolltech.qt.systemlibraries=mingwm10.dll \"-Dcom.trolltech.qt.library-path=" + moonlightInstDir + "\\lib\\Win32\\i686\" \"-Djava.library.path=" + moonlightInstDir + "\\lib\\Win32\\i686\" -cp \"" + libClassPath + " ;mlhdrviewer.jar\" eu.moonlight3d.hdrviewer.HDRBatch \"" + moonlightInstDir + "\""; var arguments = ""; for (var i = 0;i < WScript.Arguments.Length;i++) { var arg = WScript.Arguments.Item(i); arguments += " \"" + arg + "\""; } var cmd = javaPath + (pathComplete ? "" : ("\\bin\\" + javaExec)) + options + arguments; logFile.writeLine(cmd); var ph = sh.Exec(cmd); while(! ph.StdErr.AtEndOfStream) { var line = ph.StdErr.ReadLine(); logFile.writeLine(line); } logFile.close();