Changed license to CC0
[instantlauncher.git] / src / main / java / eu / svjatoslav / instantlauncher / InstantLauncher.java
1 /*
2  * Instantlauncher. Author: Svjatoslav Agejenko, svjatoslav@svjatoslav.eu
3  * This project is released under Creative Commons Zero (CC0) license.
4  */
5 package eu.svjatoslav.instantlauncher;
6
7 import eu.svjatoslav.instantlauncher.configuration.ConfigurationManager;
8 import eu.svjatoslav.instantlauncher.configuration.FileAssociation;
9
10 import java.io.File;
11 import java.io.IOException;
12
13 import static eu.svjatoslav.instantlauncher.Utils.runOpeningApplication;
14
15 public class InstantLauncher {
16
17     private final MainFrame mainFrame;
18     public ConfigurationManager configurationManager;
19
20     public InstantLauncher() throws IOException {
21         configurationManager = new ConfigurationManager();
22         mainFrame = new MainFrame(this);
23     }
24
25     public static void exitProgram() {
26         System.exit(0);
27     }
28
29     /**
30      * @return <code>true</code> if file was opened. <code>false</code> if
31      * unknown file type.
32      */
33     public boolean openFile(final File file) {
34         FileAssociation fileAssociation = configurationManager.getConfiguration().findFileAssociation(file);
35         if (fileAssociation == null) return false;
36
37         runOpeningApplication(fileAssociation.command, file);
38         return true;
39     }
40
41     public void run() {
42         mainFrame.show();
43     }
44
45     public void openDirectory(File chosenFile) {
46         runOpeningApplication(configurationManager.getConfiguration().directoryOpenCommand, chosenFile);
47     }
48
49     public void openDirectoryInTerminal(File chosenFile) {
50         runOpeningApplication(configurationManager.getConfiguration().directoryTerminalOpenCommand, chosenFile);
51     }
52
53 }