Changeset 13007 in josm for trunk/src/org/openstreetmap
- Timestamp:
- 2017-10-16T21:45:44+02:00 (7 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/plugins/Plugin.java
r12627 r13007 1 1 // License: GPL. For details, see LICENSE file. 2 2 package org.openstreetmap.josm.plugins; 3 4 import static org.openstreetmap.josm.tools.I18n.tr; 3 5 4 6 import java.io.File; … … 19 21 import org.openstreetmap.josm.gui.download.DownloadSelection; 20 22 import org.openstreetmap.josm.gui.preferences.PreferenceSetting; 23 import org.openstreetmap.josm.spi.preferences.Config; 24 import org.openstreetmap.josm.spi.preferences.IBaseDirectories; 25 import org.openstreetmap.josm.tools.Logging; 21 26 import org.openstreetmap.josm.tools.Utils; 22 27 … … 53 58 private PluginInformation info; 54 59 60 private final IBaseDirectories pluginBaseDirectories = new PluginBaseDirectories(); 61 62 private class PluginBaseDirectories implements IBaseDirectories { 63 private File preferencesDir; 64 private File cacheDir; 65 private File userdataDir; 66 67 @Override 68 public File getPreferencesDirectory(boolean createIfMissing) { 69 if (preferencesDir == null) { 70 preferencesDir = Config.getDirs().getPreferencesDirectory(createIfMissing).toPath() 71 .resolve("plugins").resolve(info.name).toFile(); 72 } 73 if (createIfMissing && !preferencesDir.exists() && !preferencesDir.mkdirs()) { 74 Logging.error(tr("Failed to create missing plugin preferences directory: {0}", preferencesDir.getAbsoluteFile())); 75 } 76 return preferencesDir; 77 } 78 79 @Override 80 public File getUserDataDirectory(boolean createIfMissing) { 81 if (userdataDir == null) { 82 userdataDir = Config.getDirs().getUserDataDirectory(createIfMissing).toPath() 83 .resolve("plugins").resolve(info.name).toFile(); 84 } 85 if (createIfMissing && !userdataDir.exists() && !userdataDir.mkdirs()) { 86 Logging.error(tr("Failed to create missing plugin user data directory: {0}", userdataDir.getAbsoluteFile())); 87 } 88 return userdataDir; 89 } 90 91 @Override 92 public File getCacheDirectory(boolean createIfMissing) { 93 if (cacheDir == null) { 94 cacheDir = Config.getDirs().getCacheDirectory(createIfMissing).toPath() 95 .resolve("plugins").resolve(info.name).toFile(); 96 } 97 if (createIfMissing && !cacheDir.exists() && !cacheDir.mkdirs()) { 98 Logging.error(tr("Failed to create missing plugin cache directory: {0}", cacheDir.getAbsoluteFile())); 99 } 100 return cacheDir; 101 } 102 } 103 55 104 /** 56 105 * Creates the plugin … … 81 130 82 131 /** 132 * Get the directories where this plugin can store various files. 133 * @return the directories where this plugin can store files 134 * @since 13007 135 */ 136 public IBaseDirectories getPluginDirs() { 137 return pluginBaseDirectories; 138 } 139 140 /** 83 141 * @return The directory for the plugin to store all kind of stuff. 84 */ 142 * @deprecated (since 13007) to get the same directory as this method, use {@code getPluginDirectories().getUserDataDirectory(false)}. 143 * However, for files that can be characterized as cache or preferences, you are encouraged to use the appropriate 144 * {@link IBaseDirectories} method from {@link #getPluginDirectories()}. 145 */ 146 @Deprecated 85 147 public String getPluginDir() { 86 148 return new File(Main.pref.getPluginsDirectory(), info.name).getPath();
Note:
See TracChangeset
for help on using the changeset viewer.