read file associations from configuration
[instantlauncher.git] / src / main / java / eu / svjatoslav / instantlauncher / Utils.java
index c5d7641..1884fec 100755 (executable)
@@ -1,8 +1,13 @@
 package eu.svjatoslav.instantlauncher;
 
+import eu.svjatoslav.commons.gui.dialog.ExceptionDialog;
+
 import javax.swing.*;
 import java.awt.*;
 import java.io.File;
+import java.io.IOException;
+
+import static eu.svjatoslav.commons.file.FilePathParser.getFileExtension;
 
 public class Utils {
 
@@ -11,7 +16,22 @@ public class Utils {
         component.setMaximumSize(size);
         component.setSize(size);
         component.setPreferredSize(size);
+    }
+
+    private static final String FILE_INDICATOR = "{file}";
+
+    public static void runOpeningApplication(final File file, final String[] commands) {
+        for (int i = 0; i < commands.length; i++)
+            if (commands[i].equals(FILE_INDICATOR))
+                commands[i] = file.getAbsolutePath();
+
+        try {
+            Runtime.getRuntime().exec(commands);
+            InstantLauncher.exitProgram();
 
+        } catch (final IOException e) {
+            new ExceptionDialog(e);
+        }
     }
 
 }