Make configs generate paths with forwardslashes whenever possible

This commit is contained in:
Lukas Rieger (Blue) 2023-06-19 15:44:57 +02:00
parent 31ae055ae5
commit b4b3e72d51
No known key found for this signature in database
GPG Key ID: 2D09EC5ED2687FF2
1 changed files with 21 additions and 8 deletions

View File

@ -34,10 +34,7 @@ import de.bluecolored.bluemap.core.util.FileHelper;
import de.bluecolored.bluemap.core.util.Tristate;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.nio.file.StandardOpenOption;
import java.nio.file.*;
import java.time.LocalDateTime;
import java.util.Collections;
import java.util.HashMap;
@ -396,12 +393,28 @@ public class BlueMapConfigs implements BlueMapConfigProvider {
}
private String formatPath(Path path) {
return Path.of("")
// normalize path
path = Path.of("")
.toAbsolutePath()
.relativize(path.toAbsolutePath())
.normalize()
.toString()
.replace("\\", "\\\\");
.normalize();
String pathString = path.toString();
String formatted = pathString;
String separator = FileSystems.getDefault().getSeparator();
// try to replace separator with standardized forward slash
if (!separator.equals("/"))
formatted = pathString.replace(separator, "/");
// sanity check forward slash compatibility
if (!Path.of(formatted).equals(path))
formatted = pathString;
// escape all backslashes
formatted = formatted.replace("\\", "\\\\");
return formatted;
}
}