mirror of
https://github.com/Grasscutters/Grasscutter.git
synced 2025-03-13 05:47:20 +08:00
implement getCachePath (#2121)
* implement getCachePath for further use like grids cache. * Update src/main/java/emu/grasscutter/utils/FileUtils.java --------- Co-authored-by: Magix <27646710+KingRainbow44@users.noreply.github.com>
This commit is contained in:
parent
6989d49080
commit
0dd41f9350
@ -8,6 +8,7 @@ import emu.grasscutter.Grasscutter.ServerRunMode;
|
||||
import emu.grasscutter.utils.JsonUtils;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
import java.net.URI;
|
||||
import java.util.Set;
|
||||
import java.lang.reflect.Field;
|
||||
import java.util.Arrays;
|
||||
@ -88,6 +89,7 @@ public class ConfigContainer {
|
||||
public String packets = "./packets/";
|
||||
public String scripts = "resources:Scripts/";
|
||||
public String plugins = "./plugins/";
|
||||
public String cache = "./cache/";
|
||||
|
||||
// UNUSED (potentially added later?)
|
||||
// public String dumps = "./dumps/";
|
||||
|
@ -21,6 +21,7 @@ public final class FileUtils {
|
||||
private static final Path DATA_USER_PATH = Path.of(Grasscutter.config.folderStructure.data);
|
||||
private static final Path PACKETS_PATH = Path.of(Grasscutter.config.folderStructure.packets);
|
||||
private static final Path PLUGINS_PATH = Path.of(Grasscutter.config.folderStructure.plugins);
|
||||
private static final Path CACHE_PATH = Path.of(Grasscutter.config.folderStructure.cache);
|
||||
private static final Path RESOURCES_PATH;
|
||||
private static final Path SCRIPTS_PATH;
|
||||
private static final String[] TSJ_JSON_TSV = {"tsj", "json", "tsv"};
|
||||
@ -138,6 +139,10 @@ public final class FileUtils {
|
||||
return DATA_USER_PATH.resolve(path);
|
||||
}
|
||||
|
||||
public static Path getCachePath(String path) {
|
||||
return CACHE_PATH.resolve(path);
|
||||
}
|
||||
|
||||
public static Path getPacketPath(String path) {
|
||||
return PACKETS_PATH.resolve(path);
|
||||
}
|
||||
|
@ -2,6 +2,7 @@ package emu.grasscutter.utils;
|
||||
|
||||
import static emu.grasscutter.config.Configuration.FALLBACK_LANGUAGE;
|
||||
import static emu.grasscutter.utils.FileUtils.getResourcePath;
|
||||
import static emu.grasscutter.utils.FileUtils.getCachePath;
|
||||
|
||||
import com.google.gson.JsonElement;
|
||||
import com.google.gson.JsonObject;
|
||||
@ -37,8 +38,7 @@ public final class Language {
|
||||
private static final Map<String, Language> cachedLanguages = new ConcurrentHashMap<>();
|
||||
private static final int TEXTMAP_CACHE_VERSION = 0x9CCACE04;
|
||||
private static final Pattern textMapKeyValueRegex = Pattern.compile("\"(\\d+)\": \"(.+)\"");
|
||||
private static final Path TEXTMAP_CACHE_PATH =
|
||||
Path.of(Utils.toFilePath("cache/TextMapCache.bin"));
|
||||
private static final Path TEXTMAP_CACHE_PATH = getCachePath("TextMap/TextMapCache.bin");
|
||||
private static boolean scannedTextmaps =
|
||||
false; // Ensure that we don't infinitely rescan on cache misses that don't exist
|
||||
private static Int2ObjectMap<TextStrings> textMapStrings;
|
||||
@ -289,14 +289,9 @@ public final class Language {
|
||||
}
|
||||
|
||||
private static void saveTextMapsCache(Int2ObjectMap<TextStrings> input) throws IOException {
|
||||
try {
|
||||
Files.createDirectory(Path.of("cache"));
|
||||
} catch (FileAlreadyExistsException ignored) {
|
||||
}
|
||||
try (ObjectOutputStream file =
|
||||
new ObjectOutputStream(
|
||||
new BufferedOutputStream(
|
||||
Files.newOutputStream(TEXTMAP_CACHE_PATH, StandardOpenOption.CREATE), 0x100000))) {
|
||||
Files.createDirectories(TEXTMAP_CACHE_PATH.getParent());
|
||||
try (var file = new ObjectOutputStream(new BufferedOutputStream(
|
||||
Files.newOutputStream(TEXTMAP_CACHE_PATH, StandardOpenOption.CREATE), 0x100000))) {
|
||||
file.writeInt(TEXTMAP_CACHE_VERSION);
|
||||
file.writeObject(input);
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user