OmegaT の背景に画像を表示します。
設定ファイル取得系のメソッドを、優先パスと代替パスに分割し、既定の画像検索場所を両方に対応
| @@ -41,6 +41,8 @@ | ||
| 41 | 41 | */ |
| 42 | 42 | public class MoeConfig { |
| 43 | 43 | |
| 44 | + static final String FILE_NAME = "config.groovy"; | |
| 45 | + | |
| 44 | 46 | public enum ProviderType { |
| 45 | 47 | Color, SimpleImage |
| 46 | 48 | } |
| @@ -129,11 +131,17 @@ | ||
| 129 | 131 | } |
| 130 | 132 | |
| 131 | 133 | public static ConfigObject getDefaultConfig() { |
| 132 | - // search image files from MoeConfigDir | |
| 133 | - File parentDir = MoeUtil.getMoeConfigDir(); | |
| 134 | + // search image files from PrimaryMoeConfigDir | |
| 135 | + File parentDir = MoeUtil.getPrimaryMoeConfigDir(); | |
| 134 | 136 | String image = getFirstImagePath(parentDir); |
| 135 | 137 | |
| 136 | - // If image file not found, search image files from PluginJarDir | |
| 138 | + // If image file not found, search image files from SecondaryMoeConfigDir | |
| 139 | + if (image.isEmpty()) { | |
| 140 | + parentDir = MoeUtil.getSecondaryMoeConfigDir(); | |
| 141 | + image = getFirstImagePath(parentDir); | |
| 142 | + } | |
| 143 | + | |
| 144 | + // If image file still not found, search image files from PluginJarDir | |
| 137 | 145 | // for backward compatibility. |
| 138 | 146 | if (image.isEmpty()) { |
| 139 | 147 | try { |
| @@ -143,7 +151,7 @@ | ||
| 143 | 151 | Log.log(ex.getMessage()); |
| 144 | 152 | } |
| 145 | 153 | } |
| 146 | - | |
| 154 | + | |
| 147 | 155 | ConfigObject conf = new ConfigObject(); |
| 148 | 156 | conf.put("index", -1); |
| 149 | 157 | conf.put("enabled", !image.isEmpty()); |
| @@ -42,6 +42,7 @@ | ||
| 42 | 42 | private static final Pattern RE_HAS_URL_SHORTCUT_EXTENSION = Pattern.compile(".+\\.(?:bmp|png|jpg|jpeg|gif)\\z", Pattern.CASE_INSENSITIVE); |
| 43 | 43 | private static final Pattern RE_URL_IN_SHORTCUT = Pattern.compile("\\[InternetShortcut\\]\\s+URL=(.+)\\b"); |
| 44 | 44 | private static final Pattern RE_URL_IN_WEBLOC = Pattern.compile("<key>URL</key>\\s+<string>(.+)</string>"); |
| 45 | + private static final String SAFE_PLUGIN_NAME = "moenizer"; | |
| 45 | 46 | private static File pluginJarFile; |
| 46 | 47 | |
| 47 | 48 | static { |
| @@ -124,12 +125,38 @@ | ||
| 124 | 125 | && RE_HAS_IMAGE_EXTENSION.matcher(name).matches()); |
| 125 | 126 | } |
| 126 | 127 | |
| 127 | - public static File getMoeConfigDir() { | |
| 128 | - return new File(StaticUtils.getConfigDir(), "moenizer"); | |
| 128 | + public static File getPrimaryMoeConfigDir() { | |
| 129 | + return new File(StaticUtils.getConfigDir(), SAFE_PLUGIN_NAME); | |
| 129 | 130 | } |
| 130 | 131 | |
| 132 | + public static File getPrimaryMoeConfigFile() { | |
| 133 | + return new File(getPrimaryMoeConfigDir(), MoeConfig.FILE_NAME); | |
| 134 | + } | |
| 135 | + | |
| 136 | + public static File getSecondaryMoeConfigDir() { | |
| 137 | + return new File(StaticUtils.getConfigDir(), | |
| 138 | + "plugins" + File.separator + SAFE_PLUGIN_NAME); | |
| 139 | + } | |
| 140 | + | |
| 141 | + public static File getSecondaryMoeConfigFile() { | |
| 142 | + return new File(getSecondaryMoeConfigDir(), MoeConfig.FILE_NAME); | |
| 143 | + } | |
| 144 | + | |
| 145 | + /** | |
| 146 | + * 設定ファイルを取得する | |
| 147 | + * @return 候補パスのいずれかにファイルが実在すればそれを、どれも実在 | |
| 148 | + * しなければ優先パスを返す | |
| 149 | + */ | |
| 131 | 150 | public static File getMoeConfigFile() { |
| 132 | - return new File(getMoeConfigDir(), "config.groovy"); | |
| 151 | + File primaryMoeConfigFile = getPrimaryMoeConfigFile(); | |
| 152 | + if (primaryMoeConfigFile.isFile()) { | |
| 153 | + return primaryMoeConfigFile; | |
| 154 | + } | |
| 155 | + File secondaryMoeConfigFile = getSecondaryMoeConfigFile(); | |
| 156 | + if (secondaryMoeConfigFile.isFile()) { | |
| 157 | + return secondaryMoeConfigFile; | |
| 158 | + } | |
| 159 | + return primaryMoeConfigFile; | |
| 133 | 160 | } |
| 134 | 161 | |
| 135 | 162 | } |