Add RegEx to File Selection
This commit is contained in:
parent
9d01f46c16
commit
3fc249cf07
|
@ -50,70 +50,96 @@ public class ReplacementScanner {
|
||||||
} catch (IllegalAccessException | InvocationTargetException | NoSuchMethodException e) {
|
} catch (IllegalAccessException | InvocationTargetException | NoSuchMethodException e) {
|
||||||
throw new IllegalStateException("Cannot access zipsearch()", e);
|
throw new IllegalStateException("Cannot access zipsearch()", e);
|
||||||
}
|
}
|
||||||
|
if (files.size() <= 0 || whitelist.length <= 0)
|
||||||
|
return;
|
||||||
|
|
||||||
|
boolean csfs = false;
|
||||||
|
{
|
||||||
|
long stamp = Math.round(Math.random() * 100000);
|
||||||
|
File test1 = new File(dir, '.' + stamp + ".ss_fsc");
|
||||||
|
File test2 = new File(dir, '.' + stamp + ".SS_FSC");
|
||||||
|
|
||||||
|
test1.createNewFile();
|
||||||
|
if (test2.createNewFile()) {
|
||||||
|
csfs = true;
|
||||||
|
test2.delete();
|
||||||
|
}
|
||||||
|
test1.delete();
|
||||||
|
}
|
||||||
|
|
||||||
LinkedHashMap<Pattern, Boolean> rules = new LinkedHashMap<Pattern, Boolean>();
|
LinkedHashMap<Pattern, Boolean> rules = new LinkedHashMap<Pattern, Boolean>();
|
||||||
for (String entry : whitelist) {
|
for (String entry : whitelist) {
|
||||||
boolean mode = !entry.startsWith("!");
|
boolean mode = !entry.startsWith("!");
|
||||||
if (!mode) entry = entry.substring(1);
|
if (!mode) entry = entry.substring(1);
|
||||||
if (entry.startsWith(".")) entry = entry.substring(1);
|
|
||||||
|
|
||||||
StringBuilder rule = new StringBuilder();
|
String pattern;
|
||||||
if (entry.startsWith("**")) {
|
if (!entry.startsWith("%")) {
|
||||||
entry = entry.substring(2);
|
if (entry.startsWith("./"))
|
||||||
rule.append("^.*");
|
entry = entry.substring(1);
|
||||||
} else if (entry.startsWith("/")) {
|
|
||||||
rule.append("^");
|
|
||||||
}
|
|
||||||
|
|
||||||
boolean greedyEnding = false;
|
StringBuilder rule = new StringBuilder();
|
||||||
if (entry.endsWith("**")) {
|
if (entry.startsWith("**")) {
|
||||||
entry = entry.substring(0, entry.length() - 2);
|
entry = entry.substring(2);
|
||||||
greedyEnding = true;
|
rule.append("^.*");
|
||||||
} else if (entry.endsWith("/")) {
|
} else if (entry.startsWith("/")) {
|
||||||
greedyEnding = true;
|
rule.append("^");
|
||||||
}
|
|
||||||
|
|
||||||
StringBuilder literal = new StringBuilder();
|
|
||||||
for (PrimitiveIterator.OfInt i = entry.codePoints().iterator(); i.hasNext(); ) {
|
|
||||||
int c = i.next();
|
|
||||||
if ((c == '*' || c == '?' || c == '[') && literal.length() > 0) {
|
|
||||||
rule.append(Pattern.quote(literal.toString()));
|
|
||||||
literal = new StringBuilder();
|
|
||||||
}
|
}
|
||||||
switch (c) {
|
|
||||||
case '\\':
|
boolean greedyEnding = false;
|
||||||
if (i.hasNext()) c = i.next();
|
if (entry.endsWith("**")) {
|
||||||
literal.appendCodePoint(c);
|
entry = entry.substring(0, entry.length() - 2);
|
||||||
case '[':
|
greedyEnding = true;
|
||||||
for (boolean escaped = false; i.hasNext() && (c != ']' || escaped); c = i.next()) {
|
} else if (entry.endsWith("/")) {
|
||||||
if (c == '\\') escaped = !escaped;
|
greedyEnding = true;
|
||||||
else escaped = false;
|
}
|
||||||
literal.appendCodePoint(c);
|
|
||||||
}
|
StringBuilder literal = new StringBuilder();
|
||||||
if (c == ']' && literal.length() > 1) {
|
for (PrimitiveIterator.OfInt i = entry.codePoints().iterator(); i.hasNext(); ) {
|
||||||
literal.appendCodePoint(c);
|
int c = i.next();
|
||||||
rule.append(literal.toString());
|
if ((c == '*' || c == '?' || c == '[') && literal.length() > 0) {
|
||||||
}
|
rule.append(Pattern.quote(literal.toString()));
|
||||||
literal = new StringBuilder();
|
literal = new StringBuilder();
|
||||||
break;
|
}
|
||||||
case '*':
|
switch (c) {
|
||||||
rule.append("[^/]+");
|
case '\\':
|
||||||
break;
|
if (i.hasNext()) c = i.next();
|
||||||
case '?':
|
literal.appendCodePoint(c);
|
||||||
rule.append("[^/]");
|
case '[':
|
||||||
break;
|
for (boolean escaped = false; i.hasNext() && (c != ']' || escaped); c = i.next()) {
|
||||||
default:
|
if (c == '\\') escaped = !escaped;
|
||||||
literal.appendCodePoint(c);
|
else escaped = false;
|
||||||
break;
|
literal.appendCodePoint(c);
|
||||||
|
}
|
||||||
|
if (c == ']' && literal.length() > 1) {
|
||||||
|
literal.appendCodePoint(c);
|
||||||
|
rule.append(literal.toString());
|
||||||
|
}
|
||||||
|
literal = new StringBuilder();
|
||||||
|
break;
|
||||||
|
case '*':
|
||||||
|
rule.append("[^/]+");
|
||||||
|
break;
|
||||||
|
case '?':
|
||||||
|
rule.append("[^/]");
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
literal.appendCodePoint(c);
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
if (literal.length() > 0)
|
||||||
if (literal.length() > 0)
|
rule.append(Pattern.quote(literal.toString()));
|
||||||
rule.append(Pattern.quote(literal.toString()));
|
|
||||||
|
|
||||||
if (greedyEnding)
|
if (greedyEnding)
|
||||||
rule.append(".*");
|
rule.append(".*");
|
||||||
rule.append("$");
|
rule.append("$");
|
||||||
rules.put(Pattern.compile(rule.toString()), mode);
|
pattern = rule.toString();
|
||||||
|
} else {
|
||||||
|
pattern = entry.substring(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (csfs) rules.put(Pattern.compile(pattern), mode);
|
||||||
|
else rules.put(Pattern.compile(pattern, Pattern.CASE_INSENSITIVE), mode);
|
||||||
}
|
}
|
||||||
|
|
||||||
for (String file : files) {
|
for (String file : files) {
|
||||||
|
|
|
@ -50,70 +50,96 @@ public class ReplacementScanner {
|
||||||
} catch (IllegalAccessException | InvocationTargetException | NoSuchMethodException e) {
|
} catch (IllegalAccessException | InvocationTargetException | NoSuchMethodException e) {
|
||||||
throw new IllegalStateException("Cannot access zipsearch()", e);
|
throw new IllegalStateException("Cannot access zipsearch()", e);
|
||||||
}
|
}
|
||||||
|
if (files.size() <= 0 || whitelist.length <= 0)
|
||||||
|
return;
|
||||||
|
|
||||||
|
boolean csfs = false;
|
||||||
|
{
|
||||||
|
long stamp = Math.round(Math.random() * 100000);
|
||||||
|
File test1 = new File(dir, '.' + stamp + ".ss_fsc");
|
||||||
|
File test2 = new File(dir, '.' + stamp + ".SS_FSC");
|
||||||
|
|
||||||
|
test1.createNewFile();
|
||||||
|
if (test2.createNewFile()) {
|
||||||
|
csfs = true;
|
||||||
|
test2.delete();
|
||||||
|
}
|
||||||
|
test1.delete();
|
||||||
|
}
|
||||||
|
|
||||||
LinkedHashMap<Pattern, Boolean> rules = new LinkedHashMap<Pattern, Boolean>();
|
LinkedHashMap<Pattern, Boolean> rules = new LinkedHashMap<Pattern, Boolean>();
|
||||||
for (String entry : whitelist) {
|
for (String entry : whitelist) {
|
||||||
boolean mode = !entry.startsWith("!");
|
boolean mode = !entry.startsWith("!");
|
||||||
if (!mode) entry = entry.substring(1);
|
if (!mode) entry = entry.substring(1);
|
||||||
if (entry.startsWith(".")) entry = entry.substring(1);
|
|
||||||
|
|
||||||
StringBuilder rule = new StringBuilder();
|
String pattern;
|
||||||
if (entry.startsWith("**")) {
|
if (!entry.startsWith("%")) {
|
||||||
entry = entry.substring(2);
|
if (entry.startsWith("./"))
|
||||||
rule.append("^.*");
|
entry = entry.substring(1);
|
||||||
} else if (entry.startsWith("/")) {
|
|
||||||
rule.append("^");
|
|
||||||
}
|
|
||||||
|
|
||||||
boolean greedyEnding = false;
|
StringBuilder rule = new StringBuilder();
|
||||||
if (entry.endsWith("**")) {
|
if (entry.startsWith("**")) {
|
||||||
entry = entry.substring(0, entry.length() - 2);
|
entry = entry.substring(2);
|
||||||
greedyEnding = true;
|
rule.append("^.*");
|
||||||
} else if (entry.endsWith("/")) {
|
} else if (entry.startsWith("/")) {
|
||||||
greedyEnding = true;
|
rule.append("^");
|
||||||
}
|
|
||||||
|
|
||||||
StringBuilder literal = new StringBuilder();
|
|
||||||
for (PrimitiveIterator.OfInt i = entry.codePoints().iterator(); i.hasNext(); ) {
|
|
||||||
int c = i.next();
|
|
||||||
if ((c == '*' || c == '?' || c == '[') && literal.length() > 0) {
|
|
||||||
rule.append(Pattern.quote(literal.toString()));
|
|
||||||
literal = new StringBuilder();
|
|
||||||
}
|
}
|
||||||
switch (c) {
|
|
||||||
case '\\':
|
boolean greedyEnding = false;
|
||||||
if (i.hasNext()) c = i.next();
|
if (entry.endsWith("**")) {
|
||||||
literal.appendCodePoint(c);
|
entry = entry.substring(0, entry.length() - 2);
|
||||||
case '[':
|
greedyEnding = true;
|
||||||
for (boolean escaped = false; i.hasNext() && (c != ']' || escaped); c = i.next()) {
|
} else if (entry.endsWith("/")) {
|
||||||
if (c == '\\') escaped = !escaped;
|
greedyEnding = true;
|
||||||
else escaped = false;
|
}
|
||||||
literal.appendCodePoint(c);
|
|
||||||
}
|
StringBuilder literal = new StringBuilder();
|
||||||
if (c == ']' && literal.length() > 1) {
|
for (PrimitiveIterator.OfInt i = entry.codePoints().iterator(); i.hasNext(); ) {
|
||||||
literal.appendCodePoint(c);
|
int c = i.next();
|
||||||
rule.append(literal.toString());
|
if ((c == '*' || c == '?' || c == '[') && literal.length() > 0) {
|
||||||
}
|
rule.append(Pattern.quote(literal.toString()));
|
||||||
literal = new StringBuilder();
|
literal = new StringBuilder();
|
||||||
break;
|
}
|
||||||
case '*':
|
switch (c) {
|
||||||
rule.append("[^/]+");
|
case '\\':
|
||||||
break;
|
if (i.hasNext()) c = i.next();
|
||||||
case '?':
|
literal.appendCodePoint(c);
|
||||||
rule.append("[^/]");
|
case '[':
|
||||||
break;
|
for (boolean escaped = false; i.hasNext() && (c != ']' || escaped); c = i.next()) {
|
||||||
default:
|
if (c == '\\') escaped = !escaped;
|
||||||
literal.appendCodePoint(c);
|
else escaped = false;
|
||||||
break;
|
literal.appendCodePoint(c);
|
||||||
|
}
|
||||||
|
if (c == ']' && literal.length() > 1) {
|
||||||
|
literal.appendCodePoint(c);
|
||||||
|
rule.append(literal.toString());
|
||||||
|
}
|
||||||
|
literal = new StringBuilder();
|
||||||
|
break;
|
||||||
|
case '*':
|
||||||
|
rule.append("[^/]+");
|
||||||
|
break;
|
||||||
|
case '?':
|
||||||
|
rule.append("[^/]");
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
literal.appendCodePoint(c);
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
if (literal.length() > 0)
|
||||||
if (literal.length() > 0)
|
rule.append(Pattern.quote(literal.toString()));
|
||||||
rule.append(Pattern.quote(literal.toString()));
|
|
||||||
|
|
||||||
if (greedyEnding)
|
if (greedyEnding)
|
||||||
rule.append(".*");
|
rule.append(".*");
|
||||||
rule.append("$");
|
rule.append("$");
|
||||||
rules.put(Pattern.compile(rule.toString()), mode);
|
pattern = rule.toString();
|
||||||
|
} else {
|
||||||
|
pattern = entry.substring(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (csfs) rules.put(Pattern.compile(pattern), mode);
|
||||||
|
else rules.put(Pattern.compile(pattern, Pattern.CASE_INSENSITIVE), mode);
|
||||||
}
|
}
|
||||||
|
|
||||||
for (String file : files) {
|
for (String file : files) {
|
||||||
|
|
Loading…
Reference in New Issue