From 0176be12688cce994a90e77a497b3ce917108261 Mon Sep 17 00:00:00 2001 From: rfresh2 <89827146+rfresh2@users.noreply.github.com> Date: Sat, 22 Jul 2023 23:57:34 -0700 Subject: [PATCH] MapDownloader: replace illegal characters in map names fixes write failures on certain named maps --- .../com/lambda/client/module/modules/misc/MapDownloader.kt | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/main/kotlin/com/lambda/client/module/modules/misc/MapDownloader.kt b/src/main/kotlin/com/lambda/client/module/modules/misc/MapDownloader.kt index 6509bec18..95af889c1 100644 --- a/src/main/kotlin/com/lambda/client/module/modules/misc/MapDownloader.kt +++ b/src/main/kotlin/com/lambda/client/module/modules/misc/MapDownloader.kt @@ -46,6 +46,7 @@ internal object MapDownloader : Module( private var pendingTasks = mutableSetOf() private val secTimer = TickTimer(TimeUnit.SECONDS) private val milliSecTimer = TickTimer(TimeUnit.MILLISECONDS) + private val illegalFilenameCharsRegex = "[^a-zA-Z0-9\\.\\-]".toRegex() // https://learn.microsoft.com/en-us/windows/win32/fileio/naming-a-file init { existingHashes = getExistingHashes() @@ -159,7 +160,11 @@ internal object MapDownloader : Module( try { val resized = BufferedImage(finalSize, finalSize, img.type) val g = resized.createGraphics() - val loc = "${FolderUtils.mapImagesFolder}${mapInfo.hash}_name_${mapInfo.name.replace(File.separator, "")}_id_${mapInfo.id}_${if (mc.isIntegratedServerRunning) "local" else "server_${player.connection.networkManager.remoteAddress.toString().replace("/", "_").replace(":", "_")}"}.png" + val loc = "${FolderUtils.mapImagesFolder}${mapInfo.hash}" + + "_name_${mapInfo.name.replace(illegalFilenameCharsRegex, "_")}" + + "_id_${mapInfo.id}" + + "_${if (mc.isIntegratedServerRunning) "local" + else "server_${player.connection.networkManager.remoteAddress.toString().replace("/", "_").replace(":", "_")}"}.png" g.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_NEAREST_NEIGHBOR) g.drawImage(img, 0, 0, finalSize, finalSize, 0, 0, img.width,