mirror of
https://github.com/BlueMap-Minecraft/BlueMap.git
synced 2024-11-29 14:06:32 +01:00
Make configs generate paths with forwardslashes whenever possible
This commit is contained in:
parent
31ae055ae5
commit
b4b3e72d51
@ -34,10 +34,7 @@
|
|||||||
import de.bluecolored.bluemap.core.util.Tristate;
|
import de.bluecolored.bluemap.core.util.Tristate;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.nio.file.Files;
|
import java.nio.file.*;
|
||||||
import java.nio.file.Path;
|
|
||||||
import java.nio.file.Paths;
|
|
||||||
import java.nio.file.StandardOpenOption;
|
|
||||||
import java.time.LocalDateTime;
|
import java.time.LocalDateTime;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
@ -396,12 +393,28 @@ private ConfigTemplate createEndMapTemplate(String name, Path worldFolder, int i
|
|||||||
}
|
}
|
||||||
|
|
||||||
private String formatPath(Path path) {
|
private String formatPath(Path path) {
|
||||||
return Path.of("")
|
// normalize path
|
||||||
|
path = Path.of("")
|
||||||
.toAbsolutePath()
|
.toAbsolutePath()
|
||||||
.relativize(path.toAbsolutePath())
|
.relativize(path.toAbsolutePath())
|
||||||
.normalize()
|
.normalize();
|
||||||
.toString()
|
String pathString = path.toString();
|
||||||
.replace("\\", "\\\\");
|
|
||||||
|
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;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user