From cf48247601f3ec07aab8ea3e929f1ff6aec07e7e Mon Sep 17 00:00:00 2001 From: Reinhard Pointner Date: Fri, 14 Jun 2019 02:23:55 +0700 Subject: [PATCH] Added `-no-history` and `-clear-history` CLI options --- CHANGES.md | 2 +- source/net/filebot/HistorySpooler.java | 10 ++++++++++ source/net/filebot/Main.java | 8 +++++++- source/net/filebot/cli/ArgumentBean.java | 7 +++++++ 4 files changed, 25 insertions(+), 2 deletions(-) diff --git a/CHANGES.md b/CHANGES.md index 3e55cd6e..ad046e6b 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -8,7 +8,7 @@ Next Release (4.8.6) * Evaluate `{closures}` automatically in `String.plus(Closure)` constructs (e.g. `{"[" + {n} + " " + {s00e00} + "]"}`) * Ensure that `ActionPopup` is always displayed on top of the Windows Task Bar * Improved `-mediainfo -exec` pipeline -* Added `-no-history` CLI option +* Added `-no-history` and `-clear-history` CLI options * Allow dynamic code evaluation (e.g. `evaluate('/path/to/snippet.groovy' as File)`) * Allow `@file.groovy` syntax in `Format Editor` and `Preset Editor` (e.g. `@/path/to/MyFormat.groovy`) * Added `--mapper` option (e.g. `--mapper XEM.TheTVDB`) diff --git a/source/net/filebot/HistorySpooler.java b/source/net/filebot/HistorySpooler.java index 32252fa6..3f645f82 100644 --- a/source/net/filebot/HistorySpooler.java +++ b/source/net/filebot/HistorySpooler.java @@ -81,6 +81,7 @@ public final class HistorySpooler { channel.truncate(channel.position()); sessionHistory.clear(); + sessionHistoryTotalSize = 0; persistentHistoryTotalSize = history.totalSize(); } } @@ -89,6 +90,15 @@ public final class HistorySpooler { } } + public synchronized void clear() throws IOException { + log.fine("* Delete " + persistentHistoryFile); + persistentHistoryFile.delete(); + + sessionHistory.clear(); + sessionHistoryTotalSize = 0; + persistentHistoryTotalSize = 0; + } + public synchronized void append(Map elements) { append(elements.entrySet()); } diff --git a/source/net/filebot/Main.java b/source/net/filebot/Main.java index c2aea3e3..1ff58274 100644 --- a/source/net/filebot/Main.java +++ b/source/net/filebot/Main.java @@ -75,7 +75,13 @@ public class Main { System.exit(SUCCESS); } - if (args.clearCache() || args.clearUserData()) { + if (args.clearCache() || args.clearUserData() || args.clearHistory()) { + // clear persistent history + if (args.clearHistory) { + log.info("Reset history"); + HistorySpooler.getInstance().clear(); + } + // clear persistent user preferences if (args.clearUserData()) { log.info("Reset preferences"); diff --git a/source/net/filebot/cli/ArgumentBean.java b/source/net/filebot/cli/ArgumentBean.java index 121baa95..da899031 100644 --- a/source/net/filebot/cli/ArgumentBean.java +++ b/source/net/filebot/cli/ArgumentBean.java @@ -153,6 +153,9 @@ public class ArgumentBean { @Option(name = "-clear-prefs", usage = "Clear application settings") public boolean clearPrefs = false; + @Option(name = "-clear-history", usage = "Clear application history") + public boolean clearHistory = false; + @Option(name = "-version", usage = "Print version identifier") public boolean version = false; @@ -189,6 +192,10 @@ public class ArgumentBean { return clearPrefs; } + public boolean clearHistory() { + return clearHistory; + } + public List getFiles(boolean resolveFolders) throws Exception { if (arguments == null || arguments.isEmpty()) { return emptyList();