Hide Saving Replay popup when no output is produced (fixes #420)
I.e. if the had Auto-Recording disabled and never pressed start, there won't be any replays and it would just be the Done button, which is pointless.
This commit is contained in:
@@ -53,6 +53,10 @@ public class MarkerProcessor {
|
||||
}
|
||||
}
|
||||
|
||||
public static boolean producesAnyOutput(ReplayFile replayFile) throws IOException {
|
||||
return !getOutputSuffixes(replayFile).isEmpty();
|
||||
}
|
||||
|
||||
private enum OutputState {
|
||||
/** A new output file has begun but not data has been written yet. */
|
||||
NotYetWriting,
|
||||
|
||||
@@ -39,6 +39,7 @@ import net.minecraft.network.Packet;
|
||||
import net.minecraft.network.PacketByteBuf;
|
||||
import net.minecraft.text.LiteralText;
|
||||
import net.minecraft.util.crash.CrashReport;
|
||||
import org.apache.commons.io.FilenameUtils;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
|
||||
@@ -65,6 +66,7 @@ import net.minecraft.network.NetworkSide;
|
||||
import java.io.DataOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.OutputStream;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
@@ -266,6 +268,23 @@ public class PacketListener extends ChannelInboundHandlerAdapter {
|
||||
List<Pair<Path, ReplayMetaData>> outputPaths;
|
||||
synchronized (replayFile) {
|
||||
try {
|
||||
if (!MarkerProcessor.producesAnyOutput(replayFile)) {
|
||||
// Immediately close the saving popup, the user doesn't care about it
|
||||
core.runLater(guiSavingReplay::close);
|
||||
|
||||
// We still have the replay, so we just save it (at least for a few weeks) in case they change their mind
|
||||
String replayName = FilenameUtils.getBaseName(outputPath.getFileName().toString());
|
||||
Path rawFolder = ReplayMod.instance.getRawReplayFolder();
|
||||
Path rawPath = rawFolder.resolve(outputPath.getFileName());
|
||||
for (int i = 1; Files.exists(rawPath); i++) {
|
||||
rawPath = rawPath.resolveSibling(replayName + "." + i + ".mcpr");
|
||||
}
|
||||
Files.createDirectories(rawPath.getParent());
|
||||
replayFile.saveTo(rawPath.toFile());
|
||||
replayFile.close();
|
||||
return;
|
||||
}
|
||||
|
||||
replayFile.save();
|
||||
replayFile.close();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user