Search in sources :

Example 1 with UIApplication

use of jgnash.ui.UIApplication in project jgnash by ccavanaugh.

the class Main method init.

private void init(final String[] args) {
    configureLogging();
    final OptionParser parser = buildParser();
    try {
        final OptionSet options = parser.parse(args);
        /* handle a file name passed in as an argument without use of the -file argument
               assumed behavior for windows users */
        if (!options.nonOptionArguments().isEmpty()) {
            // Check for no-option version of a file load
            for (final Object object : options.nonOptionArguments()) {
                if (object instanceof String) {
                    if (Files.exists(Paths.get((String) object))) {
                        file = new File((String) object);
                        break;
                    } else {
                        System.err.println(object + " was not a valid file");
                    }
                }
            }
        }
        if (options.has(EDT_OPTION)) {
            enableEDT = true;
        }
        if (options.has(VERBOSE_OPTION_SHORT)) {
            verbose = true;
        }
        if (options.has(HANG_DETECT_OPTION)) {
            hangDetect = true;
        }
        if (options.has(PORT_OPTION)) {
            port = (Integer) options.valueOf(PORT_OPTION);
        }
        if (options.has(PASSWORD_OPTION)) {
            password = ((String) options.valueOf(PASSWORD_OPTION)).toCharArray();
        }
        if (options.has(HOST_OPTION)) {
            hostName = (String) options.valueOf(HOST_OPTION);
        }
        if (options.has(FILE_OPTION_SHORT) && file == null) {
            file = (File) options.valueOf(FILE_OPTION_SHORT);
            if (!file.exists()) {
                file = null;
            }
        }
        if (options.has(SERVER_OPTION)) {
            final File file = (File) options.valueOf(SERVER_OPTION);
            if (file.exists()) {
                serverFile = file;
            }
        }
        // Check to see if portable preferences are being used
        if (options.has(PORTABLE_FILE_OPTION)) {
            final File file = (File) options.valueOf(PORTABLE_FILE_OPTION);
            if (file.exists()) {
                portableFile = file;
            }
        } else if (options.has(PORTABLE_OPTION_SHORT)) {
            // simple use of portable preferences
            portable = true;
        }
        /* If a shutdown request is found, it trumps any other commandline options */
        if (options.has(SHUTDOWN_OPTION)) {
            if (hostName == null) {
                hostName = EngineFactory.LOCALHOST;
            }
            MessageBus.getInstance().shutDownRemoteServer(hostName, port + 1, password);
        } else if (options.has(UNINSTALL_OPTION_SHORT)) {
            /* Dump the registry settings if requested */
            PortablePreferences.deleteUserPreferences();
        } else if (serverFile != null) {
            try {
                if (!FileUtils.isFileLocked(serverFile.getAbsolutePath())) {
                    JpaNetworkServer networkServer = new JpaNetworkServer();
                    networkServer.startServer(serverFile.getAbsolutePath(), port, password);
                } else {
                    System.err.println(ResourceUtils.getString("Message.FileIsLocked"));
                }
            } catch (FileNotFoundException e) {
                logSevere(Main.class, e);
                System.err.println("File " + serverFile.getAbsolutePath() + " was not found");
            } catch (Exception e) {
                logSevere(Main.class, e);
            }
        } else {
            // start the UI
            if (portable || portableFile != null) {
                // must hook in the preferences implementation first
                // for best operation
                PortablePreferences.initPortablePreferences(portableFile.getAbsolutePath());
            }
            enableAntialiasing();
            if (options.has(OPEN_GL_OPTION)) {
                System.setProperty("sun.java2d.opengl", "True");
            }
            if (options.has(XRENDER_OPTION)) {
                System.setProperty("sun.java2d.xrender", "True");
            }
            if (OS.isSystemOSX()) {
                System.setProperty("apple.laf.useScreenMenuBar", "true");
            }
            setupNetworking();
            if (hostName != null) {
                new UIApplication(hostName, port, password);
            } else if (file != null && file.exists()) {
                new UIApplication(file.toPath(), password);
            } else {
                new UIApplication(null, null);
            }
        }
    } catch (final Exception e) {
        try {
            parser.printHelpOn(System.err);
        } catch (final IOException ioe) {
            logSevere(Main.class, ioe);
        }
    }
}
Also used : FileNotFoundException(java.io.FileNotFoundException) JpaNetworkServer(jgnash.engine.jpa.JpaNetworkServer) UIApplication(jgnash.ui.UIApplication) IOException(java.io.IOException) OptionSet(joptsimple.OptionSet) OptionParser(joptsimple.OptionParser) File(java.io.File) IOException(java.io.IOException) FileNotFoundException(java.io.FileNotFoundException)

Aggregations

File (java.io.File)1 FileNotFoundException (java.io.FileNotFoundException)1 IOException (java.io.IOException)1 JpaNetworkServer (jgnash.engine.jpa.JpaNetworkServer)1 UIApplication (jgnash.ui.UIApplication)1 OptionParser (joptsimple.OptionParser)1 OptionSet (joptsimple.OptionSet)1