package eu.svjatoslav.instantlauncher;
+import eu.svjatoslav.commons.gui.dialog.ExceptionDialog;
import eu.svjatoslav.instantlauncher.configuration.ConfigurationManager;
import eu.svjatoslav.instantlauncher.configuration.FileAssociation;
-import org.apache.log4j.Logger;
import java.io.File;
import java.io.IOException;
public class InstantLauncher {
- private static final Logger LOGGER = Logger.getLogger(InstantLauncher.class);
+ private final MainFrame mainFrame;
public ConfigurationManager configurationManager;
- final MainFrame mainFrame;
public InstantLauncher() throws IOException {
configurationManager = new ConfigurationManager();
mainFrame = new MainFrame(this);
}
+ public static void exitProgram() {
+ System.exit(0);
+ }
+
/**
* @return <code>true</code> if file was opened. <code>false</code> if
* unknown file type.
FileAssociation fileAssociation = configurationManager.getConfiguration().findFileAssociation(file);
if (fileAssociation == null) return false;
- final String[] commands = fileAssociation.getCommands();
- runOpeningApplication(file, commands);
-
- return false;
+ runOpeningApplication(fileAssociation.command, file);
+ return true;
}
- public static void exitProgram() {
- LOGGER.info("Closing InstantLauncher");
- System.exit(0);
+ public void run() {
+ mainFrame.show();
}
- public void run() throws IOException {
- mainFrame.show();
+ public void openDirectory(File chosenFile) {
+ executeCommand(configurationManager.getConfiguration().directoryOpenCommand, chosenFile.getAbsolutePath());
}
+ public void executeCommand(String... c) {
+ try {
+ Runtime.getRuntime().exec(c);
+ exitProgram();
+
+ } catch (final IOException e) {
+ new ExceptionDialog(e);
+ }
+ }
}