fix find files
This commit is contained in:
@@ -1,7 +1,6 @@
|
|||||||
package dmx.lwjake2;
|
package dmx.lwjake2;
|
||||||
|
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
import lombok.Setter;
|
|
||||||
import lombok.experimental.UtilityClass;
|
import lombok.experimental.UtilityClass;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
|
||||||
@@ -10,6 +9,7 @@ import java.io.*;
|
|||||||
import java.nio.ByteBuffer;
|
import java.nio.ByteBuffer;
|
||||||
import java.nio.channels.FileChannel;
|
import java.nio.channels.FileChannel;
|
||||||
import java.nio.file.Files;
|
import java.nio.file.Files;
|
||||||
|
import java.nio.file.Path;
|
||||||
import java.nio.file.Paths;
|
import java.nio.file.Paths;
|
||||||
|
|
||||||
@Slf4j
|
@Slf4j
|
||||||
@@ -17,19 +17,25 @@ import java.nio.file.Paths;
|
|||||||
public class UnpackLoader {
|
public class UnpackLoader {
|
||||||
|
|
||||||
@Getter
|
@Getter
|
||||||
@Setter
|
private static Path rootPath;
|
||||||
private static String rootPath;
|
|
||||||
|
|
||||||
private static File getFile(String path) {
|
private static File getFile(String path) {
|
||||||
File file = new File(rootPath, path);
|
File file = rootPath.resolve(path).toFile();
|
||||||
if (!file.exists()) {
|
if (!file.exists()) {
|
||||||
log.warn("File '{}' not exists", file.getPath());
|
file = rootPath.getParent().resolve(path).toFile();
|
||||||
return null;
|
if (!file.exists()) {
|
||||||
|
log.warn("File '{}' not exists", file.getPath());
|
||||||
|
return null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return file;
|
return file;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static void setRootPath(String rootPath) {
|
||||||
|
UnpackLoader.rootPath = Paths.get(rootPath);
|
||||||
|
}
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
public static byte[] loadFile(String path) {
|
public static byte[] loadFile(String path) {
|
||||||
File file = getFile(path);
|
File file = getFile(path);
|
||||||
@@ -84,6 +90,6 @@ public class UnpackLoader {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static boolean exists(String path) {
|
public static boolean exists(String path) {
|
||||||
return Files.exists(Paths.get(rootPath, path));
|
return Files.exists(rootPath.resolve(path));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user