Commit 4b05ed28 authored by Melledy's avatar Melledy Committed by GitHub
Browse files

Merge pull request #15 from Melledy/file-separator

Use the operating system's file separator
parents d98ea08f d873b8ad
...@@ -2,20 +2,12 @@ package emu.grasscutter.data; ...@@ -2,20 +2,12 @@ package emu.grasscutter.data;
import java.io.File; import java.io.File;
import java.io.FileReader; import java.io.FileReader;
import java.nio.file.Files; import java.util.*;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.Collection;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.TreeMap;
import java.util.Map.Entry; import java.util.Map.Entry;
import java.util.regex.Matcher; import java.util.regex.Matcher;
import java.util.regex.Pattern; import java.util.regex.Pattern;
import java.util.stream.Stream;
import emu.grasscutter.utils.Utils;
import org.reflections.Reflections; import org.reflections.Reflections;
import com.google.gson.reflect.TypeToken; import com.google.gson.reflect.TypeToken;
...@@ -39,19 +31,12 @@ public class ResourceLoader { ...@@ -39,19 +31,12 @@ public class ResourceLoader {
} }
}); });
classList.sort((a, b) -> { classList.sort((a, b) -> b.getAnnotation(ResourceType.class).loadPriority().value() - a.getAnnotation(ResourceType.class).loadPriority().value());
return b.getAnnotation(ResourceType.class).loadPriority().value() - a.getAnnotation(ResourceType.class).loadPriority().value();
});
return classList; return classList;
} }
public static void loadAll() { public static void loadAll() {
// Create resource folder if it doesnt exist
File resFolder = new File(Grasscutter.getConfig().RESOURCE_FOLDER);
if (!resFolder.exists()) {
resFolder.mkdir();
}
// Load ability lists // Load ability lists
loadAbilityEmbryos(); loadAbilityEmbryos();
loadOpenConfig(); loadOpenConfig();
...@@ -110,7 +95,7 @@ public class ResourceLoader { ...@@ -110,7 +95,7 @@ public class ResourceLoader {
try { try {
loadFromResource(resourceDefinition, type, map); loadFromResource(resourceDefinition, type, map);
} catch (Exception e) { } catch (Exception e) {
Grasscutter.getLogger().error("Error loading resource file: " + type.name(), e); Grasscutter.getLogger().error("Error loading resource file: " + Arrays.toString(type.name()), e);
} }
} }
} }
...@@ -153,10 +138,16 @@ public class ResourceLoader { ...@@ -153,10 +138,16 @@ public class ResourceLoader {
Pattern pattern = Pattern.compile("(?<=ConfigAvatar_)(.*?)(?=.json)"); Pattern pattern = Pattern.compile("(?<=ConfigAvatar_)(.*?)(?=.json)");
embryoList = new LinkedList<>(); embryoList = new LinkedList<>();
File folder = new File(Grasscutter.getConfig().RESOURCE_FOLDER + "BinOutput\\Avatar\\"); File folder = new File(Utils.toFilePath(Grasscutter.getConfig().RESOURCE_FOLDER + "BinOutput/Avatar/"));
for (File file : folder.listFiles()) { File[] files = folder.listFiles();
AvatarConfig config = null; if(files == null) {
String avatarName = null; Grasscutter.getLogger().error("Error loading ability embryos: no files found in " + folder.getAbsolutePath());
return;
}
for (File file : files) {
AvatarConfig config;
String avatarName;
Matcher matcher = pattern.matcher(file.getName()); Matcher matcher = pattern.matcher(file.getName());
if (matcher.find()) { if (matcher.find()) {
...@@ -209,14 +200,18 @@ public class ResourceLoader { ...@@ -209,14 +200,18 @@ public class ResourceLoader {
String[] folderNames = {"BinOutput\\Talent\\EquipTalents\\", "BinOutput\\Talent\\AvatarTalents\\"}; String[] folderNames = {"BinOutput\\Talent\\EquipTalents\\", "BinOutput\\Talent\\AvatarTalents\\"};
for (String name : folderNames) { for (String name : folderNames) {
File folder = new File(Grasscutter.getConfig().RESOURCE_FOLDER + name); File folder = new File(Utils.toFilePath(Grasscutter.getConfig().RESOURCE_FOLDER + name));
File[] files = folder.listFiles();
if(files == null) {
Grasscutter.getLogger().error("Error loading open config: no files found in " + folder.getAbsolutePath()); return;
}
for (File file : folder.listFiles()) { for (File file : files) {
if (!file.getName().endsWith(".json")) { if (!file.getName().endsWith(".json")) {
continue; continue;
} }
Map<String, OpenConfigData[]> config = null; Map<String, OpenConfigData[]> config;
try (FileReader fileReader = new FileReader(file)) { try (FileReader fileReader = new FileReader(file)) {
config = Grasscutter.getGsonFactory().fromJson(fileReader, type); config = Grasscutter.getGsonFactory().fromJson(fileReader, type);
......
...@@ -79,6 +79,15 @@ public final class Utils { ...@@ -79,6 +79,15 @@ public final class Utils {
return v7; return v7;
} }
/**
* Creates a string with the path to a file.
* @param path The path to the file.
* @return A path using the operating system's file separator.
*/
public static String toFilePath(String path) {
return path.replace("/", File.separator);
}
/** /**
* Checks if a file exists on the file system. * Checks if a file exists on the file system.
* @param path The path to the file. * @param path The path to the file.
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment