read file associations from configuration
[instantlauncher.git] / src / main / java / eu / svjatoslav / instantlauncher / InstantLauncher.java
1 package eu.svjatoslav.instantlauncher;
2
3 import eu.svjatoslav.instantlauncher.configuration.ConfigurationManager;
4 import eu.svjatoslav.instantlauncher.configuration.FileAssociation;
5 import org.apache.log4j.Logger;
6
7 import java.io.File;
8 import java.io.IOException;
9
10 import static eu.svjatoslav.instantlauncher.Utils.runOpeningApplication;
11
12 public class InstantLauncher {
13
14     private static final Logger LOGGER = Logger.getLogger(InstantLauncher.class);
15     public ConfigurationManager configurationManager;
16     final MainFrame mainFrame;
17
18     public InstantLauncher() throws IOException {
19         configurationManager = new ConfigurationManager();
20         mainFrame = new MainFrame(this);
21     }
22
23     /**
24      * @return <code>true</code> if file was opened. <code>false</code> if
25      * unknown file type.
26      */
27     public boolean openFile(final File file) {
28         FileAssociation fileAssociation = configurationManager.getConfiguration().findFileAssociation(file);
29         if (fileAssociation == null) return false;
30
31         final String[] commands = fileAssociation.getCommands();
32         runOpeningApplication(file, commands);
33
34         return false;
35     }
36
37     public static void exitProgram() {
38         LOGGER.info("Closing InstantLauncher");
39         System.exit(0);
40     }
41
42     public void run() throws IOException {
43         mainFrame.show();
44     }
45
46 }