From d535fa82ab61a7974d62bdb90597d569ff312b69 Mon Sep 17 00:00:00 2001 From: ShirosakiMio <852468399@qq.com> Date: Mon, 1 Jul 2024 08:47:24 +0800 Subject: [PATCH] fix crash caused by style #422 --- .../com/tungsten/fcl/control/data/ButtonStyles.java | 12 ++++++++++-- .../tungsten/fcl/control/data/DirectionStyles.java | 11 +++++++++-- 2 files changed, 19 insertions(+), 4 deletions(-) diff --git a/FCL/src/main/java/com/tungsten/fcl/control/data/ButtonStyles.java b/FCL/src/main/java/com/tungsten/fcl/control/data/ButtonStyles.java index 0a75d1663..ae7da965c 100644 --- a/FCL/src/main/java/com/tungsten/fcl/control/data/ButtonStyles.java +++ b/FCL/src/main/java/com/tungsten/fcl/control/data/ButtonStyles.java @@ -17,6 +17,7 @@ import java.io.File; import java.io.IOException; import java.util.ArrayList; +import java.util.Objects; import java.util.logging.Level; public class ButtonStyles { @@ -70,14 +71,21 @@ public static void init() { } private static ArrayList getStylesFromDisk() { + ArrayList list = new ArrayList<>(); try { String json = FileUtils.readText(new File(FCLPath.CONTROLLER_DIR + "/styles/button_styles.json")); Gson gson = new GsonBuilder().setPrettyPrinting().create(); - return gson.fromJson(json, new TypeToken>(){}.getType()); + ArrayList styles = gson.fromJson(json, new TypeToken>() { + }.getType()); + if (Objects.isNull(styles)) { + new File(FCLPath.CONTROLLER_DIR + "/styles/button_styles.json").delete(); + } else { + list.addAll(styles); + } } catch (IOException e) { Logging.LOG.log(Level.SEVERE, "Failed to get button styles", e); - return new ArrayList<>(); } + return list; } public static ObservableList getStyles() { diff --git a/FCL/src/main/java/com/tungsten/fcl/control/data/DirectionStyles.java b/FCL/src/main/java/com/tungsten/fcl/control/data/DirectionStyles.java index 9529e338d..ea2e4bbcd 100644 --- a/FCL/src/main/java/com/tungsten/fcl/control/data/DirectionStyles.java +++ b/FCL/src/main/java/com/tungsten/fcl/control/data/DirectionStyles.java @@ -17,6 +17,7 @@ import java.io.File; import java.io.IOException; import java.util.ArrayList; +import java.util.Objects; import java.util.logging.Level; public class DirectionStyles { @@ -70,14 +71,20 @@ public static void init() { } private static ArrayList getStylesFromDisk() { + ArrayList list = new ArrayList<>(); try { String json = FileUtils.readText(new File(FCLPath.CONTROLLER_DIR + "/styles/direction_styles.json")); Gson gson = new GsonBuilder().setPrettyPrinting().create(); - return gson.fromJson(json, new TypeToken>(){}.getType()); + ArrayList styles = gson.fromJson(json, new TypeToken>(){}.getType()); + if (Objects.isNull(styles)) { + new File(FCLPath.CONTROLLER_DIR + "/styles/button_styles.json").delete(); + } else { + list.addAll(styles); + } } catch (IOException e) { Logging.LOG.log(Level.SEVERE, "Failed to get direction styles", e); - return new ArrayList<>(); } + return list; } public static ObservableList getStyles() {