OSDN Git Service

getConfigPath() to getConfigDir()
authorOlyutorskii <olyutorskii@users.osdn.me>
Wed, 25 Mar 2020 13:10:42 +0000 (22:10 +0900)
committerOlyutorskii <olyutorskii@users.osdn.me>
Wed, 25 Mar 2020 13:10:42 +0000 (22:10 +0900)
src/main/java/jp/sfjp/jindolf/JindolfMain.java
src/main/java/jp/sfjp/jindolf/config/ConfigFile.java
src/main/java/jp/sfjp/jindolf/config/ConfigStore.java
src/main/java/jp/sfjp/jindolf/view/HelpFrame.java

index 2485ce3..e672c2c 100644 (file)
@@ -31,7 +31,7 @@ import jp.sfjp.jindolf.view.WindowManager;
 /**
  * Jindolf スタートアップクラス。
  *
- * <p>{@link JindolfJre17}の下請けとして本格的なJindolf起動処理に入る。
+ * <p>{@link JindolfJre18}の下請けとして本格的なJindolf起動処理に入る。
  */
 public final class JindolfMain {
 
@@ -137,7 +137,7 @@ public final class JindolfMain {
 
         ConfigStore configStore = appSetting.getConfigStore();
         if(configStore.useStoreFile()){
-            LOGGER.log(Level.INFO, LOG_CONF, configStore.getConfigPath());
+            LOGGER.log(Level.INFO, LOG_CONF, configStore.getConfigDir());
         }else{
             LOGGER.info(LOG_NOCONF);
         }
index fe92f87..6679934 100644 (file)
@@ -48,22 +48,31 @@ public final class ConfigFile{
      * 隠れコンストラクタ。
      */
     private ConfigFile(){
-        super();
+        assert false;
         return;
     }
 
 
     /**
      * 暗黙的な設定格納ディレクトリを返す。
-     * 起動元JARファイルと同じディレクトリに、
+     *
+     * <ul>
+     *
+     * <li>起動元JARファイルと同じディレクトリに、
      * アクセス可能なディレクトリ"Jindolf"が
      * すでに存在していればそれを返す。
-     * 起動元JARファイルおよび"Jindolf"が発見できなければ、
+     *
+     * <li>起動元JARファイルおよび"Jindolf"が発見できなければ、
      * MacOSX環境の場合"~/Library/Application Support/Jindolf/"を返す。
      * Windows環境の場合"%USERPROFILE%\Jindolf\"を返す。
-     * それ以外の環境(Linux,etc?)の場合"~/.jindolf/"を返す。
-     * 返すディレクトリが存在しているか否か、
+     *
+     * <li>それ以外の環境(Linux,etc?)の場合"~/.jindolf/"を返す。
+     *
+     * </ul>
+     *
+     * <p>返すディレクトリが存在しているか否か、
      * アクセス可能か否かは呼び出し元で判断せよ。
+     *
      * @return 設定格納ディレクトリ
      */
     public static File getImplicitConfigDirectory(){
@@ -91,14 +100,16 @@ public final class ConfigFile{
 
     /**
      * まだ存在しない設定格納ディレクトリを新規に作成する。
-     * エラーがあればダイアログ提示とともにVM終了する。
+     *
+     * <p>エラーがあればダイアログ提示とともにVM終了する。
+     *
      * @param confPath 設定格納ディレクトリ
      * @param isImplicitPath ディレクトリが暗黙的に指定されたものならtrue。
      * @return 新規に作成した設定格納ディレクトリ
      * @throws IllegalArgumentException すでにそのディレクトリは存在する。
      */
     public static File buildConfigDirectory(File confPath,
-                                               boolean isImplicitPath )
+                                            boolean isImplicitPath )
             throws IllegalArgumentException{
         if(confPath.exists()) throw new IllegalArgumentException();
 
@@ -156,7 +167,9 @@ public final class ConfigFile{
     /**
      * 設定ディレクトリ操作の
      * 共通エラーメッセージ確認ダイアログを表示する。
-     * 閉じるまで待つ。
+     *
+     * <p>閉じるまで待つ。
+     *
      * @param seq メッセージ
      */
     private static void showErrorMessage(CharSequence seq){
@@ -170,7 +183,9 @@ public final class ConfigFile{
     /**
      * 設定ディレクトリ操作の
      * 共通エラーメッセージ確認ダイアログを表示する。
-     * 閉じるまで待つ。
+     *
+     * <p>閉じるまで待つ。
+     *
      * @param seq メッセージ
      */
     private static void showWarnMessage(CharSequence seq){
@@ -184,7 +199,9 @@ public final class ConfigFile{
     /**
      * 設定ディレクトリ操作の
      * 情報提示メッセージ確認ダイアログを表示する。
-     * 閉じるまで待つ。
+     *
+     * <p>閉じるまで待つ。
+     *
      * @param seq メッセージ
      */
     private static void showInfoMessage(CharSequence seq){
@@ -197,6 +214,7 @@ public final class ConfigFile{
 
     /**
      * ダイアログを表示し、閉じられるまで待つ。
+     *
      * @param pane ダイアログの元となるペイン
      */
     private static void showDialog(JOptionPane pane){
@@ -222,6 +240,7 @@ public final class ConfigFile{
     /**
      * 設定ディレクトリのルートファイルシステムもしくはドライブレターに
      * アクセスできないエラーをダイアログに提示し、VM終了する。
+     *
      * @param path 設定ディレクトリ
      * @param preMessage メッセージ前半
      */
@@ -242,6 +261,7 @@ public final class ConfigFile{
     /**
      * 設定ディレクトリの祖先に書き込めないエラーをダイアログで提示し、
      * VM終了する。
+     *
      * @param existsAncestor 存在するもっとも近い祖先
      * @param preMessage メッセージ前半
      */
@@ -262,6 +282,7 @@ public final class ConfigFile{
 
     /**
      * 設定ディレクトリを新規に生成してよいかダイアログで問い合わせる。
+     *
      * @param existsAncestor 存在するもっとも近い祖先
      * @param preMessage メッセージ前半
      * @return 生成してよいと指示があればtrue
@@ -312,6 +333,7 @@ public final class ConfigFile{
     /**
      * 設定ディレクトリが生成できないエラーをダイアログで提示し、
      * VM終了する。
+     *
      * @param path 生成できなかったディレクトリ
      */
     private static void abortCantBuildConfigDir(File path){
@@ -330,6 +352,7 @@ public final class ConfigFile{
     /**
      * 設定ディレクトリへアクセスできないエラーをダイアログで提示し、
      * VM終了する。
+     *
      * @param path アクセスできないディレクトリ
      */
     private static void abortCantAccessConfigDir(File path){
@@ -349,6 +372,7 @@ public final class ConfigFile{
 
     /**
      * ファイルに書き込めないエラーをダイアログで提示し、VM終了する。
+     *
      * @param file 書き込めなかったファイル
      */
     private static void abortCantWrite(File file){
@@ -365,7 +389,9 @@ public final class ConfigFile{
 
     /**
      * 指定されたディレクトリにREADMEファイルを生成する。
-     * 生成できなければダイアログ表示とともにVM終了する。
+     *
+     * <p>生成できなければダイアログ表示とともにVM終了する。
+     *
      * @param path READMEの格納ディレクトリ
      */
     private static void touchReadme(File path){
@@ -413,6 +439,7 @@ public final class ConfigFile{
     /**
      * 設定ディレクトリがアクセス可能でなければ
      * エラーダイアログを出してVM終了する。
+     *
      * @param confDir 設定ディレクトリ
      */
     public static void checkAccessibility(File confDir){
@@ -425,6 +452,7 @@ public final class ConfigFile{
 
     /**
      * センタリングされたファイル名表示のHTML表記を出力する。
+     *
      * @param path ファイル
      * @return HTML表記
      */
@@ -437,10 +465,13 @@ public final class ConfigFile{
 
     /**
      * ロックエラーダイアログの表示。
-     * 呼び出しから戻ってもまだロックオブジェクトが
+     *
+     * <p>呼び出しから戻ってもまだロックオブジェクトが
      * ロックファイルのオーナーでない場合、
      * 今後設定ディレクトリは一切使わずに起動を続行するものとする。
-     * ロックファイルの強制解除に失敗した場合はVM終了する。
+     *
+     * <p>ロックファイルの強制解除に失敗した場合はVM終了する。
+     *
      * @param lock エラーを起こしたロック
      */
     public static void confirmLockError(InterVMLock lock){
index 28b3e9c..d1fe372 100644 (file)
@@ -55,44 +55,32 @@ public class ConfigStore {
 
     private boolean useStoreFile;
     private boolean isImplicitPath;
-    private File configPath;
+    private File configDir;
 
 
     /**
      * コンストラクタ。
-     * @param useStoreFile 設定ディレクトリへの永続化機能を使うならtrue
-     * @param configPath 設定ディレクトリ。
-     *     設定ディレクトリを使わない場合は無視され、nullとして扱われる。
-     */
-    public ConfigStore(boolean useStoreFile, File configPath ){
-        this(useStoreFile, true, configPath);
-        return;
-    }
-
-    /**
-     * コンストラクタ。
-     * @param useStoreFile 設定ディレクトリへの永続化機能を使うならtrue
-     * @param isImplicitPath コマンドラインで指定されたディレクトリならfalse
-     * @param configPath 設定ディレクトリ。
-     *     設定ディレクトリを使わない場合は無視され、nullとして扱われる。
+     *
+     * @param useStoreFile 設定ディレクトリ内への
+     *     セーブデータ機能を使うならtrue
+     * @param isImplicitPath 起動コマンドラインから指定された
+     *     設定ディレクトリの場合false
+     * @param configDirPath 設定ディレクトリ。
+     *     設定ディレクトリを使わない場合は無視される。
      */
     public ConfigStore(boolean useStoreFile,
-                         boolean isImplicitPath,
-                         File configPath ){
+                       boolean isImplicitPath,
+                       File configDirPath ){
         super();
 
         this.useStoreFile = useStoreFile;
 
         if(this.useStoreFile){
             this.isImplicitPath = isImplicitPath;
+            this.configDir = configDirPath;
         }else{
             this.isImplicitPath = true;
-        }
-
-        if(this.useStoreFile){
-            this.configPath = configPath;
-        }else{
-            this.configPath = null;
+            this.configDir = null;
         }
 
         return;
@@ -101,6 +89,7 @@ public class ConfigStore {
 
     /**
      * 設定ディレクトリを使うか否か判定する。
+     *
      * @return 設定ディレクトリを使うならtrue。
      */
     public boolean useStoreFile(){
@@ -109,13 +98,11 @@ public class ConfigStore {
 
     /**
      * 設定ディレクトリを返す。
+     *
      * @return 設定ディレクトリ。設定ディレクトリを使わない場合はnull
      */
-    public File getConfigPath(){
-        File result;
-        if(this.useStoreFile) result = this.configPath;
-        else                  result = null;
-        return result;
+    public File getConfigDir(){
+        return this.configDir;
     }
 
     /**
@@ -126,13 +113,13 @@ public class ConfigStore {
     public void prepareConfigDir(){
         if( ! this.useStoreFile ) return;
 
-        if( ! this.configPath.exists() ){
+        if( ! this.configDir.exists() ){
             File created =
-                ConfigFile.buildConfigDirectory(this.configPath,
+                ConfigFile.buildConfigDirectory(this.configDir,
                                                 this.isImplicitPath );
             ConfigFile.checkAccessibility(created);
         }else{
-            ConfigFile.checkAccessibility(this.configPath);
+            ConfigFile.checkAccessibility(this.configDir);
         }
 
         return;
@@ -140,11 +127,14 @@ public class ConfigStore {
 
     /**
      * ロックファイルの取得を試みる。
+     *
+     * <p>ロックに失敗したが処理を続行する場合、
+     * 設定ディレクトリは使わないものとして続行する。
      */
     public void tryLock(){
         if( ! this.useStoreFile ) return;
 
-        File lockFile = new File(this.configPath, LOCKFILE);
+        File lockFile = new File(this.configDir, LOCKFILE);
         InterVMLock lock = new InterVMLock(lockFile);
 
         lock.tryLock();
@@ -153,7 +143,8 @@ public class ConfigStore {
             ConfigFile.confirmLockError(lock);
             if( ! lock.isFileOwner() ){
                 this.useStoreFile = false;
-                this.configPath = null;
+                this.isImplicitPath = true;
+                this.configDir = null;
             }
         }
 
@@ -162,6 +153,7 @@ public class ConfigStore {
 
     /**
      * 設定ディレクトリ上のOBJECT型JSONファイルを読み込む。
+     *
      * @param file JSONファイルの相対パス。
      * @return JSON object。
      *     設定ディレクトリを使わない設定、
@@ -178,6 +170,7 @@ public class ConfigStore {
 
     /**
      * 設定ディレクトリ上のJSONファイルを読み込む。
+     *
      * @param file JSONファイルの相対パス
      * @return JSON objectまたはarray。
      *     設定ディレクトリを使わない設定、
@@ -191,8 +184,8 @@ public class ConfigStore {
         if(file.isAbsolute()){
             absFile = file;
         }else{
-            if(this.configPath == null) return null;
-            absFile = new File(this.configPath, file.getPath());
+            if(this.configDir == null) return null;
+            absFile = new File(this.configDir, file.getPath());
             if( ! absFile.exists() ) return null;
             if( ! absFile.isAbsolute() ) return null;
         }
@@ -257,6 +250,7 @@ public class ConfigStore {
 
     /**
      * 文字ストリーム上のJSONデータを読み込む。
+     *
      * @param reader 文字ストリーム
      * @return JSON objectまたはarray。
      * @throws IOException 入力エラー
@@ -270,6 +264,7 @@ public class ConfigStore {
 
     /**
      * 設定ディレクトリ上のJSONファイルに書き込む。
+     *
      * @param file JSONファイルの相対パス
      * @param root JSON objectまたはarray
      * @return 正しくセーブが行われればtrue。
@@ -279,7 +274,7 @@ public class ConfigStore {
         if( ! this.useStoreFile ) return false;
 
         // TODO テンポラリファイルを用いたより安全なファイル更新
-        File absFile = new File(this.configPath, file.getPath());
+        File absFile = new File(this.configDir, file.getPath());
         String absPath = absFile.getPath();
 
         absFile.delete();
@@ -351,6 +346,7 @@ public class ConfigStore {
 
     /**
      * 文字ストリームにJSONデータを書き込む。
+     *
      * @param writer 文字ストリーム出力
      * @param root JSON objectまたはarray
      * @throws IOException 出力エラー
@@ -364,6 +360,7 @@ public class ConfigStore {
 
     /**
      * 検索履歴ファイルを読み込む。
+     *
      * @return 履歴データ。履歴を読まないもしくは読めない場合はnull
      */
     public JsObject loadHistoryConfig(){
@@ -373,6 +370,7 @@ public class ConfigStore {
 
     /**
      * 原稿ファイルを読み込む。
+     *
      * @return 原稿データ。原稿を読まないもしくは読めない場合はnull
      */
     public JsObject loadDraftConfig(){
@@ -382,6 +380,7 @@ public class ConfigStore {
 
     /**
      * ネットワーク設定ファイルを読み込む。
+     *
      * @return ネットワーク設定データ。
      *     設定を読まないもしくは読めない場合はnull
      */
@@ -392,6 +391,7 @@ public class ConfigStore {
 
     /**
      * 台詞表示設定ファイルを読み込む。
+     *
      * @return 台詞表示設定データ。
      *     設定を読まないもしくは読めない場合はnull
      */
@@ -402,6 +402,7 @@ public class ConfigStore {
 
     /**
      * 検索履歴ファイルに書き込む。
+     *
      * @param root 履歴データ
      * @return 書き込まなかったもしくは書き込めなかった場合はfalse
      */
@@ -412,6 +413,7 @@ public class ConfigStore {
 
     /**
      * 原稿ファイルに書き込む。
+     *
      * @param root 原稿データ
      * @return 書き込まなかったもしくは書き込めなかった場合はfalse
      */
@@ -422,6 +424,7 @@ public class ConfigStore {
 
     /**
      * ネットワーク設定ファイルに書き込む。
+     *
      * @param root ネットワーク設定
      * @return 書き込まなかったもしくは書き込めなかった場合はfalse
      */
@@ -432,6 +435,7 @@ public class ConfigStore {
 
     /**
      * 台詞表示設定ファイルに書き込む。
+     *
      * @param root 台詞表示設定
      * @return 書き込まなかったもしくは書き込めなかった場合はfalse
      */
index 9162f5a..2100db2 100644 (file)
@@ -172,7 +172,7 @@ public class HelpFrame extends JFrame
 
         if(configStore.useStoreFile()){
             info.append("設定格納ディレクトリ : ")
-                .append(configStore.getConfigPath().getPath());
+                .append(configStore.getConfigDir().getPath());
         }else{
             info.append("※ 設定格納ディレクトリは使っていません。");
         }