diff --git a/source/net/filebot/HistorySpooler.java b/source/net/filebot/HistorySpooler.java index 2da960cb..32252fa6 100644 --- a/source/net/filebot/HistorySpooler.java +++ b/source/net/filebot/HistorySpooler.java @@ -97,7 +97,12 @@ public final class HistorySpooler { List sequence = new ArrayList(); for (Entry element : elements) { - sequence.add(new Element(element.getKey().getName(), element.getValue().getPath(), element.getKey().getParentFile())); + File k = element.getKey(); + File v = element.getValue(); + + if (k != null && v != null) { + sequence.add(new Element(k.getName(), v.getPath(), k.getParentFile())); + } } if (sequence.size() > 0) { diff --git a/source/net/filebot/cli/ArgumentBean.java b/source/net/filebot/cli/ArgumentBean.java index 6a50f702..8e5077bc 100644 --- a/source/net/filebot/cli/ArgumentBean.java +++ b/source/net/filebot/cli/ArgumentBean.java @@ -28,6 +28,7 @@ import org.kohsuke.args4j.spi.ExplicitBooleanOptionHandler; import net.filebot.ApplicationFolder; import net.filebot.Language; +import net.filebot.RenameAction; import net.filebot.StandardRenameAction; import net.filebot.WebServices; import net.filebot.format.ExpressionFileFilter; @@ -201,7 +202,7 @@ public class ArgumentBean { return files; } - public StandardRenameAction getRenameAction() { + public RenameAction getRenameAction() { return StandardRenameAction.forName(action); } diff --git a/source/net/filebot/cli/GroovyRenameAction.java b/source/net/filebot/cli/GroovyRenameAction.java new file mode 100644 index 00000000..63229755 --- /dev/null +++ b/source/net/filebot/cli/GroovyRenameAction.java @@ -0,0 +1,34 @@ +package net.filebot.cli; + +import java.io.File; + +import groovy.lang.Closure; +import net.filebot.RenameAction; + +public class GroovyRenameAction implements RenameAction { + + private final Closure closure; + + public GroovyRenameAction(Closure closure) { + this.closure = closure; + } + + @Override + public File rename(File from, File to) throws Exception { + Object value = closure.call(from, to); + + // must return File object, so we try the result of the closure, but if it's not a File we just return the original destination parameter + return value instanceof File ? (File) value : null; + } + + @Override + public boolean canRevert() { + return false; + } + + @Override + public String toString() { + return "CLOSURE"; + } + +} diff --git a/source/net/filebot/cli/ProcessRenameAction.java b/source/net/filebot/cli/ProcessRenameAction.java new file mode 100644 index 00000000..b13c3708 --- /dev/null +++ b/source/net/filebot/cli/ProcessRenameAction.java @@ -0,0 +1,38 @@ +package net.filebot.cli; + +import static net.filebot.Logging.*; + +import java.io.File; + +import net.filebot.RenameAction; + +public class ProcessRenameAction implements RenameAction { + + private final String executable; + + public ProcessRenameAction(String executable) { + this.executable = executable; + } + + @Override + public File rename(File from, File to) throws Exception { + Process process = new ProcessBuilder(executable, from.getPath(), to.getPath()).inheritIO().start(); + + if (process.waitFor() != 0) { + debug.severe(format("[%s] failed with exit code %d", executable, process.exitValue())); + } + + return null; + } + + @Override + public boolean canRevert() { + return false; + } + + @Override + public String toString() { + return executable; + } + +} diff --git a/source/net/filebot/cli/ScriptShellBaseClass.java b/source/net/filebot/cli/ScriptShellBaseClass.java index 1ec61fcd..aab9f15f 100644 --- a/source/net/filebot/cli/ScriptShellBaseClass.java +++ b/source/net/filebot/cli/ScriptShellBaseClass.java @@ -513,29 +513,8 @@ public abstract class ScriptShellBaseClass extends Script { return StandardRenameAction.forName(obj.toString()); } - if (obj instanceof Closure) { - return new RenameAction() { - - private final Closure closure = (Closure) obj; - - @Override - public File rename(File from, File to) throws Exception { - Object value = closure.call(from, to); - - // must return File object, so we try the result of the closure, but if it's not a File we just return the original destination parameter - return new File(value.toString()); - } - - @Override - public boolean canRevert() { - return false; - } - - @Override - public String toString() { - return "CLOSURE"; - } - }; + if (obj instanceof Closure) { + return new GroovyRenameAction((Closure) obj); } // object probably can't be casted