diff options
-rw-r--r-- | CHANGELOG.md | 1 | ||||
-rw-r--r-- | src/main/java/de/cowtipper/cowlection/search/GuiSearch.java | 7 | ||||
-rw-r--r-- | src/main/java/de/cowtipper/cowlection/search/LogFilesSearcher.java | 12 |
3 files changed, 10 insertions, 10 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md index 45cdc45..b85a8fb 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -18,6 +18,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/). ### Changed +- `/moo search`: Allow empty search query (= returns all log entries between start and end date) - `/moo stalkskyblock`: replaced "last played" with "last time *someone* played on the selected profile" ### Fixed diff --git a/src/main/java/de/cowtipper/cowlection/search/GuiSearch.java b/src/main/java/de/cowtipper/cowlection/search/GuiSearch.java index 2970c24..125f155 100644 --- a/src/main/java/de/cowtipper/cowlection/search/GuiSearch.java +++ b/src/main/java/de/cowtipper/cowlection/search/GuiSearch.java @@ -27,7 +27,6 @@ import org.lwjgl.input.Keyboard; import java.awt.*; import java.io.File; -import java.io.FileInputStream; import java.io.FileOutputStream; import java.io.IOException; import java.nio.file.Files; @@ -161,7 +160,7 @@ public class GuiSearch extends GuiScreen { boolean isStartDateValid = fieldDateStart.validateDate(); boolean isEndDateValid = fieldDateEnd.validateDate(); - this.buttonSearch.enabled = !isSearchInProgress && this.fieldSearchQuery.getText().trim().length() > 1 && !this.fieldSearchQuery.getText().startsWith(SEARCH_QUERY_PLACE_HOLDER) && isStartDateValid && isEndDateValid && !dateStart.isAfter(dateEnd); + this.buttonSearch.enabled = !isSearchInProgress && !this.fieldSearchQuery.getText().startsWith(SEARCH_QUERY_PLACE_HOLDER) && isStartDateValid && isEndDateValid && !dateStart.isAfter(dateEnd); if (isStartDateValid && isEndDateValid && dateStart.isAfter(dateEnd)) { fieldDateStart.setTextColor(0xFFDD3333); @@ -244,7 +243,7 @@ public class GuiSearch extends GuiScreen { boolean isStartDateValid = fieldDateStart.validateDate(); boolean isEndDateValid = fieldDateEnd.validateDate(); - this.buttonSearch.enabled = !isSearchInProgress && searchQuery.trim().length() > 1 && !searchQuery.startsWith(SEARCH_QUERY_PLACE_HOLDER) && isStartDateValid && isEndDateValid && !dateStart.isAfter(dateEnd); + this.buttonSearch.enabled = !isSearchInProgress && !searchQuery.startsWith(SEARCH_QUERY_PLACE_HOLDER) && isStartDateValid && isEndDateValid && !dateStart.isAfter(dateEnd); if (isStartDateValid && isEndDateValid && dateStart.isAfter(dateEnd)) { fieldDateStart.setTextColor(0xFFDD3333); @@ -508,7 +507,7 @@ public class GuiSearch extends GuiScreen { } else { // .log.gz String newLine = System.getProperty("line.separator"); String fileHeader = "# Original filename: " + logFileName + newLine + "# Use CTRL + F to search for specific words" + newLine + newLine; - try (GZIPInputStream logFileGzipped = new GZIPInputStream(new FileInputStream(logFileName)); + try (GZIPInputStream logFileGzipped = new GZIPInputStream(Files.newInputStream(searchResult.getFilePath())); FileOutputStream logFileUnGzipped = new FileOutputStream(mcLogOutputFile)) { logFileUnGzipped.write(fileHeader.getBytes()); int len; diff --git a/src/main/java/de/cowtipper/cowlection/search/LogFilesSearcher.java b/src/main/java/de/cowtipper/cowlection/search/LogFilesSearcher.java index c005852..38b8202 100644 --- a/src/main/java/de/cowtipper/cowlection/search/LogFilesSearcher.java +++ b/src/main/java/de/cowtipper/cowlection/search/LogFilesSearcher.java @@ -26,7 +26,7 @@ class LogFilesSearcher { * - [13:33:37] [Client thread/INFO]: [CHAT] Hello World * - [08:15:42] [Client thread/ERROR]: Item entity 9001 has no item?! */ - private static final Pattern LOG4J_PATTERN = Pattern.compile("^\\[(?<timeHours>[\\d]{2}):(?<timeMinutes>[\\d]{2}):(?<timeSeconds>[\\d]{2})] \\[(?<thread>[^/]+)/(?<logLevel>[A-Z]+)]:(?<isChat> \\[CHAT])? (?<message>.*)$"); + private static final Pattern LOG4J_PATTERN = Pattern.compile("^\\[(?<timeHours>\\d{2}):(?<timeMinutes>\\d{2}):(?<timeSeconds>\\d{2})] \\[(?<thread>[^/]+)/(?<logLevel>[A-Z]+)]:(?<isChat> \\[CHAT])? (?<message>.*)$"); private int analyzedFilesWithHits = 0; LogSearchResults searchFor(String searchQuery, boolean chatOnly, boolean matchCase, boolean removeFormatting, LocalDate dateStart, LocalDate dateEnd) throws IOException { @@ -44,8 +44,8 @@ class LogFilesSearcher { } String fileName = path.getFileName().toString(); return fileName.endsWith(".log.gz") || "latest.log".equals(fileName); - }).collect(Collectors.toList()).parallelStream()) { - paths.forEach(path -> { + }); Stream<Path> allPaths = paths.collect(Collectors.toList()).parallelStream()) { + allPaths.forEach(path -> { String fileName = path.getFileName().toString(); if (fileName.endsWith("z")) { // .log.gz Matcher fileNameMatcher = LOG_FILE_PATTERN.matcher(fileName); @@ -103,8 +103,8 @@ class LogFilesSearcher { List<LogEntry> searchResults = new ArrayList<>(); boolean foundSearchTermInFile = false; try (BufferedReader in = (isGzipped - ? new BufferedReader(new InputStreamReader(new GZIPInputStream(new FileInputStream(path.toFile())))) // ....log.gz - : new BufferedReader(new InputStreamReader(new FileInputStream(path.toFile()))))) { // latest.log + ? new BufferedReader(new InputStreamReader(new GZIPInputStream(Files.newInputStream(path)))) // ....log.gz + : new BufferedReader(new InputStreamReader(Files.newInputStream(path))))) { // latest.log String content; LogEntry logEntry = null; while ((content = in.readLine()) != null) { @@ -172,7 +172,7 @@ class LogFilesSearcher { // no result, abort return null; } - } else if (!logMessage.contains(searchTerms)) { + } else if (searchTerms.length() > 0 && !logMessage.contains(searchTerms)) { // no result, abort return null; } |