X-Git-Url: https://gitweb.fperrin.net/?a=blobdiff_plain;f=tim%2Fprune%2FExternalTools.java;h=8cd1aef178f44c80674af5923a7a4937ec9e4466;hb=326f489e36aa7f235bc19409a57bf4955cd50f24;hp=22291fb122968331a6f1a52b28d4f9fc56782cb7;hpb=54b9d8bc8f0025ccf97a67d9dd217ef1f9cf082f;p=GpsPrune.git diff --git a/tim/prune/ExternalTools.java b/tim/prune/ExternalTools.java index 22291fb..8cd1aef 100644 --- a/tim/prune/ExternalTools.java +++ b/tim/prune/ExternalTools.java @@ -2,48 +2,74 @@ package tim.prune; import java.io.IOException; +import tim.prune.config.Config; + /** * Class to manage interfaces to external tools, like exiftool */ public abstract class ExternalTools { - - /** - * Attempt to call Povray to see if it's installed / available in path - * @return true if found, false otherwise - */ - public static boolean isPovrayInstalled() - { - return check("povray"); - } + /** Constant for Exiftool */ + public static final int TOOL_EXIFTOOL = 0; + /** Constant for Gpsbabel */ + public static final int TOOL_GPSBABEL = 1; + /** Constant for Gnuplot */ + public static final int TOOL_GNUPLOT = 2; + /** Constant for Xerces xml library */ + public static final int TOOL_XERCES = 3; + /** Config keys in order that the tools are defined above */ + private static final String[] CONFIG_KEYS = {Config.KEY_EXIFTOOL_PATH, Config.KEY_GPSBABEL_PATH, Config.KEY_GNUPLOT_PATH}; + /** Verification flags for the tools in the order defined above */ + private static final String[] VERIFY_FLAGS = {"-v", "-V", "-V"}; /** - * Attempt to call Exiftool to see if it's installed / available in path - * @return true if found, false otherwise + * Check if the selected tool is installed + * @param inToolNum number of tool, from constants + * @return true if selected tool is installed */ - public static boolean isExiftoolInstalled() + public static boolean isToolInstalled(int inToolNum) { - return check("exiftool -v"); - } - - /** - * Attempt to call gpsbabel to see if it's installed / available in path - * @return true if found, false otherwise - */ - public static boolean isGpsbabelInstalled() - { - return check("gpsbabel -V"); + switch (inToolNum) { + case TOOL_EXIFTOOL: + case TOOL_GPSBABEL: + case TOOL_GNUPLOT: + String toolPath = Config.getConfigString(CONFIG_KEYS[inToolNum]); + if (toolPath != null && toolPath.length() > 0) { + return check(toolPath + " " + VERIFY_FLAGS[inToolNum]); + } + break; + case TOOL_XERCES: + try { + return Class.forName("org.apache.xerces.parsers.SAXParser").getClassLoader() != null; + } + catch (ClassNotFoundException e) { + // System.err.println(e.getClass().getName() + " : " + e.getMessage()); + } + break; + } + // Not found + return false; } /** - * Attempt to call gnuplot to see if it's installed / available in path - * @return true if found, false otherwise + * Check if the selected tool is installed using the given path + * @param inToolNum number of tool, from constants + * @param inPath selected path to use instead of configured one + * @return true if selected tool is installed */ - public static boolean isGnuplotInstalled() + public static boolean isToolInstalled(int inToolNum, String inPath) { - return check(Config.getGnuplotPath() + " -V"); + if (inPath == null || inPath.equals("")) {return false;} + switch (inToolNum) { + case TOOL_EXIFTOOL: + case TOOL_GPSBABEL: + case TOOL_GNUPLOT: + return check(inPath + " " + VERIFY_FLAGS[inToolNum]); + } + // Not found + return false; } /**