Improves output logging and fixes some bugs

Fixes an error caused by the BuildTools directory not being created
Creates functions for writing to files in CommonFunctions
Adds some more error info to the log when BuildTools fails to download
Fixes some typos
Makes sure all visible text is logged
This commit is contained in:
2021-08-03 15:22:04 +02:00
parent 28291cf4c3
commit e47b34a472
9 changed files with 109 additions and 32 deletions

View File

@ -1,7 +1,11 @@
package net.knarcraft.minecraftserverlauncher.userinterface;
import net.knarcraft.minecraftserverlauncher.Main;
import net.knarcraft.minecraftserverlauncher.utility.CommonFunctions;
import javax.swing.*;
import java.io.BufferedWriter;
import java.io.File;
import java.io.IOException;
import java.io.OutputStreamWriter;
@ -12,6 +16,7 @@ public abstract class MessageHandler implements GUI {
private final boolean silent;
private final BufferedWriter writer;
private final String logFile = Main.getApplicationWorkDirectory() + File.separator + "latestrun.log";
/***
* Initializes a new message handler
@ -23,11 +28,29 @@ public abstract class MessageHandler implements GUI {
this.writer = new BufferedWriter(new OutputStreamWriter(System.out));
}
@Override
public void logMessage(String message) {
try {
CommonFunctions.appendFile(logFile, "[Info]: " + message);
} catch (IOException e) {
e.printStackTrace();
}
}
@Override
public void logError(String message) {
try {
CommonFunctions.appendFile(logFile, "[Error]: " + message);
} catch (IOException e) {
e.printStackTrace();
}
}
@Override
public void showError(String title, String message) {
if (silent) {
try {
writer.write("Error: ");
writer.write("[Error]: ");
writer.write(message);
writer.newLine();
writer.flush();
@ -37,6 +60,7 @@ public abstract class MessageHandler implements GUI {
} else {
showJOptionPane(title, message, JOptionPane.ERROR_MESSAGE);
}
logError(message);
}
@Override
@ -48,7 +72,7 @@ public abstract class MessageHandler implements GUI {
public void showMessage(String title, String message) {
if (silent) {
try {
writer.write(message);
writer.write("[Info]: " + message);
writer.newLine();
writer.flush();
} catch (IOException e) {
@ -57,6 +81,7 @@ public abstract class MessageHandler implements GUI {
} else {
showJOptionPane(title, message, JOptionPane.INFORMATION_MESSAGE);
}
logMessage(message);
}
@Override