* unified embedded checksum handling
This commit is contained in:
parent
4267899842
commit
66cf786b19
|
@ -6,6 +6,7 @@ import java.io.File;
|
|||
import java.io.FileFilter;
|
||||
import java.io.FilenameFilter;
|
||||
import java.util.List;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import net.sourceforge.tuned.FileUtil;
|
||||
|
@ -28,8 +29,6 @@ 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
|
||||
|
@ -47,6 +46,26 @@ public final class FileBotUtil {
|
|||
return INVALID_CHARACTERS_PATTERN.matcher(filename).find();
|
||||
}
|
||||
|
||||
/**
|
||||
* A {@link Pattern} that will match checksums enclosed in brackets ("[]" or "()"). A
|
||||
* checksum string is a hex number with at least 8 digits. Capturing group 1 will contain
|
||||
* the matched checksum string.
|
||||
*/
|
||||
public static final Pattern EMBEDDED_CHECKSUM_PATTERN = Pattern.compile("(?<=\\[|\\()(\\p{XDigit}{8,})(?=\\]|\\))");
|
||||
|
||||
|
||||
public static String getEmbeddedChecksum(String string) {
|
||||
Matcher matcher = FileBotUtil.EMBEDDED_CHECKSUM_PATTERN.matcher(string);
|
||||
String embeddedChecksum = null;
|
||||
|
||||
// get last match
|
||||
while (matcher.find()) {
|
||||
embeddedChecksum = matcher.group(1);
|
||||
}
|
||||
|
||||
return embeddedChecksum;
|
||||
}
|
||||
|
||||
private static final String[] TORRENT_FILE_EXTENSIONS = { "torrent" };
|
||||
private static final String[] SFV_FILE_EXTENSIONS = { "sfv" };
|
||||
private static final String[] LIST_FILE_EXTENSIONS = { "txt", "list", "" };
|
||||
|
|
|
@ -6,7 +6,6 @@ import java.io.File;
|
|||
import java.util.Collection;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.regex.Matcher;
|
||||
|
||||
import net.sourceforge.filebot.FileBotUtil;
|
||||
|
||||
|
@ -51,11 +50,11 @@ public class ChecksumRow {
|
|||
*/
|
||||
private static Long getEmbeddedChecksum(String name) {
|
||||
// look for a checksum pattern like [49A93C5F]
|
||||
Matcher matcher = FileBotUtil.EMBEDDED_CHECKSUM_PATTERN.matcher(name);
|
||||
String match = FileBotUtil.getEmbeddedChecksum(name);
|
||||
|
||||
if (match != null)
|
||||
return Long.parseLong(match, 16);
|
||||
|
||||
if (matcher.find())
|
||||
return Long.parseLong(matcher.group(1), 16);
|
||||
else
|
||||
return null;
|
||||
}
|
||||
|
||||
|
|
|
@ -3,6 +3,7 @@ package net.sourceforge.filebot.ui.panel.sfv;
|
|||
|
||||
|
||||
import java.awt.Component;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import javax.swing.JTable;
|
||||
|
@ -32,10 +33,20 @@ 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 = pattern.matcher(value.toString()).replaceAll("[<span style='font-size: " + cssFontSize + ";" + (!isSelected ? "color: " + cssColor + ";" : "") + "'>$1</span>]");
|
||||
Matcher matcher = pattern.matcher(value.toString());
|
||||
|
||||
// use no-break, because we really don't want line-wrapping in our table cells
|
||||
setText("<html><nobr>" + htmlText + "</nobr></html>");
|
||||
StringBuffer htmlText = new StringBuffer("<html><nobr>");
|
||||
|
||||
while (matcher.find()) {
|
||||
matcher.appendReplacement(htmlText, "<span style='font-size: " + cssFontSize + ";" + (!isSelected ? "color: " + cssColor + ";" : "") + "'>$1</span>");
|
||||
}
|
||||
|
||||
matcher.appendTail(htmlText);
|
||||
|
||||
htmlText.append("</nobr></html>");
|
||||
|
||||
setText(htmlText.toString());
|
||||
|
||||
return this;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue