• R/O
  • HTTP
  • SSH
  • HTTPS

Jindolf: 提交

Jindolfプロジェクトは、CGIゲーム「人狼BBS」を快適にプレイするための専用クライアントを製作するために発足したオープンソースプロジェクトです。


Commit MetaInfo

修订版ec54c05beb09ec750d75ea01eb4bd555f161807d (tree)
时间2020-05-09 17:43:41
作者Olyutorskii <olyutorskii@user...>
CommiterOlyutorskii

Log Message

add copyResource()

更改概述

差异

--- a/src/main/java/jp/sfjp/jindolf/config/ConfigDirUtils.java
+++ b/src/main/java/jp/sfjp/jindolf/config/ConfigDirUtils.java
@@ -125,6 +125,8 @@ public final class ConfigDirUtils{
125125 "ディレクトリ{0}を生成できません";
126126 private static final String LOG_CREATEERR =
127127 "ファイル{0}を生成できません";
128+ private static final String LOG_RESCPY =
129+ "内部リソースから{0}へコピーが行われました。";
128130
129131 private static final int ERR_ABORT = 1;
130132
@@ -173,38 +175,8 @@ public final class ConfigDirUtils{
173175 * @param txt メッセージ
174176 */
175177 private static void showErrorMessage(String txt){
176- JOptionPane pane;
177- pane = new JOptionPane(txt, JOptionPane.ERROR_MESSAGE);
178- showDialog(pane);
179- return;
180- }
181-
182- /**
183- * 設定ディレクトリ操作の
184- * 共通エラーメッセージ確認ダイアログを表示する。
185- *
186- * <p>閉じるまで待つ。
187- *
188- * @param txt メッセージtxt
189- */
190- private static void showWarnMessage(String txt){
191- JOptionPane pane;
192- pane = new JOptionPane(txt, JOptionPane.WARNING_MESSAGE);
193- showDialog(pane);
194- return;
195- }
196-
197- /**
198- * 設定ディレクトリ操作の
199- * 情報提示メッセージ確認ダイアログを表示する。
200- *
201- * <p>閉じるまで待つ。
202- *
203- * @param txt メッセージtxt
204- */
205- private static void showInfoMessage(String txt){
206- JOptionPane pane;
207- pane = new JOptionPane(txt, JOptionPane.INFORMATION_MESSAGE);
178+ JOptionPane pane = new JOptionPane(
179+ txt, JOptionPane.ERROR_MESSAGE);
208180 showDialog(pane);
209181 return;
210182 }
@@ -223,18 +195,6 @@ public final class ConfigDirUtils{
223195 }
224196
225197 /**
226- * 設定ディレクトリ生成をやめた操作への警告をダイアログで提示し、
227- * VM終了する。
228- */
229- private static void abortQuitBuildConfigDir(){
230- showWarnMessage(MSG_ABORT);
231- abort();
232- assert false;
233-
234- return;
235- }
236-
237- /**
238198 * ディレクトリが生成できないエラーをダイアログで提示し、
239199 * VM終了する。
240200 *
@@ -269,22 +229,6 @@ public final class ConfigDirUtils{
269229 }
270230
271231 /**
272- * ファイルに書き込めないエラーをダイアログで提示し、VM終了する。
273- *
274- * @param path 書き込めなかったファイル
275- */
276- private static void abortCantWrite(Path path){
277- String fileName = getCenteredFileName(path);
278- String msg = MessageFormat.format(FORM_WRITEERR, fileName);
279-
280- showErrorMessage(msg);
281- abort();
282- assert false;
283-
284- return;
285- }
286-
287- /**
288232 * ディレクトリが生成できない異常系をログ出力する。
289233 *
290234 * @param dirPath 生成できなかったディレクトリ
@@ -298,15 +242,33 @@ public final class ConfigDirUtils{
298242 }
299243
300244 /**
301- * ファイルが生成できない異常系をログ出力する。
245+ * リソースからローカルファイルへコピーする。
302246 *
303- * @param filePath 生成できなかったファイル
304- * @param cause 異常系原因
247+ * @param resource リソース名
248+ * @param dest ローカルファイル
305249 */
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);
250+ private static void copyResource(String resource, Path dest){
251+ try(InputStream ris =
252+ ResourceManager.getResourceAsStream(resource)){
253+ InputStream is = new BufferedInputStream(ris);
254+ Files.copy(is, dest);
255+ }catch(IOException | SecurityException e){
256+ String destName = dest.toString();
257+ String logMsg = MessageFormat.format(LOG_CREATEERR, destName);
258+ LOGGER.log(Level.SEVERE, logMsg, e);
259+
260+ String destHtml = getCenteredFileName(dest);
261+ String diagMsg = MessageFormat.format(FORM_WRITEERR, destHtml);
262+ showErrorMessage(diagMsg);
263+ abort();
264+
265+ assert false;
266+ }
267+
268+ String destName = dest.toString();
269+ String msg = MessageFormat.format(LOG_RESCPY, destName);
270+ LOGGER.info(msg);
271+
310272 return;
311273 }
312274
@@ -407,7 +369,10 @@ public final class ConfigDirUtils{
407369
408370 boolean confirmed = confirmBuildConfigDir(absPath);
409371 if( ! confirmed ){
410- abortQuitBuildConfigDir();
372+ JOptionPane pane = new JOptionPane(
373+ MSG_ABORT, JOptionPane.WARNING_MESSAGE);
374+ showDialog(pane);
375+ abort();
411376 assert false;
412377 }
413378
@@ -423,7 +388,8 @@ public final class ConfigDirUtils{
423388
424389 checkDirPerm(absPath);
425390
426- touchReadme(absPath);
391+ Path readme = absPath.resolve(FILE_README);
392+ copyResource(RES_README, readme);
427393
428394 return absPath;
429395 }
@@ -475,16 +441,7 @@ public final class ConfigDirUtils{
475441 checkDirPerm(absPath);
476442
477443 Path jsonPath = imgCacheDir.resolve(FILE_AVATARJSON);
478-
479- try(InputStream ris =
480- ResourceManager.getResourceAsStream(RES_AVATARJSON)){
481- InputStream is = new BufferedInputStream(ris);
482- Files.copy(is, jsonPath);
483- }catch(IOException | SecurityException e){
484- logCreateErr(jsonPath, e);
485- abortCantWrite(jsonPath);
486- assert false;
487- }
444+ copyResource(RES_AVATARJSON, jsonPath);
488445
489446 return;
490447 }
@@ -525,7 +482,9 @@ public final class ConfigDirUtils{
525482 if(lockPane.isRadioRetry()){
526483 lock.tryLock();
527484 }else if(lockPane.isRadioContinue()){
528- showInfoMessage(MSG_NOCONF);
485+ JOptionPane pane = new JOptionPane(
486+ MSG_NOCONF, JOptionPane.INFORMATION_MESSAGE);
487+ showDialog(pane);
529488 break;
530489 }else if(lockPane.isRadioForce()){
531490 forceRemove(lock);
@@ -573,27 +532,4 @@ public final class ConfigDirUtils{
573532 return;
574533 }
575534
576- /**
577- * 指定されたディレクトリにREADMEファイルを生成する。
578- *
579- * <p>生成できなければダイアログ表示とともにVM終了する。
580- *
581- * @param path READMEの格納ディレクトリ
582- */
583- private static void touchReadme(Path path){
584- Path readme = path.resolve(FILE_README);
585-
586- try(InputStream ris =
587- ResourceManager.getResourceAsStream(RES_README)){
588- InputStream is = new BufferedInputStream(ris);
589- Files.copy(is, readme);
590- }catch(IOException | SecurityException e){
591- logCreateErr(readme, e);
592- abortCantWrite(readme);
593- assert false;
594- }
595-
596- return;
597- }
598-
599535 }
Show on old repository browser