Commit 87966b9e authored by line-bear's avatar line-bear Committed by GitHub
Browse files

Remove the extra slash while loading resources. (#893)



* Remove the extra slash

* Update src/main/java/emu/grasscutter/Configuration.java
Co-authored-by: default avatarHotaruYS <105128850+HotaruYS@users.noreply.github.com>

* Update src/main/java/emu/grasscutter/Configuration.java
Co-authored-by: default avatarHotaruYS <105128850+HotaruYS@users.noreply.github.com>

* Update src/main/java/emu/grasscutter/Configuration.java
Co-authored-by: default avatarHotaruYS <105128850+HotaruYS@users.noreply.github.com>

* Import java.nio.file.Paths to use Paths.get

* Mark fields as private to prevent use *FOLDER directly

* Remove unnecessary slash
Co-authored-by: default avatarHotaruYS <105128850+HotaruYS@users.noreply.github.com>
parent eb64b25f
...@@ -4,9 +4,11 @@ import emu.grasscutter.utils.ConfigContainer; ...@@ -4,9 +4,11 @@ import emu.grasscutter.utils.ConfigContainer;
import emu.grasscutter.utils.ConfigContainer.*; import emu.grasscutter.utils.ConfigContainer.*;
import java.util.Locale; import java.util.Locale;
import java.nio.file.Paths;
import static emu.grasscutter.Grasscutter.config; import static emu.grasscutter.Grasscutter.config;
/** /**
* A data container for the server's configuration. * A data container for the server's configuration.
* *
...@@ -24,12 +26,12 @@ public final class Configuration extends ConfigContainer { ...@@ -24,12 +26,12 @@ public final class Configuration extends ConfigContainer {
public static final Locale LANGUAGE = config.language.language; public static final Locale LANGUAGE = config.language.language;
public static final Locale FALLBACK_LANGUAGE = config.language.fallback; public static final Locale FALLBACK_LANGUAGE = config.language.fallback;
public static final String DATA_FOLDER = config.folderStructure.data; private static final String DATA_FOLDER = config.folderStructure.data;
public static final String RESOURCES_FOLDER = config.folderStructure.resources; private static final String RESOURCES_FOLDER = config.folderStructure.resources;
public static final String KEYS_FOLDER = config.folderStructure.keys; private static final String KEYS_FOLDER = config.folderStructure.keys;
public static final String PLUGINS_FOLDER = config.folderStructure.plugins; private static final String PLUGINS_FOLDER = config.folderStructure.plugins;
public static final String SCRIPTS_FOLDER = config.folderStructure.scripts; private static final String SCRIPTS_FOLDER = config.folderStructure.scripts;
public static final String PACKETS_FOLDER = config.folderStructure.packets; private static final String PACKETS_FOLDER = config.folderStructure.packets;
public static final Server SERVER = config.server; public static final Server SERVER = config.server;
public static final Database DATABASE = config.databaseInfo; public static final Database DATABASE = config.databaseInfo;
...@@ -49,17 +51,36 @@ public final class Configuration extends ConfigContainer { ...@@ -49,17 +51,36 @@ public final class Configuration extends ConfigContainer {
/* /*
* Utilities * Utilities
*/ */
public static String DATA() {
return DATA_FOLDER;
}
public static String DATA(String path) { public static String DATA(String path) {
return DATA_FOLDER + "/" + path; return Paths.get(DATA_FOLDER, path).toString();
} }
public static String RESOURCE(String path) { public static String RESOURCE(String path) {
return RESOURCES_FOLDER + "/" + path; return Paths.get(RESOURCES_FOLDER, path).toString();
}
public static String KEY(String path) {
return Paths.get(KEYS_FOLDER, path).toString();
}
public static String PLUGIN() {
return PLUGINS_FOLDER;
}
public static String PLUGIN(String path) {
return Paths.get(PLUGINS_FOLDER, path).toString();
} }
public static String SCRIPT(String path) { public static String SCRIPT(String path) {
return SCRIPTS_FOLDER + "/" + path; return Paths.get(SCRIPTS_FOLDER, path).toString();
}
public static String PACKET(String path) {
return Paths.get(PACKETS_FOLDER, path).toString();
} }
/** /**
......
...@@ -358,7 +358,7 @@ public class GachaManager { ...@@ -358,7 +358,7 @@ public class GachaManager {
if(this.watchService == null) { if(this.watchService == null) {
try { try {
this.watchService = FileSystems.getDefault().newWatchService(); this.watchService = FileSystems.getDefault().newWatchService();
Path path = new File(DATA_FOLDER).toPath(); Path path = new File(DATA()).toPath();
path.register(watchService, new WatchEvent.Kind[]{StandardWatchEventKinds.ENTRY_MODIFY}, SensitivityWatchEventModifier.HIGH); path.register(watchService, new WatchEvent.Kind[]{StandardWatchEventKinds.ENTRY_MODIFY}, SensitivityWatchEventModifier.HIGH);
} catch (Exception e) { } catch (Exception e) {
Grasscutter.getLogger().error("Unable to load the Gacha Manager Watch Service. If ServerOptions.watchGacha is true it will not auto-reload"); Grasscutter.getLogger().error("Unable to load the Gacha Manager Watch Service. If ServerOptions.watchGacha is true it will not auto-reload");
......
...@@ -37,7 +37,7 @@ public abstract class Plugin { ...@@ -37,7 +37,7 @@ public abstract class Plugin {
this.identifier = identifier; this.identifier = identifier;
this.classLoader = classLoader; this.classLoader = classLoader;
this.dataFolder = new File(PLUGINS_FOLDER, identifier.name); this.dataFolder = new File(PLUGIN(), identifier.name);
this.logger = LoggerFactory.getLogger(identifier.name); this.logger = LoggerFactory.getLogger(identifier.name);
if(!this.dataFolder.exists() && !this.dataFolder.mkdirs()) { if(!this.dataFolder.exists() && !this.dataFolder.mkdirs()) {
......
...@@ -34,7 +34,7 @@ public final class PluginManager { ...@@ -34,7 +34,7 @@ public final class PluginManager {
* Loads plugins from the config-specified directory. * Loads plugins from the config-specified directory.
*/ */
private void loadPlugins() { private void loadPlugins() {
File pluginsDir = new File(Utils.toFilePath(PLUGINS_FOLDER)); File pluginsDir = new File(Utils.toFilePath(PLUGIN()));
if(!pluginsDir.exists() && !pluginsDir.mkdirs()) { if(!pluginsDir.exists() && !pluginsDir.mkdirs()) {
Grasscutter.getLogger().error("Failed to create plugins directory: " + pluginsDir.getAbsolutePath()); Grasscutter.getLogger().error("Failed to create plugins directory: " + pluginsDir.getAbsolutePath());
return; return;
......
...@@ -236,7 +236,7 @@ public class SceneScriptManager { ...@@ -236,7 +236,7 @@ public class SceneScriptManager {
group.setLoaded(true); group.setLoaded(true);
CompiledScript cs = ScriptLoader.getScriptByPath( CompiledScript cs = ScriptLoader.getScriptByPath(
SCRIPTS_FOLDER + "Scene/" + getScene().getId() + "/scene" + getScene().getId() + "_group" + group.id + "." + ScriptLoader.getScriptType()); SCRIPT("Scene/" + getScene().getId() + "/scene" + getScene().getId() + "_group" + group.id + "." + ScriptLoader.getScriptType()));
if (cs == null) { if (cs == null) {
return; return;
......
...@@ -140,7 +140,7 @@ public class GameSession extends KcpChannel { ...@@ -140,7 +140,7 @@ public class GameSession extends KcpChannel {
} }
public void replayPacket(int opcode, String name) { public void replayPacket(int opcode, String name) {
String filePath = PACKETS_FOLDER + name; String filePath = PACKET(name);
File p = new File(filePath); File p = new File(filePath);
if (!p.exists()) return; if (!p.exists()) return;
......
...@@ -20,11 +20,11 @@ public final class Crypto { ...@@ -20,11 +20,11 @@ public final class Crypto {
public static byte[] ENCRYPT_SEED_BUFFER = new byte[0]; public static byte[] ENCRYPT_SEED_BUFFER = new byte[0];
public static void loadKeys() { public static void loadKeys() {
DISPATCH_KEY = FileUtils.read(KEYS_FOLDER + "/dispatchKey.bin"); DISPATCH_KEY = FileUtils.read(KEY("dispatchKey.bin"));
DISPATCH_SEED = FileUtils.read(KEYS_FOLDER + "/dispatchSeed.bin"); DISPATCH_SEED = FileUtils.read(KEY("dispatchSeed.bin"));
ENCRYPT_KEY = FileUtils.read(KEYS_FOLDER + "/secretKey.bin"); ENCRYPT_KEY = FileUtils.read(KEY("secretKey.bin"));
ENCRYPT_SEED_BUFFER = FileUtils.read(KEYS_FOLDER + "/secretKeyBuffer.bin"); ENCRYPT_SEED_BUFFER = FileUtils.read(KEY("secretKeyBuffer.bin"));
} }
public static void xor(byte[] packet, byte[] key) { public static void xor(byte[] packet, byte[] key) {
...@@ -40,7 +40,7 @@ public final class Crypto { ...@@ -40,7 +40,7 @@ public final class Crypto {
public static void extractSecretKeyBuffer(byte[] data) { public static void extractSecretKeyBuffer(byte[] data) {
try { try {
GetPlayerTokenRsp p = GetPlayerTokenRsp.parseFrom(data); GetPlayerTokenRsp p = GetPlayerTokenRsp.parseFrom(data);
FileUtils.write(KEYS_FOLDER + "/secretKeyBuffer.bin", p.getSecretKeyBytes().toByteArray()); FileUtils.write(KEY("/secretKeyBuffer.bin"), p.getSecretKeyBytes().toByteArray());
Grasscutter.getLogger().info("Secret Key: " + p.getSecretKey()); Grasscutter.getLogger().info("Secret Key: " + p.getSecretKey());
} catch (Exception e) { } catch (Exception e) {
Grasscutter.getLogger().error("Crypto error.", e); Grasscutter.getLogger().error("Crypto error.", e);
...@@ -50,7 +50,7 @@ public final class Crypto { ...@@ -50,7 +50,7 @@ public final class Crypto {
public static void extractDispatchSeed(String data) { public static void extractDispatchSeed(String data) {
try { try {
QueryCurrRegionHttpRsp p = QueryCurrRegionHttpRsp.parseFrom(Base64.getDecoder().decode(data)); QueryCurrRegionHttpRsp p = QueryCurrRegionHttpRsp.parseFrom(Base64.getDecoder().decode(data));
FileUtils.write(KEYS_FOLDER + "/dispatchSeed.bin", p.getRegionInfo().getSecretKey().toByteArray()); FileUtils.write(KEY("/dispatchSeed.bin"), p.getRegionInfo().getSecretKey().toByteArray());
} catch (Exception e) { } catch (Exception e) {
Grasscutter.getLogger().error("Crypto error.", e); Grasscutter.getLogger().error("Crypto error.", e);
} }
......
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