From: Svjatoslav Agejenko Date: Mon, 12 May 2014 18:17:02 +0000 (+0300) Subject: better handling of log files X-Git-Url: http://www2.svjatoslav.eu/gitweb/?a=commitdiff_plain;h=36efc98a2d41ce4c615d10b9fd9b26a143dcda3f;p=instantlauncher.git better handling of log files --- diff --git a/src/main/java/eu/svjatoslav/instantlauncher/FileAssociationManager.java b/src/main/java/eu/svjatoslav/instantlauncher/FileAssociationManager.java index 88545f2..6ad5713 100755 --- a/src/main/java/eu/svjatoslav/instantlauncher/FileAssociationManager.java +++ b/src/main/java/eu/svjatoslav/instantlauncher/FileAssociationManager.java @@ -20,36 +20,49 @@ public class FileAssociationManager { public static HashMap extensionToApplication = new HashMap(); + /** + * @return true if file was opened. false if unknown file type. + */ public static boolean openFile(final File file) { + if (isLogFile(file.getName())){ + runOpeningApplication(file, new String[] { "glogg", FILE_INDICATOR }); + return true; + } + final String fileExtension = Utils.getFileExtension(file); - System.out.println("About to open file with extension: " + fileExtension); - if (extensionToApplication.containsKey(fileExtension)) { - - System.out.println("Commands found"); - final String[] commands = extensionToApplication.get(fileExtension); - - 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); - } - + runOpeningApplication(file, commands); return true; } else return false; } + private 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); + } + } + + private static boolean isLogFile(String fileName) { + if (fileName.endsWith(".out")) return true; + if (fileName.endsWith(".log")) return true; + if (fileName.contains(".log.")) return true; + + return false; + } + public FileAssociationManager() { extensionToApplication.put("txt", new String[] { TEXT_EDITOR, FILE_INDICATOR });