mirror of
https://github.com/PaperMC/Velocity.git
synced 2026-02-19 15:37:42 +01:00
Actually fix loading locales from paths with spaces in them
This commit is contained in:
@@ -18,7 +18,6 @@
|
|||||||
package com.velocitypowered.proxy.util;
|
package com.velocitypowered.proxy.util;
|
||||||
|
|
||||||
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
|
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
|
||||||
import java.io.File;
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.net.URI;
|
import java.net.URI;
|
||||||
import java.net.URISyntaxException;
|
import java.net.URISyntaxException;
|
||||||
@@ -31,6 +30,7 @@ import java.nio.file.Paths;
|
|||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
import java.util.function.Consumer;
|
import java.util.function.Consumer;
|
||||||
|
|
||||||
public class FileSystemUtils {
|
public class FileSystemUtils {
|
||||||
@@ -48,11 +48,18 @@ public class FileSystemUtils {
|
|||||||
public static boolean visitResources(Class<?> target, Consumer<Path> consumer,
|
public static boolean visitResources(Class<?> target, Consumer<Path> consumer,
|
||||||
String firstPathComponent, String... remainingPathComponents)
|
String firstPathComponent, String... remainingPathComponents)
|
||||||
throws IOException {
|
throws IOException {
|
||||||
final File file = new File(target
|
final URL knownResource = FileSystemUtils.class.getClassLoader()
|
||||||
.getProtectionDomain().getCodeSource().getLocation().getPath());
|
.getResource("default-velocity.toml");
|
||||||
|
if (knownResource == null) {
|
||||||
|
throw new IllegalStateException(
|
||||||
|
"default-velocity.toml does not exist, don't know where we are");
|
||||||
|
}
|
||||||
|
if (knownResource.getProtocol().equals("jar")) {
|
||||||
|
// Running from a JAR
|
||||||
|
String jarPathRaw = knownResource.toString().split("!")[0];
|
||||||
|
URI path = URI.create(jarPathRaw + "!/");
|
||||||
|
|
||||||
if (file.isFile()) { // jar
|
try (FileSystem fileSystem = FileSystems.newFileSystem(path, Map.of("create", "true"))) {
|
||||||
try (FileSystem fileSystem = FileSystems.newFileSystem(file.toPath(), (ClassLoader) null)) {
|
|
||||||
Path toVisit = fileSystem.getPath(firstPathComponent, remainingPathComponents);
|
Path toVisit = fileSystem.getPath(firstPathComponent, remainingPathComponents);
|
||||||
if (Files.exists(toVisit)) {
|
if (Files.exists(toVisit)) {
|
||||||
consumer.accept(toVisit);
|
consumer.accept(toVisit);
|
||||||
@@ -61,6 +68,7 @@ public class FileSystemUtils {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
// Running from the file system
|
||||||
URI uri;
|
URI uri;
|
||||||
List<String> componentList = new ArrayList<>();
|
List<String> componentList = new ArrayList<>();
|
||||||
componentList.add(firstPathComponent);
|
componentList.add(firstPathComponent);
|
||||||
|
|||||||
Reference in New Issue
Block a user