Skip to content

Commit

Permalink
fixed paths for Linux & MacOS
Browse files Browse the repository at this point in the history
  • Loading branch information
RaderRMT committed Dec 14, 2020
1 parent 2945859 commit 5db46d5
Show file tree
Hide file tree
Showing 4 changed files with 71 additions and 18 deletions.
16 changes: 14 additions & 2 deletions fr/rader/billy/Logger.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,22 @@

public class Logger {

private final File LOG_OUTPUT = new File(System.getenv("APPDATA") + "/.minecraft/logs/billy.log");
private File LOG_OUTPUT;

private List<String> unusedFields = new ArrayList<>();

public Logger() {
String os = System.getProperty("os.name").toLowerCase();

if(os.contains("windows")) {
LOG_OUTPUT = new File(System.getenv("APPDATA") + "/.minecraft/logs/billy.log");
} else if(os.contains("nix") || os.contains("nux") || os.contains("aix")) {
LOG_OUTPUT = new File("~/.minecraft/logs/billy.log");
} else if(os.contains("mac")) {
LOG_OUTPUT = new File("~/Library/Application Support/minecraft/logs/billy.log");
}
}

public void writeln(String message) {
write(message + "\n");
}
Expand Down Expand Up @@ -103,7 +115,7 @@ public void exception(Exception exception, String replay) {
writeln("Timelines dump: " + replay);

JOptionPane.showMessageDialog(null, "ERROR: " + exception.getLocalizedMessage() +
"\nPlease open an issue on https://github.com/Nemos59/Billy/issues, and provide the \".minecraft\\logs\\billy.log\" file.");
"\nPlease open an issue on https://github.com/Nemos59/Billy/issues, and provide the \".minecraft/logs/billy.log\" file.");
}

