read file associations from configuration
[instantlauncher.git] / src / main / java / eu / svjatoslav / instantlauncher / InstantLauncher.java
index b13b585..b21b2b3 100755 (executable)
@@ -1,23 +1,37 @@
 package eu.svjatoslav.instantlauncher;
 
-import java.io.FileNotFoundException;
+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 org.apache.log4j.Logger;
+import static eu.svjatoslav.instantlauncher.Utils.runOpeningApplication;
 
 public class InstantLauncher {
 
-    public Configuration configuration;
+    private static final Logger LOGGER = Logger.getLogger(InstantLauncher.class);
+    public ConfigurationManager configurationManager;
+    final MainFrame mainFrame;
 
-    FileAssociationManager associationManager = new FileAssociationManager();
+    public InstantLauncher() throws IOException {
+        configurationManager = new ConfigurationManager();
+        mainFrame = new MainFrame(this);
+    }
 
-    public static final Logger LOGGER = Logger.getLogger(InstantLauncher.class);
+    /**
+     * @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;
 
-    public void run() throws FileNotFoundException, IOException {
-        configuration = new Configuration();
+        final String[] commands = fileAssociation.getCommands();
+        runOpeningApplication(file, commands);
 
-        final MainFrame mainFrame = new MainFrame(this);
-        mainFrame.show();
+        return false;
     }
 
     public static void exitProgram() {
@@ -25,4 +39,8 @@ public class InstantLauncher {
         System.exit(0);
     }
 
+    public void run() throws IOException {
+        mainFrame.show();
+    }
+
 }