read file associations from configuration
[instantlauncher.git] / src / main / java / eu / svjatoslav / instantlauncher / InstantLauncher.java
index a0ff09e..b21b2b3 100755 (executable)
@@ -1,15 +1,38 @@
 package eu.svjatoslav.instantlauncher;
 
 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;
 
+import static eu.svjatoslav.instantlauncher.Utils.runOpeningApplication;
+
 public class InstantLauncher {
 
     private static final Logger LOGGER = Logger.getLogger(InstantLauncher.class);
-    public ConfigurationManager configuration;
-    FileAssociationManager associationManager = new FileAssociationManager();
+    public ConfigurationManager configurationManager;
+    final MainFrame mainFrame;
+
+    public InstantLauncher() throws IOException {
+        configurationManager = new ConfigurationManager();
+        mainFrame = new MainFrame(this);
+    }
+
+    /**
+     * @return <code>true</code> if file was opened. <code>false</code> if
+     * unknown file type.
+     */
+    public boolean openFile(final File file) {
+        FileAssociation fileAssociation = configurationManager.getConfiguration().findFileAssociation(file);
+        if (fileAssociation == null) return false;
+
+        final String[] commands = fileAssociation.getCommands();
+        runOpeningApplication(file, commands);
+
+        return false;
+    }
 
     public static void exitProgram() {
         LOGGER.info("Closing InstantLauncher");
@@ -17,9 +40,6 @@ public class InstantLauncher {
     }
 
     public void run() throws IOException {
-        configuration = new ConfigurationManager();
-
-        final MainFrame mainFrame = new MainFrame(this);
         mainFrame.show();
     }