/* * Moonlight|3D * Copyright (C) 2005 The Moonlight|3D team * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * * Created on Jan 5, 2005 */ package ml; /** * \package ml * * This package contains the main class for Moonlight|3D. */ import com.trolltech.qt.gui.QApplication; import ml.core.State; import ml.core.exceptions.Exception; import ml.core.scripts.Interpreter; /** * This is the batch application main class for Moonlight|3D. * This class is used when Moonlight|3D is started in battch * mode. This main class will take a script or a series of * scripts as an argument and will try to execute them in * order. * * @author gregor */ public class MLBatch { /** * The main constructor for the application * * @throws Exception if something went terribly wrong */ public MLBatch(String[] args) throws Exception { /* * args[] contains the full path to Moonlight|3D in the filesystem. * This parameter is only passed to main because there is no way * to determine this in Java and should be treated as internal. * Therefore it is removed from the command line here and treated * separately. */ String[] strippedArgs=new String[args.length-1]; String installDir=args[0]; if(args.length>1) { System.arraycopy(args, 1, strippedArgs, 0, args.length-1); } args=strippedArgs; /* * On Windows, quotation marks around the installation directory * argument are neccessary to protect white spaces in it, but * the Windows shell does not remove them before passing the * argument to the program. Instead, we have to work around that * here. */ if(installDir.charAt(0)=='"') { installDir=installDir.substring(1,installDir.length()-2); } QApplication qApp=new QApplication(args); State state=ml.core.State.getInstance(); state.setBatchMode(true); state.setInstallationDirectory(installDir); state.setCommandLineArguments(args); state.logger().info("Moonlight|3D " + State.Version.asString() + " starting in batch mode"); state.getPreferencesManager().loadPreferences(); state.getPluginManager().loadPlugins(); state.getPreferencesManager().applyLoadedPreferences(); state.getScriptManager().runStartupScripts(); state.getDocumentManager().createNewMainDocument("MoonlightScene"); if(args.length>0) { String script=args[0]; try { state.logger().info("running script " + script); Interpreter interpreter=state.getScriptManager().createInterpreterForFile(script); interpreter.runFile(script); } catch(Exception e) { System.err.print(e.getFullText()); } } else { state.logger().warning("no script given on command line: exiting without any actions performed"); } state.getPluginManager().unloadPlugins(); state.getPreferencesManager().updatePreferenceFiles(); } /** * The main entry point for Moonlight|3D in batch mode * * @param args command line arguments */ public static void main(String[] args) { try { MLBatch app=new MLBatch(args); } catch(ml.core.exceptions.Exception e) { System.err.print(e.getFullText()); } } }