mirror of
https://github.com/mitb-archive/filebot
synced 2024-11-04 16:35:08 -05:00
* root temporary folder is always lower-case
* filename embedded checksum may be enclosed with () or []
This commit is contained in:
parent
8cb277252b
commit
4267899842
@ -28,6 +28,8 @@ public final class FileBotUtil {
|
||||
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 EMBEDDED_CHECKSUM_PATTERN = Pattern.compile("[(\\[](\\p{XDigit}{8})[\\])]");
|
||||
|
||||
|
||||
/**
|
||||
* Strip filename of invalid characters
|
||||
|
@ -7,7 +7,8 @@ import java.util.Collection;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import net.sourceforge.filebot.FileBotUtil;
|
||||
|
||||
|
||||
public class ChecksumRow {
|
||||
@ -50,7 +51,7 @@ public class ChecksumRow {
|
||||
*/
|
||||
private static Long getEmbeddedChecksum(String name) {
|
||||
// look for a checksum pattern like [49A93C5F]
|
||||
Matcher matcher = Pattern.compile("\\[(\\p{XDigit}{8})\\]").matcher(name);
|
||||
Matcher matcher = FileBotUtil.EMBEDDED_CHECKSUM_PATTERN.matcher(name);
|
||||
|
||||
if (matcher.find())
|
||||
return Long.parseLong(matcher.group(1), 16);
|
||||
|
@ -3,6 +3,7 @@ package net.sourceforge.filebot.ui.panel.sfv;
|
||||
|
||||
|
||||
import java.awt.Component;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import javax.swing.JTable;
|
||||
import javax.swing.table.DefaultTableCellRenderer;
|
||||
@ -13,12 +14,12 @@ import javax.swing.table.DefaultTableCellRenderer;
|
||||
*/
|
||||
class HighlightPatternCellRenderer extends DefaultTableCellRenderer {
|
||||
|
||||
private final String pattern;
|
||||
private final Pattern pattern;
|
||||
private final String cssColor;
|
||||
private final String cssFontSize;
|
||||
|
||||
|
||||
public HighlightPatternCellRenderer(String pattern, String cssColor, String cssFontSize) {
|
||||
public HighlightPatternCellRenderer(Pattern pattern, String cssColor, String cssFontSize) {
|
||||
this.pattern = pattern;
|
||||
this.cssColor = cssColor;
|
||||
this.cssFontSize = cssFontSize;
|
||||
@ -31,7 +32,7 @@ class HighlightPatternCellRenderer extends DefaultTableCellRenderer {
|
||||
|
||||
// highlight CRC32 checksum patterns by using a smaller font-size and changing the font-color to a dark green
|
||||
// do not change the font-color if cell is selected, because that would look ugly (imagine green text on blue background ...)
|
||||
String htmlText = value.toString().replaceAll(pattern, "[<span style='font-size: " + cssFontSize + ";" + (!isSelected ? "color: " + cssColor + ";" : "") + "'>$1</span>]");
|
||||
String htmlText = pattern.matcher(value.toString()).replaceAll("[<span style='font-size: " + cssFontSize + ";" + (!isSelected ? "color: " + cssColor + ";" : "") + "'>$1</span>]");
|
||||
|
||||
// use no-break, because we really don't want line-wrapping in our table cells
|
||||
setText("<html><nobr>" + htmlText + "</nobr></html>");
|
||||
|
@ -13,6 +13,7 @@ import javax.swing.plaf.basic.BasicTableUI;
|
||||
import javax.swing.table.TableColumn;
|
||||
import javax.swing.table.TableModel;
|
||||
|
||||
import net.sourceforge.filebot.FileBotUtil;
|
||||
import net.sourceforge.filebot.ui.panel.sfv.ChecksumTableModel.ChecksumTableModelEvent;
|
||||
import net.sourceforge.filebot.ui.transfer.DefaultTransferHandler;
|
||||
|
||||
@ -45,7 +46,7 @@ class SfvTable extends JTable {
|
||||
setUI(new DragDropRowTableUI());
|
||||
|
||||
// highlight CRC32 patterns in filenames in green and with smaller font-size
|
||||
setDefaultRenderer(String.class, new HighlightPatternCellRenderer("\\[(\\p{XDigit}{8})\\]", "#009900", "smaller"));
|
||||
setDefaultRenderer(String.class, new HighlightPatternCellRenderer(FileBotUtil.EMBEDDED_CHECKSUM_PATTERN, "#009900", "smaller"));
|
||||
setDefaultRenderer(ChecksumRow.State.class, new StateIconTableCellRenderer());
|
||||
setDefaultRenderer(Checksum.class, new ChecksumTableCellRenderer());
|
||||
}
|
||||
|
@ -55,12 +55,16 @@ public class LazyTextFileTransferable implements Transferable {
|
||||
String validFileName = FileBotUtil.validateFileName(defaultFileName);
|
||||
|
||||
// create new temporary file in TEMP/APP_NAME [UUID]/dnd
|
||||
File temporaryFile = TemporaryFolder.getFolder(FileBotUtil.getApplicationName().toLowerCase()).subFolder("dnd").createFile(validFileName);
|
||||
File temporaryFile = TemporaryFolder.getFolder(FileBotUtil.getApplicationName()).subFolder("dnd").createFile(validFileName);
|
||||
|
||||
// write text to file
|
||||
FileChannel fileChannel = new FileOutputStream(temporaryFile).getChannel();
|
||||
|
||||
try {
|
||||
fileChannel.write(Charset.forName("UTF-8").encode(text));
|
||||
} finally {
|
||||
fileChannel.close();
|
||||
}
|
||||
|
||||
return new FileTransferable(temporaryFile);
|
||||
}
|
||||
|
@ -20,20 +20,23 @@ public final class TemporaryFolder {
|
||||
|
||||
/**
|
||||
* Get a {@link TemporaryFolder} instance for a given name. The actual directory will be
|
||||
* created lazily (e.g. when a file is created). The directories name will start with the
|
||||
* given name and contain a unique id, so multiple application instances may run at the
|
||||
* same time without the risk of interference.
|
||||
* created lazily (e.g. when a file is created). The name of the directory will start with
|
||||
* the given name (lower-case) and contain a unique id, so multiple application instances
|
||||
* may run at the same time without the risk of interference.
|
||||
*
|
||||
* @param name case-insensitive name of a temporary folder (e.g. application name)
|
||||
* @return temporary folder for this name
|
||||
*/
|
||||
public static TemporaryFolder getFolder(String name) {
|
||||
// make name case-insensitive
|
||||
name = name.toLowerCase();
|
||||
|
||||
synchronized (folders) {
|
||||
TemporaryFolder folder = folders.get(name.toLowerCase());
|
||||
TemporaryFolder folder = folders.get(name);
|
||||
|
||||
if (folder == null) {
|
||||
folder = new TemporaryFolder(new File(tmpdir, String.format("%s [%s]", name, UUID.randomUUID())));
|
||||
folders.put(name.toLowerCase(), folder);
|
||||
folders.put(name, folder);
|
||||
}
|
||||
|
||||
return folder;
|
||||
|
Loading…
Reference in New Issue
Block a user