Changeset 12856 in josm for trunk/src/org/openstreetmap


Ignore:
Timestamp:
2017-09-14T15:09:01+02:00 (7 years ago)
Author:
bastiK
Message:

see #15229 - add parameter to base directory methods

Location:
trunk/src/org/openstreetmap/josm
Files:
16 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/actions/ShowStatusReportAction.java

    r12855 r12856  
    231231        final String propJavaHome = System.getProperty("java.home");
    232232        final String propJavaHomeAlt = "<java.home>";
    233         final String prefDir = Config.getDirs().getPreferencesDirectory().toString();
     233        final String prefDir = Config.getDirs().getPreferencesDirectory(false).toString();
    234234        final String prefDirAlt = "<josm.pref>";
    235         final String userDataDir = Config.getDirs().getUserDataDirectory().toString();
     235        final String userDataDir = Config.getDirs().getUserDataDirectory(false).toString();
    236236        final String userDataDirAlt = "<josm.userdata>";
    237         final String userCacheDir = Config.getDirs().getCacheDirectory().toString();
     237        final String userCacheDir = Config.getDirs().getCacheDirectory(false).toString();
    238238        final String userCacheDirAlt = "<josm.cache>";
    239239        final String userHomeDir = System.getProperty("user.home");
  • trunk/src/org/openstreetmap/josm/data/Preferences.java

    r12855 r12856  
    331331     * @return The user defined preferences directory, containing the preferences.xml file
    332332     * @since 7834
    333      */
     333     * @deprecated use {@link #getPreferencesDirectory(boolean)}
     334     */
     335    @Deprecated
     336    public File getPreferencesDirectory() {
     337        return getPreferencesDirectory(false);
     338    }
     339
    334340    @Override
    335     public File getPreferencesDirectory() {
     341    public File getPreferencesDirectory(boolean createIfMissing) {
    336342        if (preferencesDir != null)
    337343            return preferencesDir;
     
    348354            }
    349355        }
     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        }
    350365        return preferencesDir;
    351366    }
     
    356371     * @return The user data directory, containing autosave, plugins, etc.
    357372     * @since 7834
    358      */
     373     * @deprecated use {@link #getUserDataDirectory(boolean)}
     374     */
     375    @Deprecated
     376    public File getUserDataDirectory() {
     377        return getUserDataDirectory(false);
     378    }
     379
    359380    @Override
    360     public File getUserDataDirectory() {
     381    public File getUserDataDirectory(boolean createIfMissing) {
    361382        if (userdataDir != null)
    362383            return userdataDir;
     
    373394            }
    374395        }
     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        }
    375405        return userdataDir;
    376406    }
     
    381411     */
    382412    public File getPreferenceFile() {
    383         return new File(getPreferencesDirectory(), "preferences.xml");
     413        return new File(getPreferencesDirectory(false), "preferences.xml");
    384414    }
    385415
     
    389419     */
    390420    public File getDefaultsCacheFile() {
    391         return new File(getCacheDirectory(), "default_preferences.xml");
     421        return new File(getCacheDirectory(true), "default_preferences.xml");
    392422    }
    393423
     
    397427     */
    398428    public File getPluginsDirectory() {
    399         return new File(getUserDataDirectory(), "plugins");
     429        return new File(getUserDataDirectory(false), "plugins");
    400430    }
    401431
     
    406436     *
    407437     * @return the cache directory
    408      */
     438     * @deprecated use {@link #getCacheDirectory(boolean)}
     439     */
     440    @Deprecated
     441    public File getCacheDirectory() {
     442        return getCacheDirectory(true);
     443    }
     444
    409445    @Override
    410     public File getCacheDirectory() {
     446    public File getCacheDirectory(boolean createIfMissing) {
    411447        if (cacheDir != null)
    412448            return cacheDir;
     
    427463            }
    428464        }
    429         if (!cacheDir.exists() && !cacheDir.mkdirs()) {
     465        if (createIfMissing && !cacheDir.exists() && !cacheDir.mkdirs()) {
    430466            Logging.warn(tr("Failed to create missing cache directory: {0}", cacheDir.getAbsoluteFile()));
    431467            JOptionPane.showMessageDialog(
     
    454490    public Collection<String> getAllPossiblePreferenceDirs() {
    455491        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());
    458494        addPossibleResourceDir(locations, System.getenv("JOSM_RESOURCES"));
    459495        addPossibleResourceDir(locations, System.getProperty("josm.resources"));
     
    718754        initSuccessful = false;
    719755        // get the preferences.
    720         File prefDir = getPreferencesDirectory();
     756        File prefDir = getPreferencesDirectory(false);
    721757        if (prefDir.exists()) {
    722758            if (!prefDir.isDirectory()) {
  • trunk/src/org/openstreetmap/josm/data/cache/JCSCacheManager.java

    r12855 r12856  
    101101    @SuppressWarnings("resource")
    102102    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");
    104104
    105105        if (!cacheDir.exists() && !cacheDir.mkdirs())
  • trunk/src/org/openstreetmap/josm/data/imagery/CachedTileLoaderFactory.java

    r12855 r12856  
    5656        String defPath = null;
    5757        try {
    58             defPath = new File(Config.getDirs().getCacheDirectory(), "tiles").getAbsolutePath();
     58            defPath = new File(Config.getDirs().getCacheDirectory(true), "tiles").getAbsolutePath();
    5959        } catch (SecurityException e) {
    6060            Logging.warn(e);
  • trunk/src/org/openstreetmap/josm/data/validation/OsmValidator.java

    r12855 r12856  
    176176     */
    177177    public static String getValidatorDir() {
    178         return new File(Config.getDirs().getUserDataDirectory(), "validator").getAbsolutePath();
     178        return new File(Config.getDirs().getUserDataDirectory(true), "validator").getAbsolutePath();
    179179    }
    180180
  • trunk/src/org/openstreetmap/josm/gui/io/CustomConfigurator.java

    r12855 r12856  
    425425        String dir;
    426426        if ("prefs".equals(base) || base.isEmpty()) {
    427             dir = Config.getDirs().getPreferencesDirectory().getAbsolutePath();
     427            dir = Config.getDirs().getPreferencesDirectory(false).getAbsolutePath();
    428428        } else if ("cache".equals(base)) {
    429             dir = Config.getDirs().getCacheDirectory().getAbsolutePath();
     429            dir = Config.getDirs().getCacheDirectory(false).getAbsolutePath();
    430430        } else if ("plugins".equals(base)) {
    431431            dir = Main.pref.getPluginsDirectory().getAbsolutePath();
     
    477477                engine.eval("API={}; API.pref={}; API.fragments={};");
    478478
    479                 engine.eval("homeDir='"+normalizeDirName(Config.getDirs().getPreferencesDirectory().getAbsolutePath()) +"';");
     479                engine.eval("homeDir='"+normalizeDirName(Config.getDirs().getPreferencesDirectory(false).getAbsolutePath()) +"';");
    480480                engine.eval("josmVersion="+Version.getInstance().getVersion()+';');
    481481                String className = CustomConfigurator.class.getName();
  • trunk/src/org/openstreetmap/josm/gui/layer/AutosaveTask.java

    r12855 r12856  
    116116    private final Deque<File> deletedLayers = new LinkedList<>();
    117117
    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);
    120120
    121121    /**
  • trunk/src/org/openstreetmap/josm/gui/layer/geoimage/ThumbsLoader.java

    r12855 r12856  
    6969            try {
    7070                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");
    7272            } catch (IOException e) {
    7373                Logging.warn("Failed to initialize cache for geoimage-thumbnails");
  • trunk/src/org/openstreetmap/josm/gui/preferences/advanced/AdvancedPreference.java

    r12855 r12856  
    370370                    }
    371371                }
    372                 files = Config.getDirs().getPreferencesDirectory().listFiles();
     372                files = Config.getDirs().getPreferencesDirectory(false).listFiles();
    373373                if (files != null) {
    374374                    for (File f: files) {
  • trunk/src/org/openstreetmap/josm/io/CacheCustomContent.java

    r12855 r12856  
    7676        this.ident = ident;
    7777        this.updateInterval = updateInterval;
    78         this.path = new File(Config.getDirs().getCacheDirectory(), ident);
     78        this.path = new File(Config.getDirs().getCacheDirectory(true), ident);
    7979    }
    8080
  • trunk/src/org/openstreetmap/josm/io/CachedFile.java

    r12855 r12856  
    277277                return null;
    278278            } 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()));
    280280            } else if (name.startsWith("josmplugindir://")) {
    281281                cacheFile = new File(Main.pref.getPluginsDirectory(), name.substring("josmplugindir://".length()));
     
    448448        }
    449449        if (destDir == null) {
    450             destDir = Config.getDirs().getCacheDirectory().getPath();
     450            destDir = Config.getDirs().getCacheDirectory(true).getPath();
    451451        }
    452452
  • trunk/src/org/openstreetmap/josm/io/remotecontrol/RemoteControl.java

    r12855 r12856  
    9595     */
    9696    public static String getRemoteControlDir() {
    97         return new File(Config.getDirs().getUserDataDirectory(), "remotecontrol").getAbsolutePath();
     97        return new File(Config.getDirs().getUserDataDirectory(true), "remotecontrol").getAbsolutePath();
    9898    }
    9999
  • trunk/src/org/openstreetmap/josm/spi/preferences/IBaseDirectories.java

    r12855 r12856  
    1515     * Get the directory where user-specific configuration and preferences
    1616     * should be stored.
     17     * @param createIfMissing if true, automatically creates this directory,
     18     * in case it is missing
    1719     * @return the preferences directory
     20     * @since 12856
    1821     */
    19     File getPreferencesDirectory();
     22    File getPreferencesDirectory(boolean createIfMissing);
    2023
    2124    /**
    2225     * 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
    2328     * @return the user data directory
     29     * @since 12856
    2430     */
    25     File getUserDataDirectory();
     31    File getUserDataDirectory(boolean createIfMissing);
    2632
    2733    /**
    2834     * Get the directory where user-specific cached content (non-essential data)
    2935     * should be stored.
     36     * @param createIfMissing if true, automatically creates this directory,
     37     * in case it is missing
    3038     * @return the cache directory
     39     * @since 12856
    3140     */
    32     File getCacheDirectory();
     41    File getCacheDirectory(boolean createIfMissing);
    3342}
  • trunk/src/org/openstreetmap/josm/tools/ImageProvider.java

    r12855 r12856  
    928928    private static ImageResource getIfAvailableHttp(String url, ImageType type) {
    929929        try (CachedFile cf = new CachedFile(url).setDestDir(
    930                 new File(Config.getDirs().getCacheDirectory(), "images").getPath());
     930                new File(Config.getDirs().getCacheDirectory(true), "images").getPath());
    931931             InputStream is = cf.getInputStream()) {
    932932            switch (type) {
     
    11741174        // Try user-data directory
    11751175        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();
    11771177            try {
    11781178                u = getImageUrl(dir, imageName, additionalClassLoaders);
     
    12481248
    12491249            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());
    12511251                 InputStream is = cf.getInputStream()) {
    12521252                parser.parse(new InputSource(is));
  • trunk/src/org/openstreetmap/josm/tools/PlatformHookWindows.java

    r12855 r12856  
    477477    public File getDefaultUserDataDirectory() {
    478478        // Use preferences directory by default
    479         return Config.getDirs().getPreferencesDirectory();
     479        return Config.getDirs().getPreferencesDirectory(false);
    480480    }
    481481
     
    522522            props.load(fis);
    523523            byte[] content = Files.readAllBytes(templateFile);
    524             File cachePath = Config.getDirs().getCacheDirectory();
     524            File cachePath = Config.getDirs().getCacheDirectory(true);
    525525            Path fontconfigFile = cachePath.toPath().resolve("fontconfig.properties");
    526526            OutputStream os = Files.newOutputStream(fontconfigFile);
  • trunk/src/org/openstreetmap/josm/tools/RightAndLefthandTraffic.java

    r12855 r12856  
    153153    private static void saveOptimizedBoundaries(Collection<Way> optimizedWays) {
    154154        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");
    156156        try (Writer writer = new OutputStreamWriter(new FileOutputStream(file), StandardCharsets.UTF_8);
    157157             OsmWriter w = OsmWriterFactory.createOsmWriter(new PrintWriter(writer), false, ds.getVersion())
     
    166166
    167167    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"))) {
    169170           return OsmReader.parseDataSet(is, null).getWays();
    170171        } catch (IllegalDataException | IOException ex) {
Note: See TracChangeset for help on using the changeset viewer.