diff options
| author | Cow <cow@volloeko.de> | 2021-07-01 21:41:59 +0200 |
|---|---|---|
| committer | Cow <cow@volloeko.de> | 2021-07-01 21:41:59 +0200 |
| commit | 581e0bc3e52d99d73cfeeffcaec64fd3da31cbc0 (patch) | |
| tree | 905f8e57a9f04b381c5cc8fa14112b62bec0d86e /src/main/java/de/cowtipper/cowlection/search | |
| parent | fa965e448033d817667760f84ca73cf9bab2519b (diff) | |
| download | Cowlection-581e0bc3e52d99d73cfeeffcaec64fd3da31cbc0.tar.gz Cowlection-581e0bc3e52d99d73cfeeffcaec64fd3da31cbc0.tar.bz2 Cowlection-581e0bc3e52d99d73cfeeffcaec64fd3da31cbc0.zip | |
Added more config options to existing features
- Bazaar: order 'Sell Inventory/Sacks Now' tooltips asc/desc
- MC Log file search: maximum file size to analyze
- Toggle: dungeon performance summary at end of dungeon
- Toggle: warn when queued and entered dungeon floors are different
- Toggle: shorten item quality info for non-randomized items
Diffstat (limited to 'src/main/java/de/cowtipper/cowlection/search')
3 files changed, 105 insertions, 27 deletions
diff --git a/src/main/java/de/cowtipper/cowlection/search/GuiSearch.java b/src/main/java/de/cowtipper/cowlection/search/GuiSearch.java index 21059ca..7e721a9 100644 --- a/src/main/java/de/cowtipper/cowlection/search/GuiSearch.java +++ b/src/main/java/de/cowtipper/cowlection/search/GuiSearch.java @@ -23,7 +23,6 @@ import net.minecraftforge.fml.client.config.IConfigElement; import net.minecraftforge.fml.relauncher.ReflectionHelper; import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.exception.ExceptionUtils; -import org.apache.commons.lang3.tuple.ImmutableTriple; import org.lwjgl.input.Keyboard; import java.awt.*; @@ -79,10 +78,11 @@ public class GuiSearch extends GuiScreen { private boolean isSearchInProgress; private String analyzedFiles; private String analyzedFilesWithHits; + private String skippedFiles; private boolean areEntriesSearchResults; - public GuiSearch(File configDirectory, String initialSearchQuery) { - this.mcLogOutputFile = new File(configDirectory, "mc-log.txt"); + public GuiSearch(String initialSearchQuery) { + this.mcLogOutputFile = new File(Cowlection.getInstance().getModOutDirectory(), "cowlection-mc-log-search-temp.txt"); try { mcLogOutputFile.createNewFile(); } catch (IOException e) { @@ -287,19 +287,21 @@ public class GuiSearch extends GuiScreen { executorService.execute(() -> { try { - ImmutableTriple<Integer, Integer, List<LogEntry>> searchResultsData = new LogFilesSearcher().searchFor(this.fieldSearchQuery.getText(), checkboxChatOnly.isChecked(), checkboxMatchCase.isChecked(), checkboxRemoveFormatting.isChecked(), dateStart, dateEnd); - this.searchResults = searchResultsData.right; - this.analyzedFiles = "Analyzed files: " + EnumChatFormatting.WHITE + searchResultsData.left; - this.analyzedFilesWithHits = "Files with hits: " + EnumChatFormatting.WHITE + searchResultsData.middle; + LogSearchResults searchResultsData = new LogFilesSearcher().searchFor(this.fieldSearchQuery.getText(), checkboxChatOnly.isChecked(), checkboxMatchCase.isChecked(), checkboxRemoveFormatting.isChecked(), dateStart, dateEnd); + this.searchResults = searchResultsData.getSortedSearchResults(); + this.analyzedFiles = "Analyzed files: " + EnumChatFormatting.WHITE + searchResultsData.getAnalyzedFiles(); + this.analyzedFilesWithHits = "Files with hits: " + EnumChatFormatting.WHITE + searchResultsData.getAnalyzedFilesWithHits(); + this.skippedFiles = "Skipped files: " + EnumChatFormatting.WHITE + searchResultsData.getSkippedFiles(); if (this.searchResults.isEmpty()) { this.searchResults.add(new LogEntry(EnumChatFormatting.ITALIC + "No results")); areEntriesSearchResults = false; } else { - areEntriesSearchResults = true; + areEntriesSearchResults = searchResultsData.getAnalyzedFiles() != 0; } } catch (IOException e) { if (e.getStackTrace().length > 0) { searchResults.add(new LogEntry(StringUtils.replaceEach(ExceptionUtils.getStackTrace(e), new String[]{"\t", "\r\n"}, new String[]{" ", "\n"}))); + areEntriesSearchResults = false; } } Minecraft.getMinecraft().addScheduledTask(() -> { @@ -319,6 +321,9 @@ public class GuiSearch extends GuiScreen { this.searchResults.add(new LogEntry("" + EnumChatFormatting.GOLD + EnumChatFormatting.BOLD + "Initial setup/configuration " + EnumChatFormatting.GRAY + EnumChatFormatting.ITALIC + "'Open Settings' (top right corner)")); this.searchResults.add(new LogEntry(EnumChatFormatting.GOLD + " 1) " + EnumChatFormatting.RESET + "Configure directories that should be scanned for log files (\"Directories with Minecraft log files\")")); this.searchResults.add(new LogEntry(EnumChatFormatting.GOLD + " 2) " + EnumChatFormatting.RESET + "Set default starting date (\"Start date for log file search\")")); + this.searchResults.add(new LogEntry(" ‣ can be a number (e.g. \"3\" means \"start searching 3 months ago\")")); + this.searchResults.add(new LogEntry(" ‣ or alternatively a fixed date (yyyy-mm-dd)")); + this.searchResults.add(new LogEntry(EnumChatFormatting.GOLD + " 3) " + EnumChatFormatting.RESET + "optional: change the maximum allowed log file size to be searched, but note that each log file must be unzipped before it can be analyzed, which can make the log file search take significantly longer for large files")); this.searchResults.add(new LogEntry("" + EnumChatFormatting.GOLD + EnumChatFormatting.BOLD + "Performing a search " + EnumChatFormatting.GRAY + EnumChatFormatting.ITALIC + "/moo search [initial search term]")); this.searchResults.add(new LogEntry(EnumChatFormatting.GOLD + " 1) " + EnumChatFormatting.RESET + "Enter search term")); this.searchResults.add(new LogEntry(EnumChatFormatting.GOLD + " 2) " + EnumChatFormatting.RESET + "Adjust start and end date")); @@ -360,6 +365,7 @@ public class GuiSearch extends GuiScreen { guiSearchResults.clearResults(); analyzedFiles = null; analyzedFilesWithHits = null; + skippedFiles = null; } else { buttonSearch.displayString = "Search"; } @@ -441,13 +447,16 @@ public class GuiSearch extends GuiScreen { } } else if (areEntriesSearchResults) { if (analyzedFiles != null) { - drawString(fontRendererObj, analyzedFiles, 8, 22, 0xff888888); + drawString(fontRendererObj, analyzedFiles, 8, 15, 0xff888888); } if (analyzedFilesWithHits != null) { - drawString(fontRendererObj, analyzedFilesWithHits, 8, 32, 0xff888888); + drawString(fontRendererObj, analyzedFilesWithHits, 8, 25, 0xff888888); + } + if (skippedFiles != null) { + drawString(fontRendererObj, skippedFiles, 8, 35, 0xff888888); } if (resultsCount != null) { - drawString(fontRendererObj, resultsCount, 8, 48, 0xff888888); + drawString(fontRendererObj, resultsCount, 8, 50, 0xff888888); } } if (errorMessage != null) { diff --git a/src/main/java/de/cowtipper/cowlection/search/LogFilesSearcher.java b/src/main/java/de/cowtipper/cowlection/search/LogFilesSearcher.java index c6b647e..bbfd0fb 100644 --- a/src/main/java/de/cowtipper/cowlection/search/LogFilesSearcher.java +++ b/src/main/java/de/cowtipper/cowlection/search/LogFilesSearcher.java @@ -2,18 +2,15 @@ package de.cowtipper.cowlection.search; import de.cowtipper.cowlection.config.MooConfig; import net.minecraft.util.EnumChatFormatting; +import org.apache.commons.io.FileUtils; import org.apache.commons.lang3.StringUtils; -import org.apache.commons.lang3.tuple.ImmutableTriple; import java.io.*; import java.nio.file.Files; import java.nio.file.Path; import java.time.*; import java.util.ArrayList; -import java.util.Collections; -import java.util.Comparator; import java.util.List; -import java.util.concurrent.atomic.AtomicInteger; import java.util.regex.Matcher; import java.util.regex.Pattern; import java.util.stream.Collectors; @@ -32,9 +29,9 @@ class LogFilesSearcher { 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; - ImmutableTriple<Integer, Integer, List<LogEntry>> searchFor(String searchQuery, boolean chatOnly, boolean matchCase, boolean removeFormatting, LocalDate dateStart, LocalDate dateEnd) throws IOException { - AtomicInteger foundLogs = new AtomicInteger(); - List<LogEntry> searchResults = Collections.synchronizedList(new ArrayList<>()); + LogSearchResults searchFor(String searchQuery, boolean chatOnly, boolean matchCase, boolean removeFormatting, LocalDate dateStart, LocalDate dateEnd) throws IOException { + LogSearchResults logSearchResults = new LogSearchResults(); + long fileSizeLimit = MooConfig.getMaxLogFileSize(); for (String logsDirPath : MooConfig.logsDirs) { File logsDir = new File(logsDirPath); if (!logsDir.exists() || !logsDir.isDirectory()) { @@ -55,15 +52,25 @@ class LogFilesSearcher { LocalDate fileLocalDate = LocalDate.of(Integer.parseInt(fileNameMatcher.group(1)), Integer.parseInt(fileNameMatcher.group(2)), Integer.parseInt(fileNameMatcher.group(3))); if (!fileLocalDate.isBefore(dateStart) && !fileLocalDate.isAfter(dateEnd)) { - foundLogs.incrementAndGet(); - searchResults.addAll(analyzeFile(path, true, fileLocalDate, searchQuery, chatOnly, matchCase, removeFormatting)); + if (path.toFile().length() > fileSizeLimit) { + // file too large + logSearchResults.addSkippedFile(); + } else { + logSearchResults.addAnalyzedFile(); + logSearchResults.addSearchResults(analyzeFile(path, true, fileLocalDate, searchQuery, chatOnly, matchCase, removeFormatting)); + } } } } else if (fileName.equals("latest.log")) { LocalDate lastModified = Instant.ofEpochMilli(path.toFile().lastModified()).atZone(ZoneId.systemDefault()).toLocalDate(); if (!lastModified.isBefore(dateStart) && !lastModified.isAfter(dateEnd)) { - foundLogs.incrementAndGet(); - searchResults.addAll(analyzeFile(path, false, lastModified, searchQuery, chatOnly, matchCase, removeFormatting)); + if (path.toFile().length() > fileSizeLimit) { + // file too large + logSearchResults.addSkippedFile(); + } else { + logSearchResults.addAnalyzedFile(); + logSearchResults.addSearchResults(analyzeFile(path, false, lastModified, searchQuery, chatOnly, matchCase, removeFormatting)); + } } } }); @@ -73,12 +80,21 @@ class LogFilesSearcher { } } - if (foundLogs.get() == 0) { - throw new FileNotFoundException(EnumChatFormatting.DARK_RED + "ERROR: No Minecraft log files could be found for the selected date range. Please check if the dates as well as the directories of the log files are set correctly (Log Search ➡ Settings)."); + if (logSearchResults.getAnalyzedFiles() == 0) { + // no files were analyzed + int skippedFileCounter = logSearchResults.getSkippedFiles(); + if (skippedFileCounter > 0) { + throw new FileNotFoundException(EnumChatFormatting.DARK_RED + "ERROR: No Minecraft log files could be found for the selected date range.\n" + + EnumChatFormatting.RED + skippedFileCounter + EnumChatFormatting.DARK_RED + " log files were skipped because they are too large ( >" + FileUtils.byteCountToDisplaySize(MooConfig.getMaxLogFileSize()) + ").\n" + + EnumChatFormatting.RED + "Please check if the dates as well as the directories of the log files are set correctly (Log Search ➡ Settings [top right corner]).\n" + + EnumChatFormatting.DARK_RED + "You could also increase the maximum allowed log file size to be searched (Log Search ➡ Settings), but note that each file must be unzipped before it can be analyzed, which can make the log file search take significantly longer for large files."); + } else { + throw new FileNotFoundException(EnumChatFormatting.DARK_RED + "ERROR: No Minecraft log files could be found for the selected date range.\n" + + EnumChatFormatting.RED + "Please check if the dates as well as the directories of the log files are set correctly (Log Search ➡ Settings [top right corner])."); + } } else { - List<LogEntry> sortedSearchResults = searchResults - .stream().sorted(Comparator.comparing(LogEntry::getTime)).collect(Collectors.toList()); - return new ImmutableTriple<>(foundLogs.get(), analyzedFilesWithHits, sortedSearchResults); + logSearchResults.setAnalyzedFilesWithHits(analyzedFilesWithHits); + return logSearchResults; } } diff --git a/src/main/java/de/cowtipper/cowlection/search/LogSearchResults.java b/src/main/java/de/cowtipper/cowlection/search/LogSearchResults.java new file mode 100644 index 0000000..2b7ce80 --- /dev/null +++ b/src/main/java/de/cowtipper/cowlection/search/LogSearchResults.java @@ -0,0 +1,53 @@ +package de.cowtipper.cowlection.search; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.Comparator; +import java.util.List; +import java.util.concurrent.atomic.AtomicInteger; +import java.util.stream.Collectors; + +public class LogSearchResults { + private final AtomicInteger analyzedFiles; + private final AtomicInteger skippedFiles; + private final List<LogEntry> searchResults; + private int analyzedFilesWithHits; + + public LogSearchResults() { + this.analyzedFiles = new AtomicInteger(); + this.skippedFiles = new AtomicInteger(); + this.searchResults = Collections.synchronizedList(new ArrayList<>()); + } + + public void addAnalyzedFile() { + analyzedFiles.incrementAndGet(); + } + + public void addSkippedFile() { + skippedFiles.incrementAndGet(); + } + + public void addSearchResults(List<LogEntry> newResults) { + searchResults.addAll(newResults); + } + + public void setAnalyzedFilesWithHits(int analyzedFilesWithHits) { + this.analyzedFilesWithHits = analyzedFilesWithHits; + } + + public int getAnalyzedFiles() { + return analyzedFiles.get(); + } + + public int getSkippedFiles() { + return skippedFiles.get(); + } + + public List<LogEntry> getSortedSearchResults() { + return searchResults.stream().sorted(Comparator.comparing(LogEntry::getTime)).collect(Collectors.toList()); + } + + public int getAnalyzedFilesWithHits() { + return analyzedFilesWithHits; + } +} |
