Changeset 12856 in josm for trunk/src/org
- Timestamp:
- 2017-09-14T15:09:01+02:00 (7 years ago)
- Location:
- trunk/src/org/openstreetmap/josm
- Files:
-
- 16 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/actions/ShowStatusReportAction.java
r12855 r12856 231 231 final String propJavaHome = System.getProperty("java.home"); 232 232 final String propJavaHomeAlt = "<java.home>"; 233 final String prefDir = Config.getDirs().getPreferencesDirectory( ).toString();233 final String prefDir = Config.getDirs().getPreferencesDirectory(false).toString(); 234 234 final String prefDirAlt = "<josm.pref>"; 235 final String userDataDir = Config.getDirs().getUserDataDirectory( ).toString();235 final String userDataDir = Config.getDirs().getUserDataDirectory(false).toString(); 236 236 final String userDataDirAlt = "<josm.userdata>"; 237 final String userCacheDir = Config.getDirs().getCacheDirectory( ).toString();237 final String userCacheDir = Config.getDirs().getCacheDirectory(false).toString(); 238 238 final String userCacheDirAlt = "<josm.cache>"; 239 239 final String userHomeDir = System.getProperty("user.home"); -
trunk/src/org/openstreetmap/josm/data/Preferences.java
r12855 r12856 331 331 * @return The user defined preferences directory, containing the preferences.xml file 332 332 * @since 7834 333 */ 333 * @deprecated use {@link #getPreferencesDirectory(boolean)} 334 */ 335 @Deprecated 336 public File getPreferencesDirectory() { 337 return getPreferencesDirectory(false); 338 } 339 334 340 @Override 335 public File getPreferencesDirectory( ) {341 public File getPreferencesDirectory(boolean createIfMissing) { 336 342 if (preferencesDir != null) 337 343 return preferencesDir; … … 348 354 } 349 355 } 356 if (createIfMissing && !preferencesDir.exists() && !preferencesDir.mkdirs()) { 357 Logging.warn(tr("Failed to create missing preferences directory: {0}", preferencesDir.getAbsoluteFile())); 358 JOptionPane.showMessageDialog( 359 Main.parent, 360 tr("<html>Failed to create missing preferences directory: {0}</html>", preferencesDir.getAbsoluteFile()), 361 tr("Error"), 362 JOptionPane.ERROR_MESSAGE 363 ); 364 } 350 365 return preferencesDir; 351 366 } … … 356 371 * @return The user data directory, containing autosave, plugins, etc. 357 372 * @since 7834 358 */ 373 * @deprecated use {@link #getUserDataDirectory(boolean)} 374 */ 375 @Deprecated 376 public File getUserDataDirectory() { 377 return getUserDataDirectory(false); 378 } 379 359 380 @Override 360 public File getUserDataDirectory( ) {381 public File getUserDataDirectory(boolean createIfMissing) { 361 382 if (userdataDir != null) 362 383 return userdataDir; … … 373 394 } 374 395 } 396 if (createIfMissing && !userdataDir.exists() && !userdataDir.mkdirs()) { 397 Logging.warn(tr("Failed to create missing user data directory: {0}", userdataDir.getAbsoluteFile())); 398 JOptionPane.showMessageDialog( 399 Main.parent, 400 tr("<html>Failed to create missing user data directory: {0}</html>", userdataDir.getAbsoluteFile()), 401 tr("Error"), 402 JOptionPane.ERROR_MESSAGE 403 ); 404 } 375 405 return userdataDir; 376 406 } … … 381 411 */ 382 412 public File getPreferenceFile() { 383 return new File(getPreferencesDirectory( ), "preferences.xml");413 return new File(getPreferencesDirectory(false), "preferences.xml"); 384 414 } 385 415 … … 389 419 */ 390 420 public File getDefaultsCacheFile() { 391 return new File(getCacheDirectory( ), "default_preferences.xml");421 return new File(getCacheDirectory(true), "default_preferences.xml"); 392 422 } 393 423 … … 397 427 */ 398 428 public File getPluginsDirectory() { 399 return new File(getUserDataDirectory( ), "plugins");429 return new File(getUserDataDirectory(false), "plugins"); 400 430 } 401 431 … … 406 436 * 407 437 * @return the cache directory 408 */ 438 * @deprecated use {@link #getCacheDirectory(boolean)} 439 */ 440 @Deprecated 441 public File getCacheDirectory() { 442 return getCacheDirectory(true); 443 } 444 409 445 @Override 410 public File getCacheDirectory( ) {446 public File getCacheDirectory(boolean createIfMissing) { 411 447 if (cacheDir != null) 412 448 return cacheDir; … … 427 463 } 428 464 } 429 if ( !cacheDir.exists() && !cacheDir.mkdirs()) {465 if (createIfMissing && !cacheDir.exists() && !cacheDir.mkdirs()) { 430 466 Logging.warn(tr("Failed to create missing cache directory: {0}", cacheDir.getAbsoluteFile())); 431 467 JOptionPane.showMessageDialog( … … 454 490 public Collection<String> getAllPossiblePreferenceDirs() { 455 491 Set<String> locations = new HashSet<>(); 456 addPossibleResourceDir(locations, getPreferencesDirectory( ).getPath());457 addPossibleResourceDir(locations, getUserDataDirectory( ).getPath());492 addPossibleResourceDir(locations, getPreferencesDirectory(false).getPath()); 493 addPossibleResourceDir(locations, getUserDataDirectory(false).getPath()); 458 494 addPossibleResourceDir(locations, System.getenv("JOSM_RESOURCES")); 459 495 addPossibleResourceDir(locations, System.getProperty("josm.resources")); … … 718 754 initSuccessful = false; 719 755 // get the preferences. 720 File prefDir = getPreferencesDirectory( );756 File prefDir = getPreferencesDirectory(false); 721 757 if (prefDir.exists()) { 722 758 if (!prefDir.isDirectory()) { -
trunk/src/org/openstreetmap/josm/data/cache/JCSCacheManager.java
r12855 r12856 101 101 @SuppressWarnings("resource") 102 102 private static void initialize() throws IOException { 103 File cacheDir = new File(Config.getDirs().getCacheDirectory( ), "jcs");103 File cacheDir = new File(Config.getDirs().getCacheDirectory(true), "jcs"); 104 104 105 105 if (!cacheDir.exists() && !cacheDir.mkdirs()) -
trunk/src/org/openstreetmap/josm/data/imagery/CachedTileLoaderFactory.java
r12855 r12856 56 56 String defPath = null; 57 57 try { 58 defPath = new File(Config.getDirs().getCacheDirectory( ), "tiles").getAbsolutePath();58 defPath = new File(Config.getDirs().getCacheDirectory(true), "tiles").getAbsolutePath(); 59 59 } catch (SecurityException e) { 60 60 Logging.warn(e); -
trunk/src/org/openstreetmap/josm/data/validation/OsmValidator.java
r12855 r12856 176 176 */ 177 177 public static String getValidatorDir() { 178 return new File(Config.getDirs().getUserDataDirectory( ), "validator").getAbsolutePath();178 return new File(Config.getDirs().getUserDataDirectory(true), "validator").getAbsolutePath(); 179 179 } 180 180 -
trunk/src/org/openstreetmap/josm/gui/io/CustomConfigurator.java
r12855 r12856 425 425 String dir; 426 426 if ("prefs".equals(base) || base.isEmpty()) { 427 dir = Config.getDirs().getPreferencesDirectory( ).getAbsolutePath();427 dir = Config.getDirs().getPreferencesDirectory(false).getAbsolutePath(); 428 428 } else if ("cache".equals(base)) { 429 dir = Config.getDirs().getCacheDirectory( ).getAbsolutePath();429 dir = Config.getDirs().getCacheDirectory(false).getAbsolutePath(); 430 430 } else if ("plugins".equals(base)) { 431 431 dir = Main.pref.getPluginsDirectory().getAbsolutePath(); … … 477 477 engine.eval("API={}; API.pref={}; API.fragments={};"); 478 478 479 engine.eval("homeDir='"+normalizeDirName(Config.getDirs().getPreferencesDirectory( ).getAbsolutePath()) +"';");479 engine.eval("homeDir='"+normalizeDirName(Config.getDirs().getPreferencesDirectory(false).getAbsolutePath()) +"';"); 480 480 engine.eval("josmVersion="+Version.getInstance().getVersion()+';'); 481 481 String className = CustomConfigurator.class.getName(); -
trunk/src/org/openstreetmap/josm/gui/layer/AutosaveTask.java
r12855 r12856 116 116 private final Deque<File> deletedLayers = new LinkedList<>(); 117 117 118 private final File autosaveDir = new File(Config.getDirs().getUserDataDirectory( ), AUTOSAVE_DIR);119 private final File deletedLayersDir = new File(Config.getDirs().getUserDataDirectory( ), DELETED_LAYERS_DIR);118 private final File autosaveDir = new File(Config.getDirs().getUserDataDirectory(true), AUTOSAVE_DIR); 119 private final File deletedLayersDir = new File(Config.getDirs().getUserDataDirectory(true), DELETED_LAYERS_DIR); 120 120 121 121 /** -
trunk/src/org/openstreetmap/josm/gui/layer/geoimage/ThumbsLoader.java
r12855 r12856 69 69 try { 70 70 cache = JCSCacheManager.getCache("geoimage-thumbnails", 0, 120, 71 Config.getDirs().getCacheDirectory( ).getPath() + File.separator + "geoimage-thumbnails");71 Config.getDirs().getCacheDirectory(true).getPath() + File.separator + "geoimage-thumbnails"); 72 72 } catch (IOException e) { 73 73 Logging.warn("Failed to initialize cache for geoimage-thumbnails"); -
trunk/src/org/openstreetmap/josm/gui/preferences/advanced/AdvancedPreference.java
r12855 r12856 370 370 } 371 371 } 372 files = Config.getDirs().getPreferencesDirectory( ).listFiles();372 files = Config.getDirs().getPreferencesDirectory(false).listFiles(); 373 373 if (files != null) { 374 374 for (File f: files) { -
trunk/src/org/openstreetmap/josm/io/CacheCustomContent.java
r12855 r12856 76 76 this.ident = ident; 77 77 this.updateInterval = updateInterval; 78 this.path = new File(Config.getDirs().getCacheDirectory( ), ident);78 this.path = new File(Config.getDirs().getCacheDirectory(true), ident); 79 79 } 80 80 -
trunk/src/org/openstreetmap/josm/io/CachedFile.java
r12855 r12856 277 277 return null; 278 278 } else if (name.startsWith("josmdir://")) { 279 cacheFile = new File(Config.getDirs().getUserDataDirectory( ), name.substring("josmdir://".length()));279 cacheFile = new File(Config.getDirs().getUserDataDirectory(false), name.substring("josmdir://".length())); 280 280 } else if (name.startsWith("josmplugindir://")) { 281 281 cacheFile = new File(Main.pref.getPluginsDirectory(), name.substring("josmplugindir://".length())); … … 448 448 } 449 449 if (destDir == null) { 450 destDir = Config.getDirs().getCacheDirectory( ).getPath();450 destDir = Config.getDirs().getCacheDirectory(true).getPath(); 451 451 } 452 452 -
trunk/src/org/openstreetmap/josm/io/remotecontrol/RemoteControl.java
r12855 r12856 95 95 */ 96 96 public static String getRemoteControlDir() { 97 return new File(Config.getDirs().getUserDataDirectory( ), "remotecontrol").getAbsolutePath();97 return new File(Config.getDirs().getUserDataDirectory(true), "remotecontrol").getAbsolutePath(); 98 98 } 99 99 -
trunk/src/org/openstreetmap/josm/spi/preferences/IBaseDirectories.java
r12855 r12856 15 15 * Get the directory where user-specific configuration and preferences 16 16 * should be stored. 17 * @param createIfMissing if true, automatically creates this directory, 18 * in case it is missing 17 19 * @return the preferences directory 20 * @since 12856 18 21 */ 19 File getPreferencesDirectory( );22 File getPreferencesDirectory(boolean createIfMissing); 20 23 21 24 /** 22 25 * Get the directory where user-specific data files should be stored. 26 * @param createIfMissing if true, automatically creates this directory, 27 * in case it is missing 23 28 * @return the user data directory 29 * @since 12856 24 30 */ 25 File getUserDataDirectory( );31 File getUserDataDirectory(boolean createIfMissing); 26 32 27 33 /** 28 34 * Get the directory where user-specific cached content (non-essential data) 29 35 * should be stored. 36 * @param createIfMissing if true, automatically creates this directory, 37 * in case it is missing 30 38 * @return the cache directory 39 * @since 12856 31 40 */ 32 File getCacheDirectory( );41 File getCacheDirectory(boolean createIfMissing); 33 42 } -
trunk/src/org/openstreetmap/josm/tools/ImageProvider.java
r12855 r12856 928 928 private static ImageResource getIfAvailableHttp(String url, ImageType type) { 929 929 try (CachedFile cf = new CachedFile(url).setDestDir( 930 new File(Config.getDirs().getCacheDirectory( ), "images").getPath());930 new File(Config.getDirs().getCacheDirectory(true), "images").getPath()); 931 931 InputStream is = cf.getInputStream()) { 932 932 switch (type) { … … 1174 1174 // Try user-data directory 1175 1175 if (Config.getDirs() != null) { 1176 String dir = new File(Config.getDirs().getUserDataDirectory( ), "images").getAbsolutePath();1176 String dir = new File(Config.getDirs().getUserDataDirectory(false), "images").getAbsolutePath(); 1177 1177 try { 1178 1178 u = getImageUrl(dir, imageName, additionalClassLoaders); … … 1248 1248 1249 1249 try (CachedFile cf = new CachedFile(base + fn).setDestDir( 1250 new File(Config.getDirs().getUserDataDirectory( ), "images").getPath());1250 new File(Config.getDirs().getUserDataDirectory(true), "images").getPath()); 1251 1251 InputStream is = cf.getInputStream()) { 1252 1252 parser.parse(new InputSource(is)); -
trunk/src/org/openstreetmap/josm/tools/PlatformHookWindows.java
r12855 r12856 477 477 public File getDefaultUserDataDirectory() { 478 478 // Use preferences directory by default 479 return Config.getDirs().getPreferencesDirectory( );479 return Config.getDirs().getPreferencesDirectory(false); 480 480 } 481 481 … … 522 522 props.load(fis); 523 523 byte[] content = Files.readAllBytes(templateFile); 524 File cachePath = Config.getDirs().getCacheDirectory( );524 File cachePath = Config.getDirs().getCacheDirectory(true); 525 525 Path fontconfigFile = cachePath.toPath().resolve("fontconfig.properties"); 526 526 OutputStream os = Files.newOutputStream(fontconfigFile); -
trunk/src/org/openstreetmap/josm/tools/RightAndLefthandTraffic.java
r12855 r12856 153 153 private static void saveOptimizedBoundaries(Collection<Way> optimizedWays) { 154 154 DataSet ds = optimizedWays.iterator().next().getDataSet(); 155 File file = new File(Config.getDirs().getCacheDirectory( ), "left-right-hand-traffic.osm");155 File file = new File(Config.getDirs().getCacheDirectory(true), "left-right-hand-traffic.osm"); 156 156 try (Writer writer = new OutputStreamWriter(new FileOutputStream(file), StandardCharsets.UTF_8); 157 157 OsmWriter w = OsmWriterFactory.createOsmWriter(new PrintWriter(writer), false, ds.getVersion()) … … 166 166 167 167 private static Collection<Way> loadOptimizedBoundaries() { 168 try (InputStream is = new FileInputStream(new File(Config.getDirs().getCacheDirectory(), "left-right-hand-traffic.osm"))) { 168 try (InputStream is = new FileInputStream(new File( 169 Config.getDirs().getCacheDirectory(false), "left-right-hand-traffic.osm"))) { 169 170 return OsmReader.parseDataSet(is, null).getWays(); 170 171 } catch (IllegalDataException | IOException ex) {
Note:
See TracChangeset
for help on using the changeset viewer.