Skip to content

Commit

Permalink
Fix dataloader not getting path correctly
Browse files Browse the repository at this point in the history
  • Loading branch information
omg-xtao authored and Melledy committed May 21, 2022
1 parent d1775b1 commit 7c899ce
Showing 1 changed file with 7 additions and 9 deletions.
16 changes: 7 additions & 9 deletions src/main/java/emu/grasscutter/utils/FileUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
import java.net.URISyntaxException;
import java.nio.charset.StandardCharsets;
import java.nio.file.*;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
Expand Down Expand Up @@ -77,19 +76,18 @@ public static String getFilenameWithoutPath(String fileName) {
}

// From https://mkyong.com/java/java-read-a-file-from-resources-folder/
public static List<Path> getPathsFromResource(String folder) throws URISyntaxException, IOException {
public static List<Path> getPathsFromResource(String folder) throws URISyntaxException {
List<Path> result = null;
// Get path of the current running JAR
String jarPath = Grasscutter.class.getProtectionDomain()

// Get pathUri of the current running JAR
URI pathUri = Grasscutter.class.getProtectionDomain()
.getCodeSource()
.getLocation()
.toURI()
.getPath();
.toURI();

try {
// file walks JAR
URI uri = URI.create("jar:file:" + jarPath);
URI uri = URI.create("jar:file:" + pathUri.getRawPath());
try (FileSystem fs = FileSystems.newFileSystem(uri, Collections.emptyMap())) {
result = Files.walk(fs.getPath(folder))
.filter(Files::isRegularFile)
Expand All @@ -105,7 +103,7 @@ public static List<Path> getPathsFromResource(String folder) throws URISyntaxExc

result = Arrays.stream(f.listFiles()).map(File::toPath).toList();
}

return result;
}

Expand Down

0 comments on commit 7c899ce

Please sign in to comment.