From: Svjatoslav Agejenko Date: Sat, 9 Nov 2013 22:04:43 +0000 (+0200) Subject: Disabled terminal commandline option. X-Git-Tag: meviz-1.0~71 X-Git-Url: http://www2.svjatoslav.eu/gitweb/?a=commitdiff_plain;h=95ffc75c41af8f8f164e1d7dbf88291ae3749127;p=meviz.git Disabled terminal commandline option. Correctly handle aphostrophes in the encoded file names. --- diff --git a/src/main/java/eu/svjatoslav/meviz/encoder/CommandlineHandler.java b/src/main/java/eu/svjatoslav/meviz/encoder/CommandlineHandler.java index 870d476..b6e10ce 100755 --- a/src/main/java/eu/svjatoslav/meviz/encoder/CommandlineHandler.java +++ b/src/main/java/eu/svjatoslav/meviz/encoder/CommandlineHandler.java @@ -22,9 +22,6 @@ public class CommandlineHandler { .createStringParameter("Encoding output format.") .addAliases("-o", "--output-format").setMandatory(); - NullParameter terminalParameter = parser.createNullParameter( - "Enable popup terminal.").addAliases("--terminal"); - NullParameter deinterlaceParameter = parser.createNullParameter( "Deinterlace video.").addAliases("--deinterlace", "-d"); @@ -67,9 +64,6 @@ public class CommandlineHandler { if (deinterlaceParameter.isParameterSpecified()) options.deinterlace = true; - if (terminalParameter.isParameterSpecified()) - options.terminal = true; - if (testParameter.isParameterSpecified()) options.testOnly = true; diff --git a/src/main/java/eu/svjatoslav/meviz/encoder/Encoder.java b/src/main/java/eu/svjatoslav/meviz/encoder/Encoder.java index 420fa49..879c6da 100755 --- a/src/main/java/eu/svjatoslav/meviz/encoder/Encoder.java +++ b/src/main/java/eu/svjatoslav/meviz/encoder/Encoder.java @@ -91,8 +91,7 @@ public class Encoder implements Module { final EncodingTask encodingTask = new EncodingTask( sourceFile, targetFile, chosenFormat); - if (encodingOptions.terminal - || chosenFormat.isTerminalMandatory()) + if (chosenFormat.isTerminalMandatory()) encodingTask.setUseTerminal(true); encodingPlan.scheduleTask(encodingTask); } diff --git a/src/main/java/eu/svjatoslav/meviz/encoder/EncodingOptions.java b/src/main/java/eu/svjatoslav/meviz/encoder/EncodingOptions.java index 9f14546..463b48a 100755 --- a/src/main/java/eu/svjatoslav/meviz/encoder/EncodingOptions.java +++ b/src/main/java/eu/svjatoslav/meviz/encoder/EncodingOptions.java @@ -23,8 +23,6 @@ public class EncodingOptions { public boolean recursive; - public boolean terminal; - public boolean testOnly; public File workingDirectory = new File(System.getProperty("user.dir")); diff --git a/src/main/java/eu/svjatoslav/meviz/encoder/EncodingPlan.java b/src/main/java/eu/svjatoslav/meviz/encoder/EncodingPlan.java index f23fbdb..e4c75c3 100755 --- a/src/main/java/eu/svjatoslav/meviz/encoder/EncodingPlan.java +++ b/src/main/java/eu/svjatoslav/meviz/encoder/EncodingPlan.java @@ -14,37 +14,18 @@ import java.util.ArrayList; public class EncodingPlan { - public ArrayList encodingTasks = new ArrayList(); + public ArrayList encodingTasks = new ArrayList(); - public void execute(final EncodingOptions encodingOptions) throws IOException { - for (final EncodingTask task : encodingTasks) { + public void execute(final EncodingOptions encodingOptions) + throws IOException { - try { - String command = task.getCommand(encodingOptions); + for (final EncodingTask task : encodingTasks) + task.execute(encodingOptions); - if (task.doUseTerminal()) { - command = "xterm -e '" + command + "'"; - } + } - System.out.println("Executing command: " + command); - - final Runtime run = Runtime.getRuntime(); - Process pr; - pr = run.exec(new String[] { "/bin/bash", "-c", command }); - - pr.waitFor(); - - } catch (final Exception e) { - System.out.println(e.toString()); - e.printStackTrace(); - } - - } - - } - - public void scheduleTask(final EncodingTask encodingTask) { - encodingTasks.add(encodingTask); - }; + public void scheduleTask(final EncodingTask encodingTask) { + encodingTasks.add(encodingTask); + }; } diff --git a/src/main/java/eu/svjatoslav/meviz/encoder/EncodingTask.java b/src/main/java/eu/svjatoslav/meviz/encoder/EncodingTask.java index 9db5d92..54811c2 100755 --- a/src/main/java/eu/svjatoslav/meviz/encoder/EncodingTask.java +++ b/src/main/java/eu/svjatoslav/meviz/encoder/EncodingTask.java @@ -15,45 +15,81 @@ import eu.svjatoslav.meviz.encoder.converters.Converter; public class EncodingTask { - /** - * Source file to encode - */ - private final File source; - - /** - * Target file. - */ - private final File target; - - private final Converter converter; - - private boolean useTerminal; - - public EncodingTask(final File source, final File destination, - final eu.svjatoslav.meviz.encoder.converters.Converter converter) { - - this.source = source; - target = destination; - this.converter = converter; - - } - - /** - * @return the useTerminal - */ - public boolean doUseTerminal() { - return useTerminal; - } - - public String getCommand(final EncodingOptions encodingOptions) { - return converter.getCommand(source, target, encodingOptions); - } - - /** - * @param useTerminal - * the useTerminal to set - */ - public void setUseTerminal(final boolean useTerminal) { - this.useTerminal = useTerminal; - } + /** + * Source file to encode + */ + private final File source; + + /** + * Target file. + */ + private final File target; + + private final Converter converter; + + private boolean useTerminal; + + public EncodingTask(final File source, final File destination, + final eu.svjatoslav.meviz.encoder.converters.Converter converter) { + + this.source = source; + target = destination; + this.converter = converter; + + } + + /** + * @return the useTerminal + */ + public boolean doUseTerminal() { + return useTerminal; + } + + public String encodeApostrophes(final String input) { + final StringBuffer result = new StringBuffer(); + + for (final char c : input.toCharArray()) { + if (c == '\'') { + result.append("'\\''"); + continue; + } + result.append(c); + } + + return result.toString(); + } + + public void execute(final EncodingOptions encodingOptions) { + try { + String command = getCommand(encodingOptions); + + if (doUseTerminal()) + command = "xterm -e '" + encodeApostrophes(command) + "'"; + + System.out.println("Executing command: " + command); + + final Runtime run = Runtime.getRuntime(); + Process pr; + pr = run.exec(new String[] { "/bin/bash", "-c", command }); + + pr.waitFor(); + + } catch (final Exception e) { + System.out.println(e.toString()); + e.printStackTrace(); + } + + } + + public String getCommand(final EncodingOptions encodingOptions) { + return converter.getCommand(source, target, encodingOptions); + } + + /** + * @param useTerminal + * the useTerminal to set + */ + public void setUseTerminal(final boolean useTerminal) { + this.useTerminal = useTerminal; + } }