Skip to content

Commit

Permalink
fix crash caused by style #422
Browse files Browse the repository at this point in the history
  • Loading branch information
ShirosakiMio committed Jul 1, 2024
1 parent 36f1b75 commit d535fa8
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 4 deletions.
12 changes: 10 additions & 2 deletions FCL/src/main/java/com/tungsten/fcl/control/data/ButtonStyles.java
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -70,14 +71,21 @@ public static void init() {
}

private static ArrayList<ControlButtonStyle> getStylesFromDisk() {
ArrayList<ControlButtonStyle> 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<ArrayList<ControlButtonStyle>>(){}.getType());
ArrayList<ControlButtonStyle> styles = gson.fromJson(json, new TypeToken<ArrayList<ControlButtonStyle>>() {
}.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<ControlButtonStyle> getStyles() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -70,14 +71,20 @@ public static void init() {
}

private static ArrayList<ControlDirectionStyle> getStylesFromDisk() {
ArrayList<ControlDirectionStyle> 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<ArrayList<ControlDirectionStyle>>(){}.getType());
ArrayList<ControlDirectionStyle> styles = gson.fromJson(json, new TypeToken<ArrayList<ControlDirectionStyle>>(){}.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<ControlDirectionStyle> getStyles() {
Expand Down

0 comments on commit d535fa8

Please sign in to comment.