OSDN Git Service

コンフィグ読み書き
[coroid/inqubus.git] / frontend / src / yukihane / inqubus / config / Properties.java
1 package yukihane.inqubus.config;
2
3 import java.io.File;
4 import java.util.ArrayList;
5 import java.util.Arrays;
6 import java.util.List;
7 import org.apache.commons.configuration.ConfigurationException;
8 import org.apache.commons.configuration.XMLConfiguration;
9
10 public enum Properties {
11
12     INSTANCE;
13     private final XMLConfiguration config = new XMLConfiguration();
14
15     public String getId() {
16         return config.getString("network.account.id", "");
17     }
18
19     /*
20      * ネットワーク - アカウント
21      */
22     public void setId(String s) {
23         config.setProperty("network.account.id", s);
24     }
25
26     public String getPassword() {
27         return config.getString("network.account.password", "");
28     }
29
30     public void setPassword(String s) {
31         config.setProperty("network.account.password", s);
32     }
33
34     /*
35      * ネットワーク - プロキシ
36      */
37     public boolean getUseProxy() {
38         return config.getBoolean("network.proxy.use", false);
39     }
40
41     public void setUseProxy(boolean s) {
42         config.setProperty("network.proxy.use", s);
43     }
44
45     public String getProxyHost() {
46         return config.getString("network.proxy.host", "");
47     }
48
49     public void setProxyHost(String s) {
50         config.setProperty("network.proxy.host", s);
51     }
52
53     /*
54      * ファイル - 動画
55      */
56     public File getVideoDir() {
57         return new File(config.getString("file.video.dir", "in/video"));
58     }
59
60     public void setVideoDir(File s) {
61         config.setProperty("file.video.dir", s.toString());
62     }
63
64     public String getVideoFileNamePattern() {
65         return config.getString("file.video.filename", "[{id}]{title}");
66     }
67
68     public void setVideoFileNamePattern(String s) {
69         config.setProperty("file.video.filename", s.toString());
70     }
71
72     public boolean getVideoUseLocal() {
73         return config.getBoolean("file.video.local", false);
74     }
75
76     public void setVideoUseLocal(boolean s) {
77         config.setProperty("file.video.local", s);
78     }
79
80     /*
81      * ファイル - コメント
82      */
83     private static final String FILE_COMMENT_DIR = "file.comment.dir";
84
85     public File getCommentDir() {
86         return new File(config.getString(FILE_COMMENT_DIR, "in/comment"));
87     }
88
89     public void setCommentDir(File s) {
90         config.setProperty(FILE_COMMENT_DIR, s.toString());
91     }
92     private static final String FILE_COMMENT_FILENAME = "file.comment.filename";
93
94     public String getCommentFileNamePattern() {
95         return config.getString(FILE_COMMENT_FILENAME, "[{id}]{title}");
96     }
97
98     public void setCommentFileNamePattern(String s) {
99         config.setProperty(FILE_COMMENT_FILENAME, s.toString());
100     }
101     private static final String FILE_COMMENT_LOCAL = "file.comment.local";
102
103     public boolean getCommentUseLocal() {
104         return config.getBoolean(FILE_COMMENT_LOCAL, false);
105     }
106
107     public void setCommentUseLocal(boolean s) {
108         config.setProperty(FILE_COMMENT_LOCAL, s);
109     }
110
111     /*
112      * ファイル - 変換動画
113      */
114     private static final String FILE_OUTPUT_DIR = "file.output.dir";
115
116     public File getOutputDir() {
117         return new File(config.getString(FILE_OUTPUT_DIR, "out"));
118     }
119
120     public void setOutputDir(File s) {
121         config.setProperty(FILE_OUTPUT_DIR, s.toString());
122     }
123     private static final String FILE_OUTPUT_FILENAME = "file.output.filename";
124
125     public String getOutputFileNamePattern() {
126         return config.getString(FILE_OUTPUT_FILENAME, "{filename}");
127     }
128
129     public void setOutputFileNamePattern(String s) {
130         config.setProperty(FILE_OUTPUT_FILENAME, s.toString());
131     }
132     private static final String FILE_OUTPUT_ENABLE = "file.output.enable";
133
134     public boolean getOutputEnable() {
135         return config.getBoolean(FILE_OUTPUT_ENABLE, true);
136     }
137
138     public void setOutputEnable(boolean s) {
139         config.setProperty(FILE_OUTPUT_ENABLE, s);
140     }
141     private static final String FILE_OUTPUT_COMMENT_OVERLAY = "file.output.comment_overlay";
142
143     public boolean getOutputCommentOverlay() {
144         return config.getBoolean(FILE_OUTPUT_COMMENT_OVERLAY, true);
145     }
146
147     public void setOutputCommentOverlay(boolean s) {
148         config.setProperty(FILE_OUTPUT_COMMENT_OVERLAY, s);
149     }
150     private static final String FILE_OUTPUT_DISPLAY_PROGRESS = "file.output.display";
151
152     public boolean getOutputDisplayProgress() {
153         return config.getBoolean(FILE_OUTPUT_DISPLAY_PROGRESS, true);
154     }
155
156     public void setOutputDisplayProgress(boolean s) {
157         config.setProperty(FILE_OUTPUT_DISPLAY_PROGRESS, s);
158     }
159     /**
160      * コメント
161      */
162     private static final String COMMENT_SIZE_AUTOSIZE = "comment.size.autosize";
163
164     public boolean getCommentSizeAutosize() {
165         return config.getBoolean(COMMENT_SIZE_AUTOSIZE, true);
166     }
167
168     public void setCommentSizeAutosize(boolean s) {
169         config.setProperty(COMMENT_SIZE_AUTOSIZE, s);
170     }
171     private static final String COMMENT_SIZE_MANUAL = "comment.size.manual";
172
173     public Integer getCommentSizeManual() {
174         return config.getInteger(COMMENT_SIZE_MANUAL, null);
175     }
176
177     public void setCommentSizeManual(Integer s) {
178         config.setProperty(COMMENT_SIZE_MANUAL, s);
179     }
180     private static final String COMMENT_MIN_SIZE_AUTOSIZE = "comment.minutesize.autosize";
181
182     public boolean getCommentMinSizeAutosize() {
183         return config.getBoolean(COMMENT_MIN_SIZE_AUTOSIZE, true);
184     }
185
186     public void setCommentMinSizeAutosize(boolean s) {
187         config.setProperty(COMMENT_MIN_SIZE_AUTOSIZE, s);
188     }
189     private static final String COMMENT_MIN_SIZE_MANUAL = "comment.minutesize.manual";
190
191     public Integer getCommentMinSizeManual() {
192         return config.getInteger(COMMENT_MIN_SIZE_MANUAL, null);
193     }
194
195     public void setCommentMinSizeManual(Integer s) {
196         config.setProperty(COMMENT_MIN_SIZE_MANUAL, s);
197     }
198     private static final String COMMENT_FONTPATH = "comment.fontpath";
199
200     public File getFontPath() {
201         return new File(config.getString(COMMENT_FONTPATH, "C:/Windows/Fonts/msgothic.ttc"));
202     }
203
204     public void setFontPath(File s) {
205         config.setProperty(COMMENT_FONTPATH, s);
206     }
207     private static final String COMMENT_FONT_INDEX = "comment.fontindex";
208
209     public Integer getFontIndex() {
210         return config.getInteger(COMMENT_FONT_INDEX, Integer.valueOf(1));
211     }
212
213     public void setFontIndex(Integer s) {
214         config.setProperty(COMMENT_FONT_INDEX, s);
215     }
216     private static final String COMMENT_FONT_SHADOW = "comment.fontshadow";
217
218     public int getFontShadow() {
219         return config.getInt(COMMENT_FONT_SHADOW, 1);
220     }
221
222     public void setFontIndex(int s) {
223         config.setProperty(COMMENT_FONT_SHADOW, s);
224     }
225     private static final String COMMENT_FONT_SIZING_DISABLE = "comment.font_no_sizing";
226
227     public boolean getFontSizeDisable() {
228         return config.getBoolean(COMMENT_FONT_SIZING_DISABLE, false);
229     }
230
231     public void setFontSizeDisable(boolean s) {
232         config.setProperty(COMMENT_FONT_SIZING_DISABLE, s);
233     }
234     private static final String COMMENT_FONT_OPAQUE = "comment.opaque";
235
236     public boolean getCommentOpaque() {
237         return config.getBoolean(COMMENT_FONT_OPAQUE, false);
238     }
239
240     public void setCommentOpaque(boolean s) {
241         config.setProperty(COMMENT_FONT_OPAQUE, s);
242     }
243     private static final String FFMPEG_PATH = "ffmpeg.path";
244
245     public File getFfmpegPath() {
246         return new File(config.getString(FFMPEG_PATH, "bin/ffmpeg.exe"));
247     }
248
249     public void setFfmpegPath(File s) {
250         config.setProperty(FFMPEG_PATH, s.toString());
251     }
252     private static final String FFMPEG_DLLPATH = "ffmpeg.dllpath";
253
254     public File getFfmpegDllPath() {
255         return new File(config.getString(FFMPEG_DLLPATH, "bin/nicovideo.dll"));
256     }
257
258     public void setFfmpegDllPath(File s) {
259         config.setProperty(FFMPEG_DLLPATH, s.toString());
260     }
261     private static final String FFMPEG_PARAM_DIRECT = "ffmpeg.param.direct";
262
263     public boolean getFfmpegParamInputDirect() {
264         return config.getBoolean(FFMPEG_PARAM_DIRECT, true);
265     }
266
267     public void setFfmpegParamInputDirect(boolean s) {
268         config.setProperty(FFMPEG_PARAM_DIRECT, s);
269     }
270     private static final String FFMPEG_PARAM_OPTIONFILE = "ffmpeg.param.optionfile";
271
272     public String getFfmpegOptionFile() {
273         return config.getString(FFMPEG_PARAM_OPTIONFILE, "");
274     }
275
276     public void setFfmpegOptionFile(String s) {
277         config.setProperty(FFMPEG_PARAM_OPTIONFILE, s);
278     }
279     private static final String FFMPEG_PARAM_EXT = "ffmpeg.param.ext";
280
281     public String getFfmpegExtension() {
282         return config.getString(FFMPEG_PARAM_EXT, "");
283     }
284
285     public void setFfmpegExtension(String s) {
286         config.setProperty(FFMPEG_PARAM_EXT, s);
287     }
288     private static final String FFMPEG_PARAM_MAIN = "ffmpeg.param.main";
289
290     public String getFfmpegMainOption() {
291         return config.getString(FFMPEG_PARAM_MAIN, "");
292     }
293
294     public void setFfmpegMainOption(String s) {
295         config.setProperty(FFMPEG_PARAM_MAIN, s);
296     }
297     private static final String FFMPEG_PARAM_IN = "ffmpeg.param.in";
298
299     public String getFfmpegInOption() {
300         return config.getString(FFMPEG_PARAM_IN, "");
301     }
302
303     public void setFfmpegInOption(String s) {
304         config.setProperty(FFMPEG_PARAM_IN, s);
305     }
306     private static final String FFMPEG_PARAM_OUT = "ffmpeg.param.out";
307
308     public String getFfmpegOutOption() {
309         return config.getString(FFMPEG_PARAM_OUT, "");
310     }
311
312     public void setFfmpegOutOption(String s) {
313         config.setProperty(FFMPEG_PARAM_OUT, s);
314     }
315     private static final String FFMPEG_PARAM_AV = "ffmpeg.param.av";
316
317     public String getFfmpegAvOption() {
318         return config.getString(FFMPEG_PARAM_AV, "");
319     }
320
321     public void setFfmpegAvOption(String s) {
322         config.setProperty(FFMPEG_PARAM_AV, s);
323     }
324     private static final String FFMPEG_PARAM_RESIZE = "ffmpeg.param.resize";
325
326     public boolean getFfmpegResizeEnable() {
327         return config.getBoolean(FFMPEG_PARAM_RESIZE, false);
328     }
329
330     public void setFfmpegResizeEnable(boolean s) {
331         config.setProperty(FFMPEG_PARAM_RESIZE, s);
332     }
333     private static final String FFMPEG_PARAM_RESIZE_WIDTH = "ffmpeg.param.resize_width";
334
335     public Integer getFfmpegResizeWidth() {
336         return config.getInteger(FFMPEG_PARAM_RESIZE_WIDTH, Integer.valueOf(480));
337     }
338
339     public void getFfmpegResizeWidth(Integer s) {
340         config.setProperty(FFMPEG_PARAM_RESIZE_WIDTH, s);
341     }
342     private static final String FFMPEG_PARAM_RESIZE_HEIGHT = "ffmpeg.param.resize_height";
343
344     public Integer getFfmpegResizeHeight() {
345         return config.getInteger(FFMPEG_PARAM_RESIZE_HEIGHT, Integer.valueOf(480));
346     }
347
348     public void getFfmpegResizeHeight(Integer s) {
349         config.setProperty(FFMPEG_PARAM_RESIZE_HEIGHT, s);
350     }
351     private static final String FFMPEG_PARAM_KEEP_ASPECT = "ffmpeg.param.keep_aspect";
352
353     public boolean getFfmpegKeepAspect() {
354         return config.getBoolean(FFMPEG_PARAM_KEEP_ASPECT, true);
355     }
356
357     public void setFfmpegKeepAspect(boolean s) {
358         config.setProperty(FFMPEG_PARAM_KEEP_ASPECT, s);
359     }
360     private static final String NG_WORD = "ng.word";
361
362     @SuppressWarnings("unchecked")
363     public List<String> getNgWords() {
364         return config.getList(NG_WORD, new ArrayList<String>(0));
365     }
366
367     public void setNgWords(List<String> s) {
368         final String[] str = s.toArray(new String[0]);
369         config.setProperty(NG_WORD, s);
370     }
371     private static final String NG_ID = "ng.id";
372
373     @SuppressWarnings("unchecked")
374     public List<String> getNgIds() {
375         return config.getList(NG_ID, new ArrayList<String>(0));
376     }
377
378     public void setNgIds(List<String> s) {
379         config.setProperty(NG_ID, s);
380     }
381
382     /*
383      *
384      */
385     public void load(String fileName) throws ConfigurationException {
386         config.setFileName(fileName);
387         config.load();
388     }
389
390     public void save(File file) throws ConfigurationException {
391         config.setFile(file);
392         save();
393     }
394
395     public void save() throws ConfigurationException {
396         throw new UnsupportedOperationException();
397 //        try {
398 //            final Class<? extends Properties> clazz = this.getClass();
399 //            final Field[] fields = clazz.getDeclaredFields();
400 //            final Field[] propertyFields = getPropertyFields(fields);
401 //            for (Field f : propertyFields) {
402 //                config.setProperty(getPropertyName(f), getPropertyValue(f));
403 //            }
404 //            config.save();
405 //        } catch (SecurityException | IllegalArgumentException | IllegalAccessException | ConfigurationException ex) {
406 //            throw new ConfigurationException(ex);
407 //        }
408     }
409 //    private Field[] getPropertyFields(Field[] fields) {
410 //        List<Field> res = new ArrayList<Field>();
411 //        for (Field f : fields) {
412 //            if (f.getName().startsWith(getPrefix())) {
413 //                res.add(f);
414 //            }
415 //        }
416 //        return res.toArray(new Field[0]);
417 //    }
418 //
419 //    private String getPropertyName(Field field) {
420 //        return field.getName().replace(getPrefix(), "").replace("_", ".");
421 //    }
422 //
423 //    private String getPropertyValue(Field field) throws IllegalArgumentException, IllegalAccessException {
424 //        field.setAccessible(true);
425 //        return (String) field.get(this);
426 //    }
427 //
428 //    public boolean getUseMovieFileLocal() {
429 //        // TODO
430 //        return false;
431 //    }
432 //
433 //    public boolean getCommentFileLocal() {
434 //        // TODO
435 //        return false;
436 //    }
437 //
438 //    public boolean getOutputConvert() {
439 //        // TODO
440 //        return true;
441 //    }
442 //
443 //    public String getFileNamePattern() {
444 //        // TODO
445 //        return "[{id}]{title}";
446 //    }
447 }