mirror of
https://github.com/Grasscutters/Grasscutter.git
synced 2025-12-15 08:25:21 +01:00
Fix dataloader with eclipse
This commit is contained in:
@@ -9,6 +9,7 @@ import java.net.URI;
|
||||
import java.net.URISyntaxException;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.nio.file.*;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
@@ -76,23 +77,29 @@ public final class FileUtils {
|
||||
|
||||
// From https://mkyong.com/java/java-read-a-file-from-resources-folder/
|
||||
public static List<Path> getPathsFromResource(String folder) throws URISyntaxException, IOException {
|
||||
List<Path> result;
|
||||
|
||||
// get path of the current running JAR
|
||||
List<Path> result = null;
|
||||
|
||||
// Get path of the current running JAR
|
||||
String jarPath = Grasscutter.class.getProtectionDomain()
|
||||
.getCodeSource()
|
||||
.getLocation()
|
||||
.toURI()
|
||||
.getPath();
|
||||
|
||||
// file walks JAR
|
||||
URI uri = URI.create("jar:file:" + jarPath);
|
||||
try (FileSystem fs = FileSystems.newFileSystem(uri, Collections.emptyMap())) {
|
||||
result = Files.walk(fs.getPath(folder))
|
||||
.filter(Files::isRegularFile)
|
||||
.collect(Collectors.toList());
|
||||
try {
|
||||
// file walks JAR
|
||||
URI uri = URI.create("jar:file:" + jarPath);
|
||||
try (FileSystem fs = FileSystems.newFileSystem(uri, Collections.emptyMap())) {
|
||||
result = Files.walk(fs.getPath(folder))
|
||||
.filter(Files::isRegularFile)
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
} catch (Exception e) {
|
||||
// Eclipse puts resources in its bin folder
|
||||
File f = new File(jarPath + "defaults/data/");
|
||||
result = Arrays.stream(f.listFiles()).map(File::toPath).toList();
|
||||
}
|
||||
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user