diff options
author | Andrew Su <[email protected]> | 2011-05-30 14:03:23 -0400 |
---|---|---|
committer | Andrew Su <[email protected]> | 2011-05-30 14:03:23 -0400 |
commit | daf00816d5b19f04945e5d5e29c5c02fff8b4b4e (patch) | |
tree | 8142f5aeab654c73b6eae816921ce6f1dd5b078a /netx/net/sourceforge | |
parent | fbbeace7bbc50dc6b7fe348f9bf50bcb4479f55a (diff) |
Check if cache directory is writable from itweb-settings
Diffstat (limited to 'netx/net/sourceforge')
-rw-r--r-- | netx/net/sourceforge/jnlp/controlpanel/TemporaryInternetFilesPanel.java | 23 |
1 files changed, 21 insertions, 2 deletions
diff --git a/netx/net/sourceforge/jnlp/controlpanel/TemporaryInternetFilesPanel.java b/netx/net/sourceforge/jnlp/controlpanel/TemporaryInternetFilesPanel.java index 43b59b4..a946595 100644 --- a/netx/net/sourceforge/jnlp/controlpanel/TemporaryInternetFilesPanel.java +++ b/netx/net/sourceforge/jnlp/controlpanel/TemporaryInternetFilesPanel.java @@ -26,6 +26,7 @@ import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.awt.event.ItemEvent; import java.awt.event.ItemListener; +import java.io.File; import javax.swing.JButton; import javax.swing.JCheckBox; @@ -33,6 +34,7 @@ import javax.swing.JComboBox; import javax.swing.JComponent; import javax.swing.JFileChooser; import javax.swing.JLabel; +import javax.swing.JOptionPane; import javax.swing.JPanel; import javax.swing.JSlider; import javax.swing.JSpinner; @@ -109,10 +111,27 @@ public class TemporaryInternetFilesPanel extends NamedBorderPanel implements Cha public void actionPerformed(ActionEvent e) { JFileChooser fileChooser = new JFileChooser(); fileChooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); + fileChooser.setFileHidingEnabled(false); if (fileChooser.showOpenDialog(null) == JFileChooser.APPROVE_OPTION) { + // Check if we have permission to write to that location. String result = fileChooser.getSelectedFile().getAbsolutePath(); - location.setText(result); - config.setProperty(properties[1], result); + File dirLocation = new File(result); + boolean canWrite = dirLocation.canWrite(); + while (!canWrite && dirLocation != null){ // File does not exist, or no permission. + + if (dirLocation.exists()) { + JOptionPane.showMessageDialog(null, "No permission to write to this location."); + return; + } + + dirLocation = dirLocation.getParentFile(); + canWrite = dirLocation.canWrite(); + } + + if (canWrite) { + location.setText(result); + config.setProperty(properties[1], result); + } } } }); |