3 import java.io.IOException;
5 import tim.prune.config.Config;
9 * Class to manage interfaces to external tools, like exiftool
11 public abstract class ExternalTools
13 /** Constant for Exiftool */
14 public static final int TOOL_EXIFTOOL = 0;
15 /** Constant for Gpsbabel */
16 public static final int TOOL_GPSBABEL = 1;
17 /** Constant for Gnuplot */
18 public static final int TOOL_GNUPLOT = 2;
19 /** Config keys in order that the tools are defined above */
20 private static final String[] CONFIG_KEYS = {Config.KEY_EXIFTOOL_PATH, Config.KEY_GPSBABEL_PATH, Config.KEY_GNUPLOT_PATH};
21 /** Verification flags for the tools in the order defined above */
22 private static final String[] VERIFY_FLAGS = {"-v", "-V", "-V"};
26 * Check if the selected tool is installed
27 * @param inToolNum number of tool, from constants
28 * @return true if selected tool is installed
30 public static boolean isToolInstalled(int inToolNum)
36 String toolPath = Config.getConfigString(CONFIG_KEYS[inToolNum]);
37 if (toolPath != null && toolPath.length() > 0) {
38 return check(toolPath + " " + VERIFY_FLAGS[inToolNum]);
46 * Check if the selected tool is installed using the given path
47 * @param inToolNum number of tool, from constants
48 * @param inPath selected path to use instead of configured one
49 * @return true if selected tool is installed
51 public static boolean isToolInstalled(int inToolNum, String inPath)
53 if (inPath == null || inPath.equals("")) {return false;}
58 return check(inPath + " " + VERIFY_FLAGS[inToolNum]);
65 * Attempt to call the specified command
66 * @return true if found, false otherwise
68 private static boolean check(String inCommand)
72 Runtime.getRuntime().exec(inCommand);
75 catch (IOException ioe)
77 // exception thrown, command not found