1
0
mirror of https://github.com/mitb-archive/filebot synced 2025-01-11 05:48:01 -05:00

* refactoring

This commit is contained in:
Reinhard Pointner 2009-07-20 22:31:14 +00:00
parent cb7200434d
commit 64f1cd7040
4 changed files with 12 additions and 15 deletions

View File

@ -11,10 +11,9 @@ import net.sourceforge.tuned.FileUtilities.ExtensionFileFilter;
public final class FileBotUtilities { 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.compile("[\\\\/:*?\"<>|\\r\\n]");
public static final Pattern INVALID_CHARACTERS_PATTERN = Pattern.compile(String.format("[%s]+", Pattern.quote(INVALID_CHARACTERS)));
/** /**
@ -25,12 +24,12 @@ public final class FileBotUtilities {
*/ */
public static String validateFileName(CharSequence filename) { public static String validateFileName(CharSequence filename) {
// strip invalid characters from 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) { public static boolean isInvalidFileName(CharSequence filename) {
return INVALID_CHARACTERS_PATTERN.matcher(filename).find(); return INVALID_CHARACTERS.matcher(filename).find();
} }

View File

@ -317,7 +317,7 @@ public class EpisodeFormatDialog extends JDialog {
}); });
panel.add(formatLink); panel.add(formatLink);
panel.add(new JLabel("...")); panel.add(new JLabel(""));
panel.add(formatExample); panel.add(formatExample);
} }

View File

@ -60,16 +60,14 @@ class RenameAction extends AbstractAction {
for (ListIterator<Entry<File, String>> iterator = renameLog.listIterator(renameLog.size()); iterator.hasPrevious();) { for (ListIterator<Entry<File, String>> iterator = renameLog.listIterator(renameLog.size()); iterator.hasPrevious();) {
Entry<File, String> mapping = iterator.previous(); Entry<File, String> mapping = iterator.previous();
try { // revert rename
File source = mapping.getKey(); File original = mapping.getKey();
File destination = new File(source.getParentFile(), mapping.getValue()); File current = new File(original.getParentFile(), mapping.getValue());
// revert rename if (current.renameTo(original)) {
rename(destination, source.getName());
// remove reverted rename operation from log // remove reverted rename operation from log
iterator.remove(); iterator.remove();
} catch (IOException ioe) { } else {
// failed to revert rename operation // failed to revert rename operation
Logger.getLogger("ui").severe(String.format("Failed to revert file: \"%s\".", mapping.getValue())); Logger.getLogger("ui").severe(String.format("Failed to revert file: \"%s\".", mapping.getValue()));
} }

View File

@ -47,7 +47,7 @@ class ValidateDialog extends JDialog {
list = new JList(model); list = new JList(model);
list.setEnabled(false); 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:"); JLabel label = new JLabel("Some names contain invalid characters:");