Changeset 7834 in josm for trunk/src/org/openstreetmap/josm/data
- Timestamp:
- 2014-12-19T15:05:33+01:00 (9 years ago)
- Location:
- trunk/src/org/openstreetmap/josm/data
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/data/AutosaveTask.java
r7580 r7834 85 85 private final Deque<File> deletedLayers = new LinkedList<>(); 86 86 87 private final File autosaveDir = new File(Main.pref.get PreferencesDir() +AUTOSAVE_DIR);88 private final File deletedLayersDir = new File(Main.pref.get PreferencesDir() +DELETED_LAYERS_DIR);87 private final File autosaveDir = new File(Main.pref.getUserDataDirectory(), AUTOSAVE_DIR); 88 private final File deletedLayersDir = new File(Main.pref.getUserDataDirectory(), DELETED_LAYERS_DIR); 89 89 90 90 public void schedule() { -
trunk/src/org/openstreetmap/josm/data/CustomConfigurator.java
r7082 r7834 157 157 */ 158 158 public static void messageBox(String type, String text) { 159 if (type==null || type. length()==0) type="plain";159 if (type==null || type.isEmpty()) type="plain"; 160 160 161 161 switch (type.charAt(0)) { … … 390 390 391 391 private static String getDirectoryByAbbr(String base) { 392 393 if ("prefs".equals(base) || base.length()==0) {394 dir = Main.pref.getPreferencesDir();395 396 397 398 399 400 401 402 392 String dir; 393 if ("prefs".equals(base) || base.isEmpty()) { 394 dir = Main.pref.getPreferencesDirectory().getAbsolutePath(); 395 } else if ("cache".equals(base)) { 396 dir = Main.pref.getCacheDirectory().getAbsolutePath(); 397 } else if ("plugins".equals(base)) { 398 dir = Main.pref.getPluginsDirectory().getAbsolutePath(); 399 } else { 400 dir = null; 401 } 402 return dir; 403 403 } 404 404 … … 459 459 engine.eval("API={}; API.pref={}; API.fragments={};"); 460 460 461 engine.eval("homeDir='"+normalizeDirName(Main.pref.getPreferencesDir ()) +"';");461 engine.eval("homeDir='"+normalizeDirName(Main.pref.getPreferencesDirectory().getAbsolutePath()) +"';"); 462 462 engine.eval("josmVersion="+Version.getInstance().getVersion()+";"); 463 463 String className = CustomConfigurator.class.getName(); … … 629 629 if (locText.length()>0) text=locText; 630 630 String var = elem.getAttribute("var"); 631 if (var. length()==0) var="result";631 if (var.isEmpty()) var="result"; 632 632 633 633 String input = evalVars(elem.getAttribute("input")); -
trunk/src/org/openstreetmap/josm/data/Preferences.java
r7831 r7834 22 22 import java.util.Collection; 23 23 import java.util.Collections; 24 import java.util.HashSet; 24 25 import java.util.Iterator; 25 26 import java.util.LinkedHashMap; … … 30 31 import java.util.Objects; 31 32 import java.util.ResourceBundle; 33 import java.util.Set; 32 34 import java.util.SortedMap; 33 35 import java.util.TreeMap; … … 84 86 * Internal storage for the preference directory. 85 87 * Do not access this variable directly! 86 * @see #getPreferencesDir File()87 */ 88 private File preferencesDir File= null;88 * @see #getPreferencesDirectory() 89 */ 90 private File preferencesDir = null; 89 91 90 92 /** 91 93 * Internal storage for the cache directory. 92 94 */ 93 private File cacheDir File= null;95 private File cacheDir = null; 94 96 95 97 /** … … 530 532 * Returns the location of the user defined preferences directory 531 533 * @return The location of the user defined preferences directory 532 */ 534 * @deprecated use #getPreferencesDirectory() to access preferences directory 535 * or #getUserDataDirectory to access user data directory 536 */ 537 @Deprecated 533 538 public String getPreferencesDir() { 534 final String path = getPreferencesDir File().getPath();539 final String path = getPreferencesDirectory().getPath(); 535 540 if (path.endsWith(File.separator)) 536 541 return path; … … 539 544 540 545 /** 541 * Returns the user defined preferences directory 542 * @return The user defined preferences directory 543 */ 544 public File getPreferencesDirFile() { 545 if (preferencesDirFile != null) 546 return preferencesDirFile; 546 * Returns the user defined preferences directory, containing the preferences.xml file 547 * @return The user defined preferences directory, containing the preferences.xml file 548 * @since 7834 549 */ 550 public File getPreferencesDirectory() { 551 if (preferencesDir != null) 552 return preferencesDir; 547 553 String path; 548 554 path = System.getProperty("josm.home"); 549 555 if (path != null) { 550 preferencesDir File= new File(path).getAbsoluteFile();556 preferencesDir = new File(path).getAbsoluteFile(); 551 557 } else { 552 preferencesDirFile = Main.platform.getDefaultPrefDirectory(); 553 } 554 return preferencesDirFile; 555 } 556 557 /** 558 * Returns the user preferences file 559 * @return The user preferences file 558 preferencesDir = Main.platform.getDefaultPrefDirectory(); 559 } 560 return preferencesDir; 561 } 562 563 /** 564 * Returns the user data directory, containing autosave, plugins, etc. 565 * Depending on the OS it may be the same directory as preferences directory. 566 * @return The user data directory, containing autosave, plugins, etc. 567 * @since 7834 568 */ 569 public File getUserDataDirectory() { 570 return Main.platform.getDefaultUserDataDirectory(); 571 } 572 573 /** 574 * Returns the user preferences file (preferences.xml) 575 * @return The user preferences file (preferences.xml) 560 576 */ 561 577 public File getPreferenceFile() { 562 return new File(getPreferencesDir File(), "preferences.xml");578 return new File(getPreferencesDirectory(), "preferences.xml"); 563 579 } 564 580 … … 568 584 */ 569 585 public File getPluginsDirectory() { 570 return new File(get PreferencesDirFile(), "plugins");586 return new File(getUserDataDirectory(), "plugins"); 571 587 } 572 588 … … 580 596 */ 581 597 public File getCacheDirectory() { 582 if (cacheDir File!= null)583 return cacheDir File;598 if (cacheDir != null) 599 return cacheDir; 584 600 String path = System.getProperty("josm.cache"); 585 601 if (path != null) { 586 cacheDir File= new File(path).getAbsoluteFile();602 cacheDir = new File(path).getAbsoluteFile(); 587 603 } else { 588 604 path = get("cache.folder", null); 589 605 if (path != null) { 590 cacheDir File= new File(path);606 cacheDir = new File(path); 591 607 } else { 592 cacheDir File= Main.platform.getDefaultCacheDirectory();593 } 594 } 595 if (!cacheDir File.exists() && !cacheDirFile.mkdirs()) {596 Main.warn(tr("Failed to create missing cache directory: {0}", cacheDir File.getAbsoluteFile()));608 cacheDir = Main.platform.getDefaultCacheDirectory(); 609 } 610 } 611 if (!cacheDir.exists() && !cacheDir.mkdirs()) { 612 Main.warn(tr("Failed to create missing cache directory: {0}", cacheDir.getAbsoluteFile())); 597 613 JOptionPane.showMessageDialog( 598 614 Main.parent, 599 tr("<html>Failed to create missing cache directory: {0}</html>", cacheDir File.getAbsoluteFile()),615 tr("<html>Failed to create missing cache directory: {0}</html>", cacheDir.getAbsoluteFile()), 600 616 tr("Error"), 601 617 JOptionPane.ERROR_MESSAGE 602 618 ); 603 619 } 604 return cacheDirFile; 605 } 606 607 /** 608 * @return A list of all existing directories where resources could be stored. 620 return cacheDir; 621 } 622 623 private void addPossibleResourceDir(Set<String> locations, String s) { 624 if (s != null) { 625 if (!s.endsWith(File.separator)) { 626 s += File.separator; 627 } 628 locations.add(s); 629 } 630 } 631 632 /** 633 * Returns a set of all existing directories where resources could be stored. 634 * @return A set of all existing directories where resources could be stored. 609 635 */ 610 636 public Collection<String> getAllPossiblePreferenceDirs() { 611 LinkedList<String> locations = new LinkedList<>(); 612 locations.add(getPreferencesDir()); 613 String s; 614 if ((s = System.getenv("JOSM_RESOURCES")) != null) { 615 if (!s.endsWith(File.separator)) { 616 s = s + File.separator; 617 } 618 locations.add(s); 619 } 620 if ((s = System.getProperty("josm.resources")) != null) { 621 if (!s.endsWith(File.separator)) { 622 s = s + File.separator; 623 } 624 locations.add(s); 625 } 626 String appdata = System.getenv("APPDATA"); 627 if (System.getenv("ALLUSERSPROFILE") != null && appdata != null 628 && appdata.lastIndexOf(File.separator) != -1) { 629 appdata = appdata.substring(appdata.lastIndexOf(File.separator)); 630 locations.add(new File(new File(System.getenv("ALLUSERSPROFILE"), 631 appdata), "JOSM").getPath()); 632 } 633 locations.add("/usr/local/share/josm/"); 634 locations.add("/usr/local/lib/josm/"); 635 locations.add("/usr/share/josm/"); 636 locations.add("/usr/lib/josm/"); 637 Set<String> locations = new HashSet<>(); 638 addPossibleResourceDir(locations, getPreferencesDirectory().getPath()); 639 addPossibleResourceDir(locations, getUserDataDirectory().getPath()); 640 addPossibleResourceDir(locations, System.getenv("JOSM_RESOURCES")); 641 addPossibleResourceDir(locations, System.getProperty("josm.resources")); 642 if (Main.isPlatformWindows()) { 643 String appdata = System.getenv("APPDATA"); 644 if (System.getenv("ALLUSERSPROFILE") != null && appdata != null 645 && appdata.lastIndexOf(File.separator) != -1) { 646 appdata = appdata.substring(appdata.lastIndexOf(File.separator)); 647 locations.add(new File(new File(System.getenv("ALLUSERSPROFILE"), 648 appdata), "JOSM").getPath()); 649 } 650 } else { 651 locations.add("/usr/local/share/josm/"); 652 locations.add("/usr/local/lib/josm/"); 653 locations.add("/usr/share/josm/"); 654 locations.add("/usr/lib/josm/"); 655 } 637 656 return locations; 638 657 } … … 811 830 public void init(boolean reset) { 812 831 // get the preferences. 813 File prefDir = getPreferencesDir File();832 File prefDir = getPreferencesDirectory(); 814 833 if (prefDir.exists()) { 815 834 if(!prefDir.isDirectory()) { -
trunk/src/org/openstreetmap/josm/data/validation/OsmValidator.java
r7574 r7834 154 154 */ 155 155 public static String getValidatorDir() { 156 return Main.pref.getPreferencesDir() + "validator/";156 return new File(Main.pref.getUserDataDirectory(), "validator").getAbsolutePath(); 157 157 } 158 158 … … 174 174 ignoredErrors.clear(); 175 175 if (Main.pref.getBoolean(ValidatorPreference.PREF_USE_IGNORE, true)) { 176 Path path = Paths.get(getValidatorDir() +"ignorederrors");176 Path path = Paths.get(getValidatorDir()).resolve("ignorederrors"); 177 177 if (Files.exists(path)) { 178 178 try { … … 196 196 197 197 public static void saveIgnoredErrors() { 198 try (PrintWriter out = new PrintWriter(new OutputStreamWriter( 199 new File OutputStream(getValidatorDir() + "ignorederrors"), StandardCharsets.UTF_8), false)) {198 try (PrintWriter out = new PrintWriter(new OutputStreamWriter(new FileOutputStream( 199 new File(getValidatorDir(), "ignorederrors")), StandardCharsets.UTF_8), false)) { 200 200 for (String e : ignoredErrors) { 201 201 out.println(e); … … 282 282 * until most bugs were discovered while keeping the processing time reasonable) 283 283 */ 284 public final void initializeGridDetail() {284 public static final void initializeGridDetail() { 285 285 String code = Main.getProjection().toCode(); 286 286 if (Arrays.asList(ProjectionPreference.wgs84.allCodes()).contains(code)) {
Note:
See TracChangeset
for help on using the changeset viewer.