public void printUnused(String replay) {
Expand Down
2 changes: 2 additions & 0 deletions fr/rader/billy/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ private void start() {
logger.writeln("Current date is: " + logger.currentDate());

logger.writeln("Checking folders...");
OpenReplayListener.setupPaths();

// Check if every folders exists
File toCheck = new File(OpenReplayListener.REPLAY_RECORDINGS);
if(!toCheck.exists()) JOptionPane.showMessageDialog(null, "The replay_recordings folder does not exist.");
Expand Down
67 changes: 53 additions & 14 deletions fr/rader/billy/gui/main/listeners/OpenReplayListener.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package fr.rader.billy.gui.main.listeners;

import com.google.gson.Gson;
import fr.rader.billy.Logger;
import fr.rader.billy.Main;
import fr.rader.billy.gui.main.MainInterface;
Expand All @@ -12,31 +13,52 @@
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.StandardCopyOption;
import java.util.HashMap;
import java.util.Locale;
import java.util.Map;

public class OpenReplayListener implements ActionListener {

private static Logger logger = Main.getInstance().getLogger();

public static final String REPLAY_RECORDINGS = System.getenv("APPDATA") + "\\.minecraft\\replay_recordings\\";
public static final String LEFT_SIDE = REPLAY_RECORDINGS + "extracted_timelines\\left\\";
public static final String RIGHT_SIDE = REPLAY_RECORDINGS + "extracted_timelines\\right\\";
public static String REPLAY_RECORDINGS;
public static String LEFT_SIDE;
public static String RIGHT_SIDE;

private static File[] files = new File[] {
new File(REPLAY_RECORDINGS),
new File(""),
new File("")
};
private static File[] files;

private static boolean hasTimeline = true;
private static boolean hasNewReplay = false;

private static TimelineSerialization serialization;
private static MainInterface mainInterface;

public static void setupPaths() {
String os = System.getProperty("os.name").toLowerCase();

if(os.contains("windows")) {
REPLAY_RECORDINGS = System.getenv("APPDATA") + "/.minecraft/replay_recordings/";
} else if(os.contains("nix") || os.contains("nux") || os.contains("aix")) {
REPLAY_RECORDINGS = "~/.minecraft/replay_recordings/";
} else if(os.contains("mac")) {
REPLAY_RECORDINGS = "~/Library/Application Support/minecraft/replay_recordings/";
}

LEFT_SIDE = REPLAY_RECORDINGS + "extracted_timelines/left/";
RIGHT_SIDE = REPLAY_RECORDINGS + "extracted_timelines/right/";

files = new File[] {
new File(REPLAY_RECORDINGS),
new File(""),
new File("")
};
}

@Override
public void actionPerformed(ActionEvent e) {
serialization = new TimelineSerialization();
Expand All @@ -47,15 +69,15 @@ public void actionPerformed(ActionEvent e) {

openReplay(openFilePrompt(), side);

startLoadingReplay(side, isOpenLeft);
startLoadingReplay(side, isOpenLeft, getVersion(files[1]));
}

private static void startLoadingReplay(String side, boolean isOpenLeft) {
private static void startLoadingReplay(String side, boolean isOpenLeft, String version) {
if(hasNewReplay) {
if(isOpenLeft && !files[1].equals(new File(""))) { // left side
mainInterface.openLeftReplayButton.setText(files[1].getName());
mainInterface.openLeftReplayButton.setText(files[1].getName() + " (" + version + ")");
} else if(!isOpenLeft && !files[2].equals(new File(""))) { // right side
mainInterface.openRightReplayButton.setText(files[2].getName());
mainInterface.openRightReplayButton.setText(files[2].getName() + " (" + version + ")");
}

if(isOpenLeft) {
Expand Down Expand Up @@ -146,6 +168,23 @@ public String getDescription() {
return null;
}

public static String getVersion(File file) {
try {
ZipFile mcprFile = new ZipFile(file);
mcprFile.extractFile("metaData.json", REPLAY_RECORDINGS + "/extracted_timelines/");

Gson gson = new Gson();

Map<?, ?> map = gson.fromJson(new FileReader(new File(REPLAY_RECORDINGS + "/extracted_timelines/metaData.json")), Map.class);

return map.get("mcversion").toString();
} catch (FileNotFoundException | ZipException e) {
e.printStackTrace();
}

return null;
}

public static File getRightFile() {
return files[2];
}
Expand All @@ -159,7 +198,7 @@ public static void refreshLeft() {
logger.writeln("Refreshing left replay...");
hasNewReplay = true;
openReplay(files[1], LEFT_SIDE);
startLoadingReplay(LEFT_SIDE, true);
startLoadingReplay(LEFT_SIDE, true, getVersion(files[1]));
}
}

Expand All @@ -168,7 +207,7 @@ public static void refreshRight() {
logger.writeln("Refreshing right replay...");
hasNewReplay = true;
openReplay(files[2], RIGHT_SIDE);
startLoadingReplay(RIGHT_SIDE, false);
startLoadingReplay(RIGHT_SIDE, false, getVersion(files[1]));
}
}
}
4 changes: 2 additions & 2 deletions fr/rader/billy/gui/main/listeners/SaveReplayListener.java
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ private void saveTimeline(String serializedTimeline, String timelinesFile, File
ZipFile outMcpr = new ZipFile(mcprFile);
outMcpr.addFile(timelinesFile);

JOptionPane.showMessageDialog(null, "Saved to " + mcprFile.getAbsolutePath().replace("/", "\\"));
JOptionPane.showMessageDialog(null, "Saved to " + mcprFile.getAbsolutePath());
return;
}

Expand All @@ -122,7 +122,7 @@ private void saveTimeline(String serializedTimeline, String timelinesFile, File
return;
}

JOptionPane.showMessageDialog(null, "Saved to " + timelinesFile.replace("/", "\\"));
JOptionPane.showMessageDialog(null, "Saved to " + timelinesFile);
} catch (IOException ioException) {
logger.exception(ioException);

Expand Down

0 comments on commit 5db46d5

Please sign in to comment.