Added license and copyright notice.
[instantlauncher.git] / src / main / java / eu / svjatoslav / instantlauncher / InstantLauncher.java
1 /*
2  * Instantlauncher. Copyright ©2012-2019, Svjatoslav Agejenko, svjatoslav@svjatoslav.eu
3  *
4  * This program is free software; you can redistribute it and/or
5  * modify it under the terms of version 3 of the GNU Lesser General Public License
6  * or later as published by the Free Software Foundation.
7  */
8
9 package eu.svjatoslav.instantlauncher;
10
11 import eu.svjatoslav.instantlauncher.configuration.ConfigurationManager;
12 import eu.svjatoslav.instantlauncher.configuration.FileAssociation;
13
14 import java.io.File;
15 import java.io.IOException;
16
17 import static eu.svjatoslav.instantlauncher.Utils.runOpeningApplication;
18
19 public class InstantLauncher {
20
21     private final MainFrame mainFrame;
22     public ConfigurationManager configurationManager;
23
24     public InstantLauncher() throws IOException {
25         configurationManager = new ConfigurationManager();
26         mainFrame = new MainFrame(this);
27     }
28
29     public static void exitProgram() {
30         System.exit(0);
31     }
32
33     /**
34      * @return <code>true</code> if file was opened. <code>false</code> if
35      * unknown file type.
36      */
37     public boolean openFile(final File file) {
38         FileAssociation fileAssociation = configurationManager.getConfiguration().findFileAssociation(file);
39         if (fileAssociation == null) return false;
40
41         runOpeningApplication(fileAssociation.command, file);
42         return true;
43     }
44
45     public void run() {
46         mainFrame.show();
47     }
48
49     public void openDirectory(File chosenFile) {
50         runOpeningApplication(configurationManager.getConfiguration().directoryOpenCommand, chosenFile);
51     }
52
53     public void openDirectoryInTerminal(File chosenFile) {
54         runOpeningApplication(configurationManager.getConfiguration().directoryTerminalOpenCommand, chosenFile);
55     }
56
57 }