Changeset 7834 in josm for trunk/src/org/openstreetmap/josm/data/Preferences.java
- Timestamp:
- 2014-12-19T15:05:33+01:00 (11 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
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()) {
Note:
See TracChangeset
for help on using the changeset viewer.
