From c2bf6635549987a91e5ae9a2bd6481503d090a77 Mon Sep 17 00:00:00 2001 From: Melledy <52122272+Melledy@users.noreply.github.com> Date: Thu, 19 May 2022 03:05:57 -0700 Subject: [PATCH] Add error message in case data files in resources could not be found --- src/main/java/emu/grasscutter/data/DataLoader.java | 6 +++++- src/main/java/emu/grasscutter/utils/FileUtils.java | 6 ++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/src/main/java/emu/grasscutter/data/DataLoader.java b/src/main/java/emu/grasscutter/data/DataLoader.java index b5ed90745..69a17491c 100644 --- a/src/main/java/emu/grasscutter/data/DataLoader.java +++ b/src/main/java/emu/grasscutter/data/DataLoader.java @@ -50,6 +50,10 @@ public class DataLoader { public static void CheckAllFiles() { try { List filenames = FileUtils.getPathsFromResource("/defaults/data/"); + + if (filenames == null) { + Grasscutter.getLogger().error("We were unable to locate your default data files."); + } for (Path file : filenames) { String relativePath = String.valueOf(file).split("defaults[\\\\\\/]data[\\\\\\/]")[1]; @@ -57,7 +61,7 @@ public class DataLoader { CheckAndCopyData(relativePath); } } catch (Exception e) { - Grasscutter.getLogger().error("An error occurred while trying to check the data folder. \n", e); + Grasscutter.getLogger().error("An error occurred while trying to check the data folder.", e); } GenerateGachaMappings(); diff --git a/src/main/java/emu/grasscutter/utils/FileUtils.java b/src/main/java/emu/grasscutter/utils/FileUtils.java index 5d42dd88f..181168aea 100644 --- a/src/main/java/emu/grasscutter/utils/FileUtils.java +++ b/src/main/java/emu/grasscutter/utils/FileUtils.java @@ -9,6 +9,7 @@ import java.net.URI; import java.net.URISyntaxException; import java.nio.charset.StandardCharsets; import java.nio.file.*; +import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; import java.util.List; @@ -97,6 +98,11 @@ public final class FileUtils { } catch (Exception e) { // Eclipse puts resources in its bin folder File f = new File(jarPath + "defaults/data/"); + + if (!f.exists() || f.listFiles().length == 0) { + return null; + } + result = Arrays.stream(f.listFiles()).map(File::toPath).toList(); }