Skip to content

Commit

Permalink
fix event add and extensions
Browse files Browse the repository at this point in the history
  • Loading branch information
ate47 committed Aug 4, 2023
1 parent a9f2a1f commit 1174fd6
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 9 deletions.
8 changes: 4 additions & 4 deletions src/main/java/fr/atesab/bo4hash/DataFetcher.java
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,12 @@ public static String fetch(String location, String outputFile) {
}
Path rp = dir.relativize(p);
String name = rp.getFileName().toString();
if (!(name.endsWith(".gsc") || name.endsWith(".csc"))) {
if (!(HashUtils.isHashFile(name))) {
return;
}


if (name.startsWith("script_")) {
if (name.startsWith("script_") && (name.endsWith(".gsc") || name.endsWith(".csc"))) {
scripts.add(name.substring(0, name.length() - ".gsc".length()));
} else {
scripts.add(rp.toString().replace('\\', '/'));
Expand Down Expand Up @@ -126,7 +126,7 @@ public static String fetch(String location, String outputFile) {
}
}
long total = 0;
try (BufferedWriter writer = Files.newBufferedWriter(outputFilePath.resolve("dataset.csv"))) {
try (BufferedWriter writer = Files.newBufferedWriter(outputFilePath.resolve("dataset.txt"))) {
long scriptCount = dumpDataset(writer, "script", scripts);
total += scriptCount;
log += I18n.get("fetcher.write.script", scriptCount) + "\n";
Expand Down Expand Up @@ -178,7 +178,7 @@ private static long dumpDataset(BufferedWriter writer, String type, Iterable<? e

public static Set<String> splitString(Stream<String> strings) {
return strings
.filter(s -> !(s.startsWith("hash_") || s.startsWith("script_") || s.startsWith("function_") || s.startsWith("namespace_") || s.startsWith("var_")))
.filter(s -> !(s.startsWith("hash_") || s.startsWith("script_") || s.startsWith("event_") || s.startsWith("function_") || s.startsWith("namespace_") || s.startsWith("var_")))
.flatMap(s -> Stream.of(s.toLowerCase().split("[^a-z0-9]")))
.filter(s -> !s.isEmpty())
.collect(Collectors.toCollection(TreeSet<String>::new));
Expand Down
7 changes: 5 additions & 2 deletions src/main/java/fr/atesab/bo4hash/MainReader.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package fr.atesab.bo4hash;

import fr.atesab.bo4hash.utils.HashUtils;

import java.io.BufferedWriter;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
Expand Down Expand Up @@ -29,7 +31,8 @@ public static void main(String[] args) throws IOException {
"namespace_",
"var_",
"hash_",
"script_"
"script_",
"event_"
};

Path dir = Path.of(prop.getProperty(Main.CFG_PATH));
Expand All @@ -41,7 +44,7 @@ public static void main(String[] args) throws IOException {
}
String name = dir.relativize(p).getFileName().toString();
System.out.println("loading " + name);
if (!(name.endsWith(".gsc") || name.endsWith(".csc"))) {
if (!(HashUtils.isHashFile(name))) {
return;
}
String s;
Expand Down
5 changes: 3 additions & 2 deletions src/main/java/fr/atesab/bo4hash/Searcher.java
Original file line number Diff line number Diff line change
Expand Up @@ -198,12 +198,13 @@ public String load(String dirPath, IndexListener listener) {
return;
}

if (!(name.endsWith(".gsc") || name.endsWith(".csc") || name.endsWith(".gcsc") || name.endsWith(".csv"))) {
if (!(HashUtils.isHashFile(name))) {
return;
}
listener.notification(loadingI18n + " #" + count.getAndIncrement() + " - " + name);
if (name.startsWith("script_")) {
Obj obj = new Obj(name.substring("script_".length(), name.length() - 4).toLowerCase(), name.substring(0, name.length() - 4));
int endIx = Math.max(0, name.lastIndexOf('.'));
Obj obj = new Obj(name.substring("script_".length(), endIx).toLowerCase(), name.substring(0, endIx));
files.put(Long.parseUnsignedLong(obj.hash(), 16), obj);
}
String s;
Expand Down
5 changes: 5 additions & 0 deletions src/main/java/fr/atesab/bo4hash/utils/HashUtils.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package fr.atesab.bo4hash.utils;

import java.nio.file.Path;
import java.util.Set;

public class HashUtils {
Expand All @@ -17,6 +18,10 @@ public static boolean isFNV(String type) {
return FNV_TYPES.contains(type);
}

public static boolean isHashFile(String name) {
return name.endsWith(".gsc") || name.endsWith(".csc") || name.endsWith(".gcsc") || name.endsWith(".csv");
}

public static long hashIDF(String input) {
long hash = 0x4B9ACE2FL;
input = input.toLowerCase();
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/fr/atesab/bo4hash/utils/ReplacerTool.java
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public static String replace(String directory, String keys) throws IOException {
}
String name = dir.relativize(p).getFileName().toString();
// ignore non GSC file
if (!(name.endsWith(".gsc") || name.endsWith(".csc"))) {
if (!(HashUtils.isHashFile(name))) {
return null;
}
String fileReplacement = hashIndex.get(name.substring(0, name.length() - 4));
Expand Down

0 comments on commit 1174fd6

Please sign in to comment.