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/data
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • 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
Note: See TracChangeset for help on using the changeset viewer.