Jindolfプロジェクトは、CGIゲーム「人狼BBS」を快適にプレイするための専用クライアントを製作するために発足したオープンソースプロジェクトです。
修订版 | 8132c02e9d31234ca27a0f1c3078d3595d5bcc81 (tree) |
---|---|
时间 | 2020-05-08 14:05:53 |
作者 | Olyutorskii <olyutorskii@user...> |
Commiter | Olyutorskii |
split format templates.
@@ -25,6 +25,9 @@ import jp.sfjp.jindolf.view.LockErrorPane; | ||
25 | 25 | |
26 | 26 | /** |
27 | 27 | * Jindolf設定格納ディレクトリに関するあれこれ。 |
28 | + * | |
29 | + * <p>ファイル操作の異常系に関する、 | |
30 | + * ユーザとのインタラクション動作など。 | |
28 | 31 | */ |
29 | 32 | public final class ConfigDirUtils{ |
30 | 33 |
@@ -53,7 +56,8 @@ public final class ConfigDirUtils{ | ||
53 | 56 | + " オプション指定により、<br/>" |
54 | 57 | + "設定格納ディレクトリを使わずに起動することができます。<br/>" |
55 | 58 | + "</ul>"; |
56 | - private static final String MSG_NOCONF = "<html>" | |
59 | + private static final String MSG_NOCONF = | |
60 | + "<html>" | |
57 | 61 | + "設定ディレクトリを使わずに起動を続行します。<br/>" |
58 | 62 | + "今回、各種設定の読み込み・保存はできません。<br/>" |
59 | 63 | + "<code>" |
@@ -61,7 +65,13 @@ public final class ConfigDirUtils{ | ||
61 | 65 | + "</code> オプション" |
62 | 66 | + "を使うとこの警告は出なくなります。" |
63 | 67 | + "</html>"; |
64 | - private static final String FORM_FAILRM = "<html>" | |
68 | + private static final String MSG_ABORT = | |
69 | + "<html>" | |
70 | + + "設定ディレクトリの作成をせずに起動を中止します。<br/>" | |
71 | + + MSG_POST | |
72 | + + "</html>"; | |
73 | + private static final String FORM_FAILRM = | |
74 | + "<html>" | |
65 | 75 | + "ロックファイルの強制解除に失敗しました。<br/>" |
66 | 76 | + "他に動いているJindolf" |
67 | 77 | + "が見つからないのであれば、<br/>" |
@@ -70,12 +80,51 @@ public final class ConfigDirUtils{ | ||
70 | 80 | + "を削除してください。<br/>" |
71 | 81 | + "起動を中止します。" |
72 | 82 | + "</html>"; |
73 | - private static final String FORM_ILLLOCK = "<html>" | |
83 | + private static final String FORM_ILLLOCK = | |
84 | + "<html>" | |
74 | 85 | + "ロックファイル<br/>" |
75 | 86 | + "{0}" |
76 | 87 | + "を確保することができません。<br/>" |
77 | 88 | + "起動を中止します。" |
78 | 89 | + "</html>"; |
90 | + private static final String FORM_MKDIRFAIL = | |
91 | + "<html>" | |
92 | + + "ディレクトリ<br/>" | |
93 | + + "{0}" | |
94 | + + "の作成に失敗しました。" | |
95 | + + "起動を中止します。<br/>" | |
96 | + + MSG_POST | |
97 | + + "</html>"; | |
98 | + private static final String FORM_ACCERR = | |
99 | + "<html>" | |
100 | + + "ディレクトリ<br/>" | |
101 | + + "{0}" | |
102 | + + "へのアクセスができません。" | |
103 | + + "起動を中止します。<br/>" | |
104 | + + "このディレクトリへのアクセス権を調整し" | |
105 | + + "読み書きできるようにしてください。<br/>" | |
106 | + + MSG_POST | |
107 | + + "</html>"; | |
108 | + private static final String FORM_WRITEERR = | |
109 | + "<html>" | |
110 | + + "ファイル<br/>" | |
111 | + + "{0}" | |
112 | + + "への書き込みができません。" | |
113 | + + "起動を中止します。<br/>" | |
114 | + + "</html>"; | |
115 | + private static final String FORM_MKCONF = | |
116 | + "<html>" | |
117 | + + "設定ファイル格納ディレクトリ<br/>" | |
118 | + + "{0}を作成します。<br/>" | |
119 | + + "このディレクトリを今から作成して構いませんか?<br/>" | |
120 | + + "このディレクトリ名は、後からいつでもヘルプウィンドウで<br/>" | |
121 | + + "確認することができます。" | |
122 | + + "</html>"; | |
123 | + | |
124 | + private static final String LOG_MKDIRERR = | |
125 | + "ディレクトリ{0}を生成できません"; | |
126 | + private static final String LOG_CREATEERR = | |
127 | + "ファイル{0}を生成できません"; | |
79 | 128 | |
80 | 129 | private static final int ERR_ABORT = 1; |
81 | 130 |
@@ -178,13 +227,7 @@ public final class ConfigDirUtils{ | ||
178 | 227 | * VM終了する。 |
179 | 228 | */ |
180 | 229 | private static void abortQuitBuildConfigDir(){ |
181 | - String msg = | |
182 | - "<html>" | |
183 | - + "設定ディレクトリの作成をせずに起動を中止します。<br/>" | |
184 | - + MSG_POST | |
185 | - + "</html>"; | |
186 | - | |
187 | - showWarnMessage(msg); | |
230 | + showWarnMessage(MSG_ABORT); | |
188 | 231 | abort(); |
189 | 232 | assert false; |
190 | 233 |
@@ -198,16 +241,8 @@ public final class ConfigDirUtils{ | ||
198 | 241 | * @param path 生成できなかったディレクトリ |
199 | 242 | */ |
200 | 243 | private static void abortCantBuildDir(Path path){ |
201 | - String form = | |
202 | - "<html>" | |
203 | - + "ディレクトリ<br/>" | |
204 | - + "{0}" | |
205 | - + "の作成に失敗しました。" | |
206 | - + "起動を中止します。<br/>" | |
207 | - + MSG_POST | |
208 | - + "</html>"; | |
209 | 244 | String fileName = getCenteredFileName(path); |
210 | - String msg = MessageFormat.format(form, fileName); | |
245 | + String msg = MessageFormat.format(FORM_MKDIRFAIL, fileName); | |
211 | 246 | |
212 | 247 | showErrorMessage(msg); |
213 | 248 | abort(); |
@@ -223,18 +258,8 @@ public final class ConfigDirUtils{ | ||
223 | 258 | * @param path アクセスできないディレクトリ |
224 | 259 | */ |
225 | 260 | private static void abortCantAccessDir(Path path){ |
226 | - String form = | |
227 | - "<html>" | |
228 | - + "ディレクトリ<br/>" | |
229 | - + "{0}" | |
230 | - + "へのアクセスができません。" | |
231 | - + "起動を中止します。<br/>" | |
232 | - + "このディレクトリへのアクセス権を調整し" | |
233 | - + "読み書きできるようにしてください。<br/>" | |
234 | - + MSG_POST | |
235 | - + "</html>"; | |
236 | 261 | String fileName = getCenteredFileName(path); |
237 | - String msg = MessageFormat.format(form, fileName); | |
262 | + String msg = MessageFormat.format(FORM_ACCERR, fileName); | |
238 | 263 | |
239 | 264 | showErrorMessage(msg); |
240 | 265 | abort(); |
@@ -249,15 +274,8 @@ public final class ConfigDirUtils{ | ||
249 | 274 | * @param path 書き込めなかったファイル |
250 | 275 | */ |
251 | 276 | private static void abortCantWrite(Path path){ |
252 | - String form = | |
253 | - "<html>" | |
254 | - + "ファイル<br/>" | |
255 | - + "{0}" | |
256 | - + "への書き込みができません。" | |
257 | - + "起動を中止します。<br/>" | |
258 | - + "</html>"; | |
259 | 277 | String fileName = getCenteredFileName(path); |
260 | - String msg = MessageFormat.format(form, fileName); | |
278 | + String msg = MessageFormat.format(FORM_WRITEERR, fileName); | |
261 | 279 | |
262 | 280 | showErrorMessage(msg); |
263 | 281 | abort(); |
@@ -267,6 +285,32 @@ public final class ConfigDirUtils{ | ||
267 | 285 | } |
268 | 286 | |
269 | 287 | /** |
288 | + * ディレクトリが生成できない異常系をログ出力する。 | |
289 | + * | |
290 | + * @param dirPath 生成できなかったディレクトリ | |
291 | + * @param cause 異常系原因 | |
292 | + */ | |
293 | + private static void logMkdirErr(Path dirPath, Throwable cause){ | |
294 | + String pathTxt = dirPath.toString(); | |
295 | + String msg = MessageFormat.format(LOG_MKDIRERR, pathTxt); | |
296 | + LOGGER.log(Level.SEVERE, msg, cause); | |
297 | + return; | |
298 | + } | |
299 | + | |
300 | + /** | |
301 | + * ファイルが生成できない異常系をログ出力する。 | |
302 | + * | |
303 | + * @param filePath 生成できなかったファイル | |
304 | + * @param cause 異常系原因 | |
305 | + */ | |
306 | + private static void logCreateErr(Path filePath, Throwable cause){ | |
307 | + String pathTxt = filePath.toString(); | |
308 | + String msg = MessageFormat.format(LOG_CREATEERR, pathTxt); | |
309 | + LOGGER.log(Level.SEVERE, msg, cause); | |
310 | + return; | |
311 | + } | |
312 | + | |
313 | + /** | |
270 | 314 | * 設定ディレクトリがアクセス可能でなければ |
271 | 315 | * エラーダイアログを出してVM終了する。 |
272 | 316 | * |
@@ -370,9 +414,7 @@ public final class ConfigDirUtils{ | ||
370 | 414 | try{ |
371 | 415 | Files.createDirectories(absPath); |
372 | 416 | }catch(IOException | SecurityException e){ |
373 | - String msg = MessageFormat.format( | |
374 | - "{0}を生成できません", absPath.toString()); | |
375 | - LOGGER.log(Level.SEVERE, msg, e); | |
417 | + logMkdirErr(absPath, e); | |
376 | 418 | abortCantBuildDir(absPath); |
377 | 419 | assert false; |
378 | 420 | } |
@@ -393,16 +435,8 @@ public final class ConfigDirUtils{ | ||
393 | 435 | * @return 生成してよいと指示があればtrue |
394 | 436 | */ |
395 | 437 | private static boolean confirmBuildConfigDir(Path confDir){ |
396 | - String form = | |
397 | - "<html>" | |
398 | - + "設定ファイル格納ディレクトリ<br/>" | |
399 | - + "{0}を作成します。<br/>" | |
400 | - + "このディレクトリを今から作成して構いませんか?<br/>" | |
401 | - + "このディレクトリ名は、後からいつでもヘルプウィンドウで<br/>" | |
402 | - + "確認することができます。" | |
403 | - + "</html>"; | |
404 | 438 | String confName = getCenteredFileName(confDir); |
405 | - String msg = MessageFormat.format(form, confName); | |
439 | + String msg = MessageFormat.format(FORM_MKCONF, confName); | |
406 | 440 | |
407 | 441 | JOptionPane pane; |
408 | 442 | pane = new JOptionPane(msg, |
@@ -432,10 +466,8 @@ public final class ConfigDirUtils{ | ||
432 | 466 | |
433 | 467 | try{ |
434 | 468 | Files.createDirectories(absPath); |
435 | - }catch(IOException e){ | |
436 | - String msg = MessageFormat.format( | |
437 | - "ディレクトリ{0}を生成できません", absPath.toString()); | |
438 | - LOGGER.log(Level.SEVERE, msg, e); | |
469 | + }catch(IOException | SecurityException e){ | |
470 | + logMkdirErr(absPath, e); | |
439 | 471 | abortCantBuildDir(absPath); |
440 | 472 | assert false; |
441 | 473 | } |
@@ -448,11 +480,8 @@ public final class ConfigDirUtils{ | ||
448 | 480 | ResourceManager.getResourceAsStream(RES_AVATARJSON)){ |
449 | 481 | InputStream is = new BufferedInputStream(ris); |
450 | 482 | Files.copy(is, jsonPath); |
451 | - }catch(IOException e){ | |
452 | - String msg = MessageFormat.format( | |
453 | - "ファイル{0}を生成できませんでした", jsonPath.toString() | |
454 | - ); | |
455 | - LOGGER.log(Level.SEVERE, msg, e); | |
483 | + }catch(IOException | SecurityException e){ | |
484 | + logCreateErr(jsonPath, e); | |
456 | 485 | abortCantWrite(jsonPath); |
457 | 486 | assert false; |
458 | 487 | } |
@@ -558,11 +587,8 @@ public final class ConfigDirUtils{ | ||
558 | 587 | ResourceManager.getResourceAsStream(RES_README)){ |
559 | 588 | InputStream is = new BufferedInputStream(ris); |
560 | 589 | Files.copy(is, readme); |
561 | - }catch(IOException e){ | |
562 | - String msg = MessageFormat.format( | |
563 | - "{0}が生成できませんでした", readme.toString() | |
564 | - ); | |
565 | - LOGGER.log(Level.SEVERE, msg, e); | |
590 | + }catch(IOException | SecurityException e){ | |
591 | + logCreateErr(readme, e); | |
566 | 592 | abortCantWrite(readme); |
567 | 593 | assert false; |
568 | 594 | } |