2008-03-19 22:14:38 +00:00
|
|
|
import java.util.ArrayList;
|
|
|
|
import java.util.HashSet;
|
|
|
|
import java.util.LinkedHashMap;
|
|
|
|
import java.util.List;
|
|
|
|
import java.util.Map;
|
|
|
|
import java.util.Set;
|
2008-02-13 20:08:06 +00:00
|
|
|
import java.util.logging.Level;
|
|
|
|
import java.util.logging.Logger;
|
2008-03-19 22:14:38 +00:00
|
|
|
import java.util.regex.Matcher;
|
|
|
|
import java.util.regex.Pattern;
|
2008-02-13 20:08:06 +00:00
|
|
|
|
2007-12-23 19:28:04 +00:00
|
|
|
import javax.swing.SwingUtilities;
|
|
|
|
import javax.swing.UIManager;
|
|
|
|
|
2008-03-19 22:14:38 +00:00
|
|
|
import net.sourceforge.filebot.Settings;
|
2007-12-23 19:28:04 +00:00
|
|
|
import net.sourceforge.filebot.ui.FileBotWindow;
|
2008-03-19 22:14:38 +00:00
|
|
|
import net.sourceforge.tuned.MessageBus;
|
2007-12-23 19:28:04 +00:00
|
|
|
|
|
|
|
|
|
|
|
public class Main {
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param args
|
|
|
|
*/
|
2008-06-21 19:24:18 +00:00
|
|
|
public static void main(String... args) {
|
2008-02-13 20:08:06 +00:00
|
|
|
|
2008-03-19 22:14:38 +00:00
|
|
|
final Arguments arguments = new Arguments(args);
|
|
|
|
|
|
|
|
if (arguments.containsParameter("clear")) {
|
|
|
|
Settings.getSettings().clear();
|
|
|
|
}
|
|
|
|
|
2007-12-23 19:28:04 +00:00
|
|
|
try {
|
|
|
|
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
|
|
|
|
} catch (Exception e) {
|
2008-03-16 01:05:06 +00:00
|
|
|
Logger.getLogger(Logger.GLOBAL_LOGGER_NAME).log(Level.SEVERE, e.toString(), e);
|
2007-12-23 19:28:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
SwingUtilities.invokeLater(new Runnable() {
|
|
|
|
|
2008-03-19 22:14:38 +00:00
|
|
|
@Override
|
2007-12-23 19:28:04 +00:00
|
|
|
public void run() {
|
2008-06-21 19:24:18 +00:00
|
|
|
FileBotWindow window = new FileBotWindow();
|
|
|
|
|
|
|
|
// publish messages from arguments to the newly created components
|
|
|
|
arguments.publishMessages();
|
|
|
|
|
|
|
|
// start
|
2008-03-19 22:14:38 +00:00
|
|
|
window.setVisible(true);
|
2007-12-23 19:28:04 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
2008-03-19 22:14:38 +00:00
|
|
|
|
|
|
|
|
|
|
|
private static class Arguments {
|
|
|
|
|
|
|
|
private final Set<String> parameters = new HashSet<String>(3);
|
|
|
|
private final Map<String, List<String>> messages = new LinkedHashMap<String, List<String>>();
|
|
|
|
|
|
|
|
|
|
|
|
public Arguments(String[] args) {
|
|
|
|
Pattern topicPattern = Pattern.compile("--(\\w+)");
|
|
|
|
|
|
|
|
String currentTopic = null;
|
|
|
|
|
|
|
|
for (String arg : args) {
|
|
|
|
Matcher m = topicPattern.matcher(arg);
|
|
|
|
|
|
|
|
if (m.matches()) {
|
|
|
|
currentTopic = m.group(1).toLowerCase();
|
|
|
|
messages.put(currentTopic, new ArrayList<String>(1));
|
|
|
|
} else if (currentTopic != null) {
|
|
|
|
messages.get(currentTopic).add(arg);
|
|
|
|
} else {
|
|
|
|
parameters.add(arg.toLowerCase());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public boolean containsParameter(String argument) {
|
|
|
|
return parameters.contains(argument);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public void publishMessages() {
|
|
|
|
for (String topic : messages.keySet()) {
|
|
|
|
MessageBus.getDefault().publish(topic, messages.get(topic).toArray(new String[0]));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-12-23 19:28:04 +00:00
|
|
|
}
|