Remember last export folder & ensure default output name is unique

This commit is contained in:
Moulberry committed 2024-08-26 14:46:00 +08:00
1 parent c4217d1acd
commit b8b22db8ee
1 file changed
+11 -1
@@ -26,6 +26,7 @@ import net.minecraft.client.Minecraft;
import net.minecraft.client.player.LocalPlayer;
import org.jetbrains.annotations.Nullable;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.concurrent.CompletableFuture;
@@ -50,6 +51,7 @@ public class StartExportWindow {
private static boolean recordAudio = false;
private static AudioCodec audioCodec = AudioCodec.AAC;
private static Path defaultExportPath = null;
private static final ImString jobName = ImGuiHelper.createResizableImString("");
static {
@@ -214,7 +216,9 @@ public class StartExportWindow {
String encoder = videoCodec.getEncoders()[selectedVideoEncoder[0]];
Path defaultExportPath = FabricLoader.getInstance().getGameDir();
if (defaultExportPath == null || !Files.exists(defaultExportPath)) {
defaultExportPath = FabricLoader.getInstance().getGameDir();
}
String defaultName = null;
if (name != null) {
@@ -222,6 +226,11 @@ public class StartExportWindow {
defaultName = FileUtil.findAvailableName(defaultExportPath, name, "." + container.extension());
} catch (Exception ignored) {}
}
if (defaultName == null) {
try {
defaultName = FileUtil.findAvailableName(defaultExportPath, "output", "." + container.extension());
} catch (Exception ignored) {}
}
if (defaultName == null) {
defaultName = "output." + container.extension();
}
@@ -251,6 +260,7 @@ public class StartExportWindow {
}
Path path = Path.of(pathStr);
defaultExportPath = path.getParent();
return new ExportSettings(name, editorState.copy(),
player.position(), player.getYRot(), player.getXRot(),
resolution[0], resolution[1], start, end,