System.setProperty("java.net.preferIPv4Stack" , "true");
SplashScreen splash = new SplashScreen(Toolkit.getDefaultToolkit().getImage(SplashScreen.class.getResource("/org/spoutcraft/launcher/resources/splash.png")));
splash.setVisible(true);
StartupParameters params = setupParameters(args);
SpoutcraftLauncher.logger = setupLogger();
cleanup();
int launcherBuild = parseInt(getLauncherBuild(), -1);
logger.info("---------------------------------------------");
logger.info("Spoutcraft Launcher is starting...");
logger.info("Operating System: " + System.getProperty("os.name") + " " + System.getProperty("os.version") + " " + System.getProperty("os.arch"));
logger.info("Java Version: " + System.getProperty("java.vendor") + " " + System.getProperty("java.version") + " <" + System.getProperty("java.vendor.url") + ">");
logger.info("Launcher Build: " + launcherBuild);
params.logParameters(logger);
// Setup directories
SpoutcraftDirectories dirs = new SpoutcraftDirectories();
dirs.getSkinDir().mkdirs();
dirs.getSpoutcraftDir().mkdirs();
if (Settings.getYAML() == null) {
YAMLProcessor settings = setupSettings();
if (settings == null) {
throw new NullPointerException("The YAMLProcessor object was null for settings.");
}
Settings.setYAML(settings);
}
Settings.setLauncherBuild(launcherBuild);
setupProxy();
if (params.isDebugMode()) {
Settings.setDebugMode(true);
}
if (Settings.isDebugMode()) {
logger.info("Initial organization and look and feel time took " + (System.currentTimeMillis() - start) + " ms");
start = System.currentTimeMillis();
}
if (Settings.isDebugMode()) {
logger.info("Loading settings took " + (System.currentTimeMillis() - start) + " ms");
start = System.currentTimeMillis();
}
if (params.relaunch(logger)) {
try {
Thread.sleep(3000);
} catch (InterruptedException e) { }
System.exit(0);
return;
}
checkInternet();
validateBuild(params);
setLookAndFeel();
if (params.isConsole() || Settings.isDebugMode()) {
setupConsole();
logger.info("Debug mode activated!");
}
Runtime.getRuntime().addShutdownHook(new ShutdownThread());
Thread logThread = new LogFlushThread();
logThread.start();
if (Settings.isDebugMode()) {
logger.info("Internet validation and look and feel took " + (System.currentTimeMillis() - start) + " ms");
start = System.currentTimeMillis();
}
// Set up the launcher and load login frame
LoginFrame frame = new MetroLoginFrame();
try {
@SuppressWarnings("unused")
Launcher launcher = new Launcher(new GameUpdater(), new GameLauncher(), frame);
} catch (IOException failure) {
failure.printStackTrace();
ErrorDialog dialog = new ErrorDialog(frame, failure);
splash.dispose();
frame.setVisible(true);
dialog.setAlwaysOnTop(true);
dialog.setVisible(true);
return;
}
Launcher.getGameUpdater().start();
if (Settings.isDebugMode()) {
logger.info("Loading default launcher skin took " + (System.currentTimeMillis() - start) + " ms");
start = System.currentTimeMillis();
}
splash.dispose();
frame.setVisible(true);
if (params.hasAccount()) {
frame.disableForm();
frame.doLogin(params.getUser(), params.getPass());
}
logger.info("Launcher startup took " + (System.currentTimeMillis() - startupTime) + "ms");
}