Mirror von
https://github.com/PaperMC/Velocity.git
synchronisiert 2024-11-17 05:20:14 +01:00
Actually fix loading locales from paths with spaces in them
Dieser Commit ist enthalten in:
Ursprung
1bd691f91b
Commit
688babb4da
@ -18,7 +18,6 @@
|
||||
package com.velocitypowered.proxy.util;
|
||||
|
||||
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.net.URI;
|
||||
import java.net.URISyntaxException;
|
||||
@ -31,6 +30,7 @@ import java.nio.file.Paths;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
public class FileSystemUtils {
|
||||
@ -48,11 +48,18 @@ public class FileSystemUtils {
|
||||
public static boolean visitResources(Class<?> target, Consumer<Path> consumer,
|
||||
String firstPathComponent, String... remainingPathComponents)
|
||||
throws IOException {
|
||||
final File file = new File(target
|
||||
.getProtectionDomain().getCodeSource().getLocation().getPath());
|
||||
final URL knownResource = FileSystemUtils.class.getClassLoader()
|
||||
.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(file.toPath(), (ClassLoader) null)) {
|
||||
try (FileSystem fileSystem = FileSystems.newFileSystem(path, Map.of("create", "true"))) {
|
||||
Path toVisit = fileSystem.getPath(firstPathComponent, remainingPathComponents);
|
||||
if (Files.exists(toVisit)) {
|
||||
consumer.accept(toVisit);
|
||||
@ -61,6 +68,7 @@ public class FileSystemUtils {
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
// Running from the file system
|
||||
URI uri;
|
||||
List<String> componentList = new ArrayList<>();
|
||||
componentList.add(firstPathComponent);
|
||||
|
Laden…
In neuem Issue referenzieren
Einen Benutzer sperren