From 64f1cd7040b4706346541771af1500b8f717569b Mon Sep 17 00:00:00 2001 From: Reinhard Pointner Date: Mon, 20 Jul 2009 22:31:14 +0000 Subject: [PATCH] * refactoring --- .../net/sourceforge/filebot/FileBotUtilities.java | 9 ++++----- .../ui/panel/rename/EpisodeFormatDialog.java | 2 +- .../filebot/ui/panel/rename/RenameAction.java | 14 ++++++-------- .../filebot/ui/panel/rename/ValidateDialog.java | 2 +- 4 files changed, 12 insertions(+), 15 deletions(-) diff --git a/source/net/sourceforge/filebot/FileBotUtilities.java b/source/net/sourceforge/filebot/FileBotUtilities.java index 253a039f..df75a7dd 100644 --- a/source/net/sourceforge/filebot/FileBotUtilities.java +++ b/source/net/sourceforge/filebot/FileBotUtilities.java @@ -11,10 +11,9 @@ import net.sourceforge.tuned.FileUtilities.ExtensionFileFilter; public final class FileBotUtilities { /** - * Invalid characters in filenames: \, /, :, *, ?, ", <, >, |, \r and \n + * Invalid filename characters: \, /, :, *, ?, ", <, >, |, \r and \n */ - public static final String INVALID_CHARACTERS = "\\/:*?\"<>|\r\n"; - public static final Pattern INVALID_CHARACTERS_PATTERN = Pattern.compile(String.format("[%s]+", Pattern.quote(INVALID_CHARACTERS))); + public static final Pattern INVALID_CHARACTERS = Pattern.compile("[\\\\/:*?\"<>|\\r\\n]"); /** @@ -25,12 +24,12 @@ public final class FileBotUtilities { */ public static String validateFileName(CharSequence filename) { // strip invalid characters from filename - return INVALID_CHARACTERS_PATTERN.matcher(filename).replaceAll(""); + return INVALID_CHARACTERS.matcher(filename).replaceAll(""); } public static boolean isInvalidFileName(CharSequence filename) { - return INVALID_CHARACTERS_PATTERN.matcher(filename).find(); + return INVALID_CHARACTERS.matcher(filename).find(); } diff --git a/source/net/sourceforge/filebot/ui/panel/rename/EpisodeFormatDialog.java b/source/net/sourceforge/filebot/ui/panel/rename/EpisodeFormatDialog.java index d9dcffde..b4186a3b 100644 --- a/source/net/sourceforge/filebot/ui/panel/rename/EpisodeFormatDialog.java +++ b/source/net/sourceforge/filebot/ui/panel/rename/EpisodeFormatDialog.java @@ -317,7 +317,7 @@ public class EpisodeFormatDialog extends JDialog { }); panel.add(formatLink); - panel.add(new JLabel("...")); + panel.add(new JLabel("…")); panel.add(formatExample); } diff --git a/source/net/sourceforge/filebot/ui/panel/rename/RenameAction.java b/source/net/sourceforge/filebot/ui/panel/rename/RenameAction.java index d95cd4f8..9c4c4857 100644 --- a/source/net/sourceforge/filebot/ui/panel/rename/RenameAction.java +++ b/source/net/sourceforge/filebot/ui/panel/rename/RenameAction.java @@ -60,16 +60,14 @@ class RenameAction extends AbstractAction { for (ListIterator> iterator = renameLog.listIterator(renameLog.size()); iterator.hasPrevious();) { Entry mapping = iterator.previous(); - try { - File source = mapping.getKey(); - File destination = new File(source.getParentFile(), mapping.getValue()); - - // revert rename - rename(destination, source.getName()); - + // revert rename + File original = mapping.getKey(); + File current = new File(original.getParentFile(), mapping.getValue()); + + if (current.renameTo(original)) { // remove reverted rename operation from log iterator.remove(); - } catch (IOException ioe) { + } else { // failed to revert rename operation Logger.getLogger("ui").severe(String.format("Failed to revert file: \"%s\".", mapping.getValue())); } diff --git a/source/net/sourceforge/filebot/ui/panel/rename/ValidateDialog.java b/source/net/sourceforge/filebot/ui/panel/rename/ValidateDialog.java index 49991aaa..ae7580cd 100644 --- a/source/net/sourceforge/filebot/ui/panel/rename/ValidateDialog.java +++ b/source/net/sourceforge/filebot/ui/panel/rename/ValidateDialog.java @@ -47,7 +47,7 @@ class ValidateDialog extends JDialog { list = new JList(model); list.setEnabled(false); - list.setCellRenderer(new HighlightListCellRenderer(INVALID_CHARACTERS_PATTERN, new CharacterHighlightPainter(new Color(0xFF4200), new Color(0xFF1200)), 4)); + list.setCellRenderer(new HighlightListCellRenderer(INVALID_CHARACTERS, new CharacterHighlightPainter(new Color(0xFF4200), new Color(0xFF1200)), 4)); JLabel label = new JLabel("Some names contain invalid characters:");