From 39717c31440376ffd9467d9a4a27d5db6cfecdbf Mon Sep 17 00:00:00 2001 From: Moritz Zwerger Date: Tue, 24 Jun 2025 23:39:25 +0200 Subject: [PATCH] don't use File::slashpath, fix some date formatting --- .../minosoft/gui/eros/crash/ErosCrashReport.kt | 13 +++++++++---- .../minosoft/gui/rendering/util/ScreenshotTaker.kt | 2 +- .../minosoft/util/crash/freeze/FreezeDump.kt | 6 ++++-- .../minosoft/util/crash/freeze/FreezeDumpUtil.kt | 11 +++++++++-- 4 files changed, 23 insertions(+), 9 deletions(-) diff --git a/src/main/java/de/bixilon/minosoft/gui/eros/crash/ErosCrashReport.kt b/src/main/java/de/bixilon/minosoft/gui/eros/crash/ErosCrashReport.kt index 03b41aaec..35ce83f49 100644 --- a/src/main/java/de/bixilon/minosoft/gui/eros/crash/ErosCrashReport.kt +++ b/src/main/java/de/bixilon/minosoft/gui/eros/crash/ErosCrashReport.kt @@ -29,6 +29,7 @@ import de.bixilon.minosoft.gui.eros.util.JavaFXUtil import de.bixilon.minosoft.protocol.network.session.play.PlaySession import de.bixilon.minosoft.terminal.RunConfiguration import de.bixilon.minosoft.util.KUtil.div +import de.bixilon.minosoft.util.KUtil.format1 import de.bixilon.minosoft.util.crash.CrashReportUtil import de.bixilon.minosoft.util.logging.Log import de.bixilon.minosoft.util.logging.LogLevels @@ -43,9 +44,12 @@ import javafx.scene.text.TextFlow import javafx.stage.Modality import javafx.stage.Stage import javafx.stage.Window +import java.io.File import java.io.FileOutputStream import java.nio.charset.StandardCharsets import java.text.SimpleDateFormat +import kotlin.time.Clock +import kotlin.time.ExperimentalTime class ErosCrashReport : JavaFXWindowController() { @@ -54,13 +58,13 @@ class ErosCrashReport : JavaFXWindowController() { @FXML private lateinit var detailsFX: TextArea - var crashReportPath: String? = null + var crashReportPath: File? = null set(value) { field = value JavaFXUtil.runLater { crashReportPathDescriptionFX.isVisible = value != null if (value != null) { - crashReportPathFX.text = value + crashReportPathFX.text = value.path } } } @@ -81,6 +85,7 @@ class ErosCrashReport : JavaFXWindowController() { UnsafeUtil.hardCrash() } + @OptIn(ExperimentalTime::class) companion object { var alreadyCrashed = false private set @@ -116,12 +121,12 @@ class ErosCrashReport : JavaFXWindowController() { }) - var crashReportPath: String? + var crashReportPath: File? try { val crashReportFolder = (RunConfiguration.HOME_DIRECTORY / "crash-reports").toFile() crashReportFolder.mkdirs() - crashReportPath = "${crashReportFolder.slashPath}/crash-${SimpleDateFormat("yyyy-MM-dd-HH.mm.ss").format(System.currentTimeMillis())}.txt" + crashReportPath = crashReportFolder / "crash-${SimpleDateFormat("yyyy-MM-dd-HH.mm.ss").format1(Clock.System.now())}.txt" val stream = FileOutputStream(crashReportPath) diff --git a/src/main/java/de/bixilon/minosoft/gui/rendering/util/ScreenshotTaker.kt b/src/main/java/de/bixilon/minosoft/gui/rendering/util/ScreenshotTaker.kt index aaf2f7d2c..f31a9a73a 100644 --- a/src/main/java/de/bixilon/minosoft/gui/rendering/util/ScreenshotTaker.kt +++ b/src/main/java/de/bixilon/minosoft/gui/rendering/util/ScreenshotTaker.kt @@ -71,7 +71,7 @@ class ScreenshotTaker( component += TextComponent(file.name).apply { color = ChatColors.WHITE underline() - clickEvent = OpenFileClickEvent(file.slashPath) + clickEvent = OpenFileClickEvent(file) hoverEvent = TextHoverEvent("Click to open") } component += " " diff --git a/src/main/java/de/bixilon/minosoft/util/crash/freeze/FreezeDump.kt b/src/main/java/de/bixilon/minosoft/util/crash/freeze/FreezeDump.kt index cb90b4c18..32efaa6b9 100644 --- a/src/main/java/de/bixilon/minosoft/util/crash/freeze/FreezeDump.kt +++ b/src/main/java/de/bixilon/minosoft/util/crash/freeze/FreezeDump.kt @@ -1,6 +1,6 @@ /* * Minosoft - * Copyright (C) 2020-2023 Moritz Zwerger + * Copyright (C) 2020-2025 Moritz Zwerger * * This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. * @@ -13,7 +13,9 @@ package de.bixilon.minosoft.util.crash.freeze +import java.io.File + class FreezeDump( val dump: String, - val path: String?, + val path: File?, ) diff --git a/src/main/java/de/bixilon/minosoft/util/crash/freeze/FreezeDumpUtil.kt b/src/main/java/de/bixilon/minosoft/util/crash/freeze/FreezeDumpUtil.kt index d3ccc3a9f..fef8e14bf 100644 --- a/src/main/java/de/bixilon/minosoft/util/crash/freeze/FreezeDumpUtil.kt +++ b/src/main/java/de/bixilon/minosoft/util/crash/freeze/FreezeDumpUtil.kt @@ -26,10 +26,16 @@ import de.bixilon.kutil.time.TimeUtil import de.bixilon.minosoft.protocol.network.session.play.PlaySession import de.bixilon.minosoft.terminal.RunConfiguration import de.bixilon.minosoft.util.KUtil.div +import de.bixilon.minosoft.util.KUtil.format1 +import java.io.File import java.io.FileOutputStream import java.lang.management.ManagementFactory import java.nio.charset.StandardCharsets +import java.nio.file.Path import java.text.SimpleDateFormat +import kotlin.time.Clock +import kotlin.time.ExperimentalTime +import kotlin.time.Instant object FreezeDumpUtil { @@ -41,6 +47,7 @@ object FreezeDumpUtil { thread.start() } + @OptIn(ExperimentalTime::class) fun catch(callback: (FreezeDump) -> Unit) { val builder = StringBuilder() @@ -81,12 +88,12 @@ object FreezeDumpUtil { val dump = builder.toString() - var path: String? + var path: File? try { val crashReportFolder = (RunConfiguration.HOME_DIRECTORY / "dumps" / "freeze").toFile() crashReportFolder.mkdirs() - path = "${crashReportFolder.slashPath}/freeze-${SimpleDateFormat("yyyy-MM-dd-HH.mm.ss").format(TimeUtil.now())}.txt" + path = crashReportFolder / "freeze-${SimpleDateFormat("yyyy-MM-dd-HH.mm.ss").format1(Clock.System.now())}.txt" val stream = FileOutputStream(path)