From 31a70f81aa569348b82a19dc9090846a111220fd Mon Sep 17 00:00:00 2001 From: John Doe Date: Thu, 25 Aug 2022 14:33:04 +0200 Subject: [PATCH] added option to strip color codes, redesigned the ui and fixed an issue issue with the log file encoding --- bin/.gitignore | 1 + src/icons/icon-more-20.png | Bin 0 -> 4200 bytes src/main/MainWindow.java | 101 +++++++++++++++++++++---------------- src/util/MCLogFile.java | 10 ++-- src/util/MCLogLine.java | 4 +- 5 files changed, 67 insertions(+), 49 deletions(-) create mode 100644 src/icons/icon-more-20.png diff --git a/bin/.gitignore b/bin/.gitignore index a876348..057c8e6 100644 --- a/bin/.gitignore +++ b/bin/.gitignore @@ -1,2 +1,3 @@ /main/ +/icons/ /util/ diff --git a/src/icons/icon-more-20.png b/src/icons/icon-more-20.png new file mode 100644 index 0000000000000000000000000000000000000000..6d34b6c116f6703f0e90781a73e383f12bb61382 GIT binary patch literal 4200 zcmV-u5SQ zaB^>EX>4U6ba`-PAZ2)IW&i+q+U=QJa^^UWh2Ob~Spx4Mmjm7+W(TwU`9R5bIy0-g zs=Hr0qWq_S$&^Hbz`??h|(eaF*JzO1j0IQi{`P<|RupUcD_7fzoR z#qSsP^yioDyuatHcFulwr@7+M`XcH&`@=(at8fqz9RRh;^s>GQ*n#`EOO35_n(NIBXqyU z?Ke?dR_Er8*pr3kQ=iB_uJ5KUHnpOr|L*bciTYnsUXCP4$$fqpQdvbCaCWF;^-ah3*!PV;>a z3ntF8Yi4&+b#HdsXgPL10r8-#-S7hqnHgsrFwA5FhS>-%q(wP9*E1LzwO>fYg;BC` zlOI%sQd)9Ug0bd~GvmlY4VbvdTyrQN=GG1X1Eqo!bI@LJHGADhwTmG{#T@T|$X&gs z8!#ZUchPvGkDHd{1awR7C3OPgtn?!7ExNbIsn;kp+UJKECGmNxzO>CEqWW@nDI+YwSj zf=XdV+#%s~Nt3|NF&du9o+J!Ya%9f62l+EA2#84*rEiTy(ymZPNzICB#Gjdv?44%X z_@1IZ$vZ0K#Yf9~eZY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b3T($}DYPt!xyrPKB9o*M-2FpVd_TO-GZp zmX7u1^ZN36br`>+8i8)Q|(wIquR#7p?WYa!#`D(%vOF&^2v~+P+ zr&lIq7Y~P~SLJbNvfKv9^tDCjjirp7E0BvBhkm38Tg98M$Armf{t81tb=s>j6n70O zGe&^s2x4hE&-CNwJ+kP{Y44w`hDL5;w?h08LJhJlv1U4n{BTWrdGf(}NW}`Un0e*} zdLFul9rN05n?(29^b>eZ8=jzTE4!^kBY{vu+=R9B>PGjIsYRU%asdm^KLsgNI%&t)wvHUwpLnGcPwikzIoKLWW2U8L2`r*7sT(QA4FhFF zZ=-D++NmPi`i%@8yYFWpNpIbyx3-Al^Lh$I(U?b|n=w$Z$?9T*_nF_Q%{?9F{OmAm znpO+BF4jn{xcSK^ZbY8!O?uKO%*~ncXS%#y)zz~9d1jr;c-rOabThGA7)&UdqW*V|RKJ0Nl@-$qr0f*41 zqH32luQy=Sv~5a?yNJh(*W_&InAXI0+O2$#`%+wC)o%a;BFP+)YX0GuWRUHjrK`zb2X(%&F^~GJS3Y-4B$G<1~d!oPopuNRf-TgnHkqt)# zsJ8q700D(*LqkwWLqi~Na&Km7Y-Iodc$|HaJxIeq9K~N#rKMCH?4aV1p*mUc3vrYx z7QsSkE41oha_NWAq#;RhaTHt&4t^|F9bBAsb#N5~!4D8eCnrT0De-?vp+$@b$NhMB z?{W7I5E>Pxnq6ans#!)l5f^j$6*2INAO;Y^I06zg^<-ut3(xU&41FWkIhk|j(YJs1Km7ZD=Fzu*zC9N ziQDhJLYBj(mxDI@E=KtkpWFL7QHOL|NWk~Xx}{-BLzP1^AA35`Th6*9Arhi yue?fPU|^Wb$iVP_*Ok|a$Z~}Aj)GA@Bme**i*Zn>&F*Xf0000 additionalFolderPaths = new TreeSet<>(); private LogRecords logRecords; private int tmpStauslength = 0; private JPanel panel_south; - private Component horizontalGlue_3; + private JMenuBar menuBar; + private JMenu mnOptionsMenu; + private JMenuItem addFoldersButtonMenuItem; + private JCheckBoxMenuItem onlyChatCheckBoxMenu; + private Component horizontalGlue_1; + private Button defaultButton; + private Component horizontalGlue_2; + private JCheckBoxMenuItem stripColorCodesCheckBoxMenu; /** * Create the frame. @@ -86,34 +92,34 @@ public MainWindow() { contentPane.add(panel_north, BorderLayout.NORTH); panel_north.setLayout(new BoxLayout(panel_north, BoxLayout.X_AXIS)); - horizontalGlue = Box.createHorizontalGlue(); - panel_north.add(horizontalGlue); + horizontalGlue_2 = Box.createHorizontalGlue(); + panel_north.add(horizontalGlue_2); defaultButton = new Button("Start analyzing currently known .minecraft folders"); - defaultButton.setBackground(new Color(240, 248, 255)); defaultButton.addActionListener(new ActionListener() { - @Override - public void actionPerformed(ActionEvent arg0) { + public void actionPerformed(ActionEvent e) { startAnalysis(); } }); - panel_north.add(defaultButton); defaultButton.setForeground(Color.BLUE); defaultButton.setFont(new Font("Consolas", Font.PLAIN, 14)); - - horizontalGlue_3 = Box.createHorizontalGlue(); - panel_north.add(horizontalGlue_3); + defaultButton.setBackground(new Color(240, 248, 255)); + panel_north.add(defaultButton); - onlyChatCheckBox = new Checkbox("Only filter chat lines"); - onlyChatCheckBox.setState(true); - onlyChatCheckBox.setFont(new Font("Consolas", Font.PLAIN, 14)); - panel_north.add(onlyChatCheckBox); + menuBar = new JMenuBar(); + menuBar.setBorderPainted(false); + panel_north.add(menuBar); - horizontalGlue_2 = Box.createHorizontalGlue(); - panel_north.add(horizontalGlue_2); + mnOptionsMenu = new JMenu(""); + mnOptionsMenu.setIcon(new ImageIcon(MainWindow.class.getResource("/icons/icon-more-20.png"))); + mnOptionsMenu.setSize(20, 20); + mnOptionsMenu.setHorizontalAlignment(SwingConstants.RIGHT); + mnOptionsMenu.setFont(new Font("Consolas", Font.PLAIN, 14)); + menuBar.add(mnOptionsMenu); - addFoldersButton = new Button("Add custom .minecraft folder locations"); - addFoldersButton.addActionListener(new ActionListener() { + addFoldersButtonMenuItem = new JMenuItem("Add custom .minecraft folder locations"); + addFoldersButtonMenuItem.setFont(new Font("Consolas", Font.PLAIN, 14)); + addFoldersButtonMenuItem.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { EventQueue.invokeLater(new Runnable() { @@ -129,10 +135,17 @@ public void run() { }); } }); - addFoldersButton.setBackground(new Color(255, 240, 245)); - panel_north.add(addFoldersButton); - addFoldersButton.setForeground(new Color(153, 0, 102)); - addFoldersButton.setFont(new Font("Consolas", Font.PLAIN, 14)); + mnOptionsMenu.add(addFoldersButtonMenuItem); + + stripColorCodesCheckBoxMenu = new JCheckBoxMenuItem("Strip color codes"); + stripColorCodesCheckBoxMenu.setSelected(true); + stripColorCodesCheckBoxMenu.setFont(new Font("Consolas", Font.PLAIN, 14)); + mnOptionsMenu.add(stripColorCodesCheckBoxMenu); + + onlyChatCheckBoxMenu = new JCheckBoxMenuItem("Only filter chat lines"); + onlyChatCheckBoxMenu.setFont(new Font("Consolas", Font.PLAIN, 14)); + onlyChatCheckBoxMenu.setSelected(true); + mnOptionsMenu.add(onlyChatCheckBoxMenu); horizontalGlue_1 = Box.createHorizontalGlue(); panel_north.add(horizontalGlue_1); @@ -174,7 +187,19 @@ public void run() { scrollPaneBottom.setViewportView(statusTextField); } - private synchronized void analyze(boolean onlyChat) { + private void startAnalysis() { + defaultButton.setEnabled(false); + addFoldersButtonMenuItem.setEnabled(false); + Thread t0 = new Thread() { + @Override + public void run() { + mainWindow.analyze(onlyChatCheckBoxMenu.getState(), stripColorCodesCheckBoxMenu.getState()); + } + }; + t0.start(); + } + + private synchronized void analyze(boolean onlyChat, boolean stripColorCodes) { try { OSFileSystem fileSystem = new OSFileSystem(mainWindow); ArrayList minecraftLogFolders = fileSystem.lookForMinecraftLogFolders(); @@ -215,7 +240,7 @@ public int compare(File f1, File f2) { addStatusTemporaryly( "INFO: Loading " + fileCount + " files - " + (counter * 100 / fileCount) + "%"); try { - minecraftLogFile = new MCLogFile(logFile, getPreviousFileInFolder(counter, allFiles), onlyChat); + minecraftLogFile = new MCLogFile(logFile, getPreviousFileInFolder(counter, allFiles), onlyChat, stripColorCodes); if (minecraftLogFile.getPlayerName() != null) { lastLoginName = minecraftLogFile.getPlayerName(); playerNames.put(lastLoginName, playerNames.getOrDefault(lastLoginName, 0) + 1); @@ -251,7 +276,7 @@ public int compare(File f1, File f2) { setOutput(sb.toString()); addStatus("INFO: Found " + logRecords.size() + " results!"); defaultButton.setEnabled(true); - addFoldersButton.setEnabled(true); + addFoldersButtonMenuItem.setEnabled(true); } catch (Exception e) { addStatus("ERROR: " + e.toString()); StringBuilder sb = new StringBuilder(); @@ -281,18 +306,6 @@ public void run() { }); } - private void startAnalysis() { - defaultButton.setEnabled(false); - addFoldersButton.setEnabled(false); - Thread t0 = new Thread() { - @Override - public void run() { - mainWindow.analyze(onlyChatCheckBox.getState()); - } - }; - t0.start(); - } - /** * Adds a new line of text to the outputTextField * diff --git a/src/util/MCLogFile.java b/src/util/MCLogFile.java index edd848c..cd76fe1 100644 --- a/src/util/MCLogFile.java +++ b/src/util/MCLogFile.java @@ -16,19 +16,22 @@ public class MCLogFile { private static String tmpPlayerName; // needs to be static. Streams are weird... + private boolean stripColorCodes; private long creationTime; private Long startingTimeOfFile; private String playerName; private Stream linesStream; - public MCLogFile(File logFile, File previousLogFile, boolean onlyChat) throws FileNotFoundException, IOException { + public MCLogFile(File logFile, File previousLogFile, boolean onlyChat, boolean stripColorCodes) + throws FileNotFoundException, IOException { + this.stripColorCodes = stripColorCodes; creationTime = previousLogFile != null ? getCreationTime(previousLogFile) : getCreationTime(logFile) - 21600000; startingTimeOfFile = null; InputStream inputStream = new FileInputStream(logFile); if (logFile.getName().endsWith(".gz")) inputStream = new GZIPInputStream(inputStream); @SuppressWarnings("resource") - BufferedReader br = new BufferedReader(new InputStreamReader(inputStream, "UTF-8")); + BufferedReader br = new BufferedReader(new InputStreamReader(inputStream, "ISO-8859-1")); final String userSettingLine = "\\[[0-9:]{8}\\] \\[Client thread/INFO\\]: Setting user: "; linesStream = br.lines().filter(a -> { if (tmpPlayerName == null && a.matches(userSettingLine + ".*")) @@ -53,7 +56,8 @@ public String getPlayerName() { public List filterLines(String logLineFilterRegex, String lastPlayerName) { List filteredlogLines = linesStream .map(a -> new MCLogLine(getTime(creationTime, a.substring(1, 9)), lastPlayerName, - a.replaceAll("\\[[0-9:]{8}\\] \\[Client thread/INFO\\]: \\[CHAT\\] ", "").trim())) + a.replaceAll("\\[[0-9:]{8}\\] \\[Client thread/INFO\\]: \\[CHAT\\] ", "").trim(), + stripColorCodes)) .filter(a -> a.getText().matches(logLineFilterRegex)).collect(Collectors.toList()); linesStream.close(); return filteredlogLines; diff --git a/src/util/MCLogLine.java b/src/util/MCLogLine.java index a917012..67e67ab 100644 --- a/src/util/MCLogLine.java +++ b/src/util/MCLogLine.java @@ -9,10 +9,10 @@ public class MCLogLine implements Comparable { private String playerName; private String text; - public MCLogLine(long creationTime, String playerName, String text) { + public MCLogLine(long creationTime, String playerName, String text, boolean stripColorCodes) { this.creationTime = creationTime; this.playerName = playerName; - this.text = text; + this.text = stripColorCodes ? text.replaceAll("§.", "") : text; } public long getCreationTime() {