Ignore:
Timestamp:
2018-04-19T20:37:16+02:00 (6 years ago)
Author:
Don-vip
Message:

see #16204 - Allow to start and close JOSM in WebStart sandbox mode (where every external access is denied). This was very useful to reproduce some very tricky bugs that occured in real life but were almost impossible to diagnose.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/data/preferences/JosmBaseDirectories.java

    r13021 r13647  
    33
    44import static org.openstreetmap.josm.tools.I18n.tr;
     5import static org.openstreetmap.josm.tools.Utils.getSystemProperty;
    56
    67import java.io.File;
     
    2728    }
    2829
     30    /**
     31     * Returns the unique instance.
     32     * @return the unique instance
     33     */
    2934    public static JosmBaseDirectories getInstance() {
    3035        return InstanceHolder.INSTANCE;
     
    4954    public File getPreferencesDirectory(boolean createIfMissing) {
    5055        if (preferencesDir == null) {
    51             String path;
    52             path = System.getProperty("josm.pref");
     56            String path = getSystemProperty("josm.pref");
    5357            if (path != null) {
    5458                preferencesDir = new File(path).getAbsoluteFile();
    5559            } else {
    56                 path = System.getProperty("josm.home");
     60                path = getSystemProperty("josm.home");
    5761                if (path != null) {
    5862                    preferencesDir = new File(path).getAbsoluteFile();
     
    6266            }
    6367        }
    64         if (createIfMissing && !preferencesDir.exists() && !preferencesDir.mkdirs()) {
    65             Logging.warn(tr("Failed to create missing preferences directory: {0}", preferencesDir.getAbsoluteFile()));
    66             JOptionPane.showMessageDialog(
    67                     Main.parent,
    68                     tr("<html>Failed to create missing preferences directory: {0}</html>", preferencesDir.getAbsoluteFile()),
    69                     tr("Error"),
    70                     JOptionPane.ERROR_MESSAGE
    71             );
     68        try {
     69            if (createIfMissing && !preferencesDir.exists() && !preferencesDir.mkdirs()) {
     70                Logging.warn(tr("Failed to create missing preferences directory: {0}", preferencesDir.getAbsoluteFile()));
     71                JOptionPane.showMessageDialog(
     72                        Main.parent,
     73                        tr("<html>Failed to create missing preferences directory: {0}</html>", preferencesDir.getAbsoluteFile()),
     74                        tr("Error"),
     75                        JOptionPane.ERROR_MESSAGE
     76                );
     77            }
     78        } catch (SecurityException e) {
     79            Logging.log(Logging.LEVEL_ERROR, "Unable to check if preferences dir must be created", e);
    7280        }
    7381        return preferencesDir;
     
    7785    public File getUserDataDirectory(boolean createIfMissing) {
    7886        if (userdataDir == null) {
    79             String path;
    80             path = System.getProperty("josm.userdata");
     87            String path = getSystemProperty("josm.userdata");
    8188            if (path != null) {
    8289                userdataDir = new File(path).getAbsoluteFile();
    8390            } else {
    84                 path = System.getProperty("josm.home");
     91                path = getSystemProperty("josm.home");
    8592                if (path != null) {
    8693                    userdataDir = new File(path).getAbsoluteFile();
     
    9097            }
    9198        }
    92         if (createIfMissing && !userdataDir.exists() && !userdataDir.mkdirs()) {
    93             Logging.warn(tr("Failed to create missing user data directory: {0}", userdataDir.getAbsoluteFile()));
    94             JOptionPane.showMessageDialog(
    95                     Main.parent,
    96                     tr("<html>Failed to create missing user data directory: {0}</html>", userdataDir.getAbsoluteFile()),
    97                     tr("Error"),
    98                     JOptionPane.ERROR_MESSAGE
    99             );
     99        try {
     100            if (createIfMissing && !userdataDir.exists() && !userdataDir.mkdirs()) {
     101                Logging.warn(tr("Failed to create missing user data directory: {0}", userdataDir.getAbsoluteFile()));
     102                JOptionPane.showMessageDialog(
     103                        Main.parent,
     104                        tr("<html>Failed to create missing user data directory: {0}</html>", userdataDir.getAbsoluteFile()),
     105                        tr("Error"),
     106                        JOptionPane.ERROR_MESSAGE
     107                );
     108            }
     109        } catch (SecurityException e) {
     110            Logging.log(Logging.LEVEL_ERROR, "Unable to check if user data dir must be created", e);
    100111        }
    101112        return userdataDir;
     
    105116    public File getCacheDirectory(boolean createIfMissing) {
    106117        if (cacheDir == null) {
    107             String path = System.getProperty("josm.cache");
     118            String path = getSystemProperty("josm.cache");
    108119            if (path != null) {
    109120                cacheDir = new File(path).getAbsoluteFile();
    110121            } else {
    111                 path = System.getProperty("josm.home");
     122                path = getSystemProperty("josm.home");
    112123                if (path != null) {
    113124                    cacheDir = new File(path, "cache");
     
    122133            }
    123134        }
    124         if (createIfMissing && !cacheDir.exists() && !cacheDir.mkdirs()) {
    125             Logging.warn(tr("Failed to create missing cache directory: {0}", cacheDir.getAbsoluteFile()));
    126             JOptionPane.showMessageDialog(
    127                     Main.parent,
    128                     tr("<html>Failed to create missing cache directory: {0}</html>", cacheDir.getAbsoluteFile()),
    129                     tr("Error"),
    130                     JOptionPane.ERROR_MESSAGE
    131             );
     135        try {
     136            if (createIfMissing && !cacheDir.exists() && !cacheDir.mkdirs()) {
     137                Logging.warn(tr("Failed to create missing cache directory: {0}", cacheDir.getAbsoluteFile()));
     138                JOptionPane.showMessageDialog(
     139                        Main.parent,
     140                        tr("<html>Failed to create missing cache directory: {0}</html>", cacheDir.getAbsoluteFile()),
     141                        tr("Error"),
     142                        JOptionPane.ERROR_MESSAGE
     143                );
     144            }
     145        } catch (SecurityException e) {
     146            Logging.log(Logging.LEVEL_ERROR, "Unable to check if cache dir must be created", e);
    132147        }
    133148        return cacheDir;
Note: See TracChangeset for help on using the changeset viewer.