PreferenceLoader.getPreferenceStore().setValue( "running", false ); PreferenceLoader.saveStore();
    public static void launch( String[] args ) {        if ( containsLink( args ) ) {            /*these two fields are only for easier if ( boolean )*/            notProcessingLink = false;            processingLink = true;        }        waiterObject = new Object();        if ( notProcessingLink ) {            myPrefs = new Preferences( preferenceStore );            /* load the preferences */            try {                myPrefs.initialize( preferenceStore );            }            catch ( IOException e ) {                System.out.println( "failed" );            }            shell = new Shell( display );            splashShell = new Shell( shell, SWT.ON_TOP );            box = new MessageBox( shell, SWT.ICON_ERROR | SWT.YES | SWT.NO );            progressBar = new ProgressBar( splashShell, SWT.NONE );            count = new int[] { 3 };            /* build the splash */            progressBar.setMaximum( count[ 0 ] );            label = new Label( splashShell, SWT.NONE );            label.setImage( G2GuiResources.getImage( "splashScreen" ) );            FormLayout layout = new FormLayout();            splashShell.setLayout( layout );            formData = new FormData();            formData.left = new FormAttachment( 0, 5 );            formData.right = new FormAttachment( 100, -5 );            formData.bottom = new FormAttachment( 100, -5 );            progressBar.setLayoutData( formData );            splashShell.pack();            shellRect = splashShell.getBounds();            displayRect = display.getBounds();            int x = ( displayRect.width - shellRect.width ) / 2;            int y = ( displayRect.height - shellRect.height ) / 2;            splashShell.setLocation( x, y );            splashShell.open();            spawnCore();            increaseBar( "Starting the model" );        }        /* if the gui isnt set up yet launch the preference window */        if ( !( preferenceStore.getBoolean( "initialized" ) ) && notProcessingLink ) {            preferenceStore.setValue( "initialized", true );            splashShell.setVisible( false );            myPrefs.open( shell, null );            // crashes if you call myPrefs.open again             // if you don't create a new Preferenes() - Why?            // a jface.Wizard would be better            // temporary hack            myPrefs = new Preferences( preferenceStore );            splashShell.setVisible( true );        }        port = preferenceStore.getInt( "port" );        hostname = preferenceStore.getString( "hostname" );        username = preferenceStore.getString( "username" );        password = preferenceStore.getString( "password" );        advancedMode = preferenceStore.getBoolean( "advancedMode" );        if ( processingLink )            advancedMode = false;        /* create the socket connection to the core */        socket = null;        try {            socketPool = new SocketPool( hostname, port );            socket = ( Socket ) socketPool.checkOut();        }        catch ( UnknownHostException e ) {            if ( notProcessingLink ) {                splashShell.dispose();                box.setText( G2GuiResources.getString( "G2_INVALID_ADDRESS" ) );                box.setMessage( G2GuiResources.getString( "G2_ILLEGAL_ADDRESS" ) );                int rc = box.open();                if ( rc == SWT.NO ) {                    shell.dispose();                    display.dispose();                }                else {                    myPrefs.open( shell, null );                    relaunchSelf( args );                }            }            else {                myPrefs = new Preferences( preferenceStore );                shell = new Shell();                myPrefs.open( shell, null );                relaunchSelf( args );            }            return;        }        catch ( IOException e ) {            if ( notProcessingLink ) {                splashShell.dispose();                box.setText( G2GuiResources.getString( "G2_IOEXCEPTION" ) );                box.setMessage( G2GuiResources.getString( "G2_CORE_NOT_RUNNING" ) );                int rc = box.open();                if ( rc == SWT.NO ) {                    shell.dispose();                    display.dispose();                }                else {                    myPrefs.open( shell, null );                    relaunchSelf( args );                }            }            else {                myPrefs = new Preferences( preferenceStore );                shell = new Shell();                myPrefs.open( shell, null );                relaunchSelf( args );            }            return;        }        /* launch the model */        PreferenceLoader.saveStore();        boolean pollMode = processingLink;        /* wait as long as the core tells us to continue */        synchronized ( waiterObject ) {            core = new Core( socket, username, password, waiterObject, pollMode, advancedMode );            core.connect();            mldonkey = new Thread( core );            mldonkey.setDaemon( true );            mldonkey.start();            try {                waiterObject.wait();            }            catch ( InterruptedException e1 ) {            }        }        /* did the core receive "bad password" */        if ( core.getConnectionDenied() ) {            if ( notProcessingLink )                connectDeniedHandling();        }        else if ( core.getBadPassword() ) {            core.disconnect();            if ( notProcessingLink )                badPasswordHandling( args );        }        else {            if ( notProcessingLink ) {                increaseBar( "Starting the view" );                MainTab g2gui = new MainTab( core, shell );            }            else                sendDownloadLink( args );        }        core.disconnect();    }