4 import java.io.IOException;
5 import java.nio.file.Files;
6 import java.nio.file.Path;
7 import java.nio.file.Paths;
9 import org.slf4j.Logger;
10 import org.slf4j.LoggerFactory;
12 import com.fasterxml.jackson.core.util.DefaultPrettyPrinter;
13 import com.fasterxml.jackson.databind.JsonNode;
14 import com.fasterxml.jackson.databind.ObjectMapper;
15 import com.fasterxml.jackson.databind.ObjectWriter;
18 * 「settings.json」ファイルから各種設定を読み込みます
20 * ・起動時のバージョンチェック (checkVersion)
21 * ・起動時にライブラリの更新有無のチェック (checkLibraryUpdates)
22 * ・ウィンドウサイズ (windowWidth), (windowHeight)
23 * ・デフォルトの曲指定上限数 (songsLimit)
24 * ・スコアログの保存 (saveScoreLog)
31 public class Settings {
34 private final static String FILEPATH = "generated/settings.json";
35 private static Logger logger = LoggerFactory.getLogger(Settings.class);
37 public static boolean fileExists() {
38 Path path = Paths.get(FILEPATH);
39 return Files.exists(path);
42 public static boolean needToCheckVersion() {
44 ObjectMapper mapper = new ObjectMapper();
46 JsonNode node = mapper.readTree(new File(FILEPATH));
47 res = node.get("checkVersion").asBoolean();
48 } catch (IOException e) {
49 logger.error("Couldn't read setting file.", e);
54 public static boolean needToCheckLibraryUpdates() {
56 ObjectMapper mapper = new ObjectMapper();
58 JsonNode node = mapper.readTree(new File(FILEPATH));
59 res = node.get("checkLibraryUpdates").asBoolean();
60 } catch (IOException e) {
61 logger.error("Couldn't read setting file.", e);
66 public static int getWindowWidth() {
68 ObjectMapper mapper = new ObjectMapper();
70 JsonNode node = mapper.readTree(new File(FILEPATH));
71 res = node.get("windowWidth").asInt();
72 } catch (IOException e) {
73 logger.error("Couldn't read setting file.", e);
75 return res < 1 ? 640 : res;
78 public static int getWindowHeight() {
80 ObjectMapper mapper = new ObjectMapper();
82 JsonNode node = mapper.readTree(new File(FILEPATH));
83 res = node.get("windowHeight").asInt();
84 } catch (IOException e) {
85 logger.error("Couldn't read setting file.", e);
87 return res < 1 ? 360 : res;
90 public static int getSongsLimit() {
92 ObjectMapper mapper = new ObjectMapper();
94 JsonNode node = mapper.readTree(new File(FILEPATH));
95 res = node.get("songLimit").asInt();
96 } catch (IOException e) {
97 logger.error("Couldn't read setting file.", e);
99 return res < 1 ? 3 : res;
102 public static boolean saveScoreLog() {
104 ObjectMapper mapper = new ObjectMapper();
106 JsonNode node = mapper.readTree(new File(FILEPATH));
107 res = node.get("saveScoreLog").asBoolean();
108 } catch (IOException e) {
109 logger.error("Couldn't read setting file.", e);
114 public static boolean writeDownJSON() {
116 SettingJSONProperty property = new SettingJSONProperty();
117 property.setCheckVersion(true);
118 property.setCheckLibraryUpdates(true);
119 property.setWindowWidth(640);
120 property.setWindowHeight(360);
121 property.setSongLimit(3);
122 property.setSaveScoreLog(false);
123 ObjectWriter writer = new ObjectMapper().writer(new DefaultPrettyPrinter());
125 writer.writeValue(Paths.get(FILEPATH).toFile(), property);
126 } catch (IOException e) {
127 logger.error("Couldn't write down setting file.", e);