This commit is contained in:
ErdbeerbaerLP 2019-03-27 18:27:53 +01:00
parent dbf404cd88
commit 0a7af5411a

View File

@ -22,9 +22,11 @@
package de.mas.wiiu.streaming;
import java.awt.GraphicsEnvironment;
import java.net.BindException;
import java.net.SocketException;
import javax.swing.JFrame;
import javax.swing.JOptionPane;
import javax.swing.SwingUtilities;
@ -38,38 +40,70 @@ import de.mas.wiiu.streaming.gui.StreamWindow;
public class Main {
public static void main(String[] args) throws Exception {
CommandLineParser parser = new DefaultParser();
public static void main(String[] args) throws Exception {
CommandLineParser parser = new DefaultParser();
Options options = new Options();
options.addOption("ip", "ip", true, "IP address of your Wii U Console.");
Options options = new Options();
options.addOption("ip", "ip", true, "IP address of your Wii U Console.");
CommandLine line = parser.parse(options, args);
String ip = null;
CommandLine line = parser.parse(options, args);
String ip = null;
if (line.hasOption("ip")) {
ip = line.getOptionValue("ip");
} else {
HelpFormatter formatter = new HelpFormatter();
formatter.printHelp("streamingTool", options);
ip = JOptionPane.showInputDialog(null, "Please enter the local IP address of your Wii U", "Wii U streaming client", JOptionPane.PLAIN_MESSAGE);
}
try {
new Main(ip);
} catch (BindException e) {
JOptionPane.showMessageDialog(null, "Can't bind socket. The client is probably already running.", e.getClass().getName(),
JOptionPane.WARNING_MESSAGE);
System.exit(-1);
}
}
if (line.hasOption("ip")) {
ip = line.getOptionValue("ip");
} else {
//Check if this is being run in cmd to prevent headless exceptions
if(GraphicsEnvironment.isHeadless()) {
HelpFormatter formatter = new HelpFormatter();
formatter.printHelp("streamingTool", options);
}else {
public Main(String ip) throws SocketException {
ImageStreamer imageStreamer = new ImageStreamer(ip);
//Create a JFrame to show the icon in the taskbar
final JFrame frame = new JFrame("Wii U Streaming Client - Enter IP...");
frame.setUndecorated( true );
frame.setVisible( true );
frame.setLocationRelativeTo( null );
SwingUtilities.invokeLater(new Runnable() {
public void run() {
new StreamWindow(imageStreamer.getImageProvider());
}
});
}
//Display the IP Dialog
ip = JOptionPane.showInputDialog(frame, "Please enter the local IP address of your Wii U", "Wii U streaming client", JOptionPane.PLAIN_MESSAGE);
//Check if user clicked "Cancel"
if(ip == null) {
System.out.println("Cancelled. Exiting program");
frame.dispose();
System.exit(0);
}
//Close the JFrame again
frame.dispose();
}
}
try {
new Main(ip);
} catch (BindException e) {
//Create a JFrame to show the icon in the taskbar
final JFrame frame = new JFrame("Wii U Streaming Client - "+e.getClass().getName());
frame.setUndecorated( true );
frame.setVisible( true );
frame.setLocationRelativeTo( null );
//Display the Message
JOptionPane.showMessageDialog(frame, "Can't bind socket. The client is probably already running.", e.getClass().getName(),
JOptionPane.WARNING_MESSAGE);
//Close the JFrame again
frame.dispose();
System.exit(-1);
}
}
public Main(String ip) throws SocketException {
ImageStreamer imageStreamer = new ImageStreamer(ip);
SwingUtilities.invokeLater(new Runnable() {
public void run() {
new StreamWindow(imageStreamer.getImageProvider());
}
});
}
}