[Fix] Fixed hang on fresh server install ( thx @jie65535 )

This commit is contained in:
hartie95 2024-07-13 18:38:47 +02:00
parent 906f15c5a3
commit 27b6c7f8e3
3 changed files with 24 additions and 18 deletions

View File

@ -121,6 +121,9 @@ public final class Grasscutter {
// Generate handbooks.
Tools.createGmHandbooks();
// Generate gacha mappings.
Tools.generateGachaMappings();
// Initialize database.
DatabaseManager.initialize();

View File

@ -118,8 +118,6 @@ public class DataLoader {
} catch (Exception e) {
logger.error("An error occurred while trying to check the data folder.", e);
}
generateGachaMappings();
}
private static void checkAndCopyData(String name) {
@ -136,15 +134,4 @@ public class DataLoader {
}
}
private static void generateGachaMappings() {
var path = GachaHandler.getGachaMappingsPath();
if (!Files.exists(path)) {
try {
logger.info("Creating default '" + path.toString() + "' data");
Tools.createGachaMappings(path);
} catch (Exception exception) {
logger.warn("Failed to create gacha mappings. \n" + exception);
}
}
}
}

View File

@ -24,6 +24,7 @@ import emu.grasscutter.data.GameData;
import emu.grasscutter.data.ResourceLoader;
import emu.grasscutter.data.excels.AvatarData;
import emu.grasscutter.data.excels.ItemData;
import emu.grasscutter.server.http.handlers.GachaHandler;
import emu.grasscutter.utils.Language;
import emu.grasscutter.utils.Language.TextStrings;
import it.unimi.dsi.fastutil.ints.Int2IntRBTreeMap;
@ -232,8 +233,19 @@ public final class Tools {
return sbs.stream().map(StringBuilder::toString).toList();
}
public static void generateGachaMappings() {
var path = GachaHandler.getGachaMappingsPath();
if (!Files.exists(path)) {
try {
Grasscutter.getLogger().info("Creating default '{}' data", path.toString());
Tools.createGachaMappings(path);
} catch (Exception exception) {
Grasscutter.getLogger().warn("Failed to create gacha mappings. \n", exception);
}
}
}
public static void createGachaMappings(Path location) throws IOException {
ResourceLoader.loadResources();
List<String> jsons = createGachaMappingJsons();
var usedLocales = new HashSet<String>();
StringBuilder sb = new StringBuilder("mappings = {\n");
@ -249,14 +261,18 @@ public final class Tools {
Files.createDirectories(location.getParent());
Files.writeString(location, sb);
Grasscutter.getLogger().info("Mappings generated to " + location);
Grasscutter.getLogger().info("Mappings generated to {}", location);
}
public static List<String> getAvailableLanguage() {
List<String> availableLangList = new ArrayList<>();
try {
Files.newDirectoryStream(getResourcePath("TextMap"), "TextMap*.json").forEach(path -> {
availableLangList.add(path.getFileName().toString().replace("TextMap", "").replace(".json", "").toLowerCase());
try(val stream = Files.newDirectoryStream(getResourcePath("TextMap"), "TextMap*.json")) {
stream.forEach(path -> {
val lang = path.getFileName().toString()
.replace("TextMap", "")
.replace(".json", "")
.toLowerCase();
availableLangList.add(lang);
});
} catch (IOException e) {
Grasscutter.getLogger().error("Failed to get available languages:", e);