1
0
mirror of https://github.com/mitb-archive/filebot synced 2025-01-10 21:38:04 -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 {
/**
* 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();
}

View File

@ -317,7 +317,7 @@ public class EpisodeFormatDialog extends JDialog {
});
panel.add(formatLink);
panel.add(new JLabel("..."));
panel.add(new JLabel(""));
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();) {
Entry<File, String> 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()));
}

View File

@ -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:");