diff options
author | Jose <jose@zeroc.com> | 2018-06-11 23:05:32 +0200 |
---|---|---|
committer | Jose <jose@zeroc.com> | 2018-06-11 23:05:32 +0200 |
commit | 7c92d149e2e4ee6a4e1b9ef7f97405388c687fa0 (patch) | |
tree | 19038935f672e414d1c4d0ecbbc9d58316eaf96a | |
parent | Add deprecation note to slice2html man page (diff) | |
download | ice-7c92d149e2e4ee6a4e1b9ef7f97405388c687fa0.tar.bz2 ice-7c92d149e2e4ee6a4e1b9ef7f97405388c687fa0.tar.xz ice-7c92d149e2e4ee6a4e1b9ef7f97405388c687fa0.zip |
Move IceGrid GUI configuration data to os specific directorie
Closes #76
-rw-r--r-- | java/src/IceGridGUI/src/main/java/com/zeroc/IceGridGUI/Coordinator.java | 158 | ||||
-rw-r--r-- | java/src/IceGridGUI/src/main/java/com/zeroc/IceGridGUI/Main.java | 2 |
2 files changed, 112 insertions, 48 deletions
diff --git a/java/src/IceGridGUI/src/main/java/com/zeroc/IceGridGUI/Coordinator.java b/java/src/IceGridGUI/src/main/java/com/zeroc/IceGridGUI/Coordinator.java index eb2c372f664..5013115bd06 100644 --- a/java/src/IceGridGUI/src/main/java/com/zeroc/IceGridGUI/Coordinator.java +++ b/java/src/IceGridGUI/src/main/java/com/zeroc/IceGridGUI/Coordinator.java @@ -27,6 +27,9 @@ import java.io.File; import java.io.FileInputStream; import java.io.FileOutputStream; +import java.nio.file.Paths; +import java.nio.file.Files; + import javax.swing.*; import javax.swing.border.EmptyBorder; import javax.swing.filechooser.FileFilter; @@ -3497,68 +3500,130 @@ public class Coordinator return _connected; } - public String getDataDirectory() throws java.lang.Exception + public void tryMigrateDataDirectory() { - if(_dataDir == null) + String oldDataDir = null; + if(System.getProperty("os.name").startsWith("Windows")) { - if(System.getProperty("os.name").startsWith("Windows")) + String regKey = "\"HKCU\\Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\Shell Folders\""; + String regQuery = "reg query " + regKey + " /v Personal"; + try { - String regKey = "\"HKCU\\Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\Shell Folders\""; - String regQuery = "reg query " + regKey + " /v Personal"; - try + java.lang.Process process = Runtime.getRuntime().exec(regQuery); + process.waitFor(); + if(process.exitValue() != 0) { - java.lang.Process process = Runtime.getRuntime().exec(regQuery); - process.waitFor(); - if(process.exitValue() != 0) - { - throw new Exception("Could not read Windows registry key `" + regKey + "'"); - } + JOptionPane.showMessageDialog(getMainFrame(), + "Could not read Windows registry key `" + regKey + "'", + "Initialization Exception", + JOptionPane.ERROR_MESSAGE); + return; + } - java.io.InputStream is = process.getInputStream(); - java.io.StringWriter sw = new java.io.StringWriter(); - int c; - while((c = is.read()) != -1) - { - sw.write(c); - } - String[] result = sw.toString().split("\n"); - for(String line : result) - { - int i = line.indexOf("REG_SZ"); - if(i == -1) - { - continue; - } - _dataDir = line.substring(i + "REG_SZ".length(), line.length()).trim(); - break; - } - if(_dataDir == null) - { - throw new Exception("Could not get Documents dir from Windows registry key `" + regKey + "'"); - } - _dataDir += File.separator + "ZeroC" + File.separator + "IceGrid Admin" + File.separator + - "KeyStore"; + java.io.InputStream is = process.getInputStream(); + java.io.StringWriter sw = new java.io.StringWriter(); + int c; + while((c = is.read()) != -1) + { + sw.write(c); } - catch(java.io.IOException ex) + String[] result = sw.toString().split("\n"); + for(String line : result) { - throw new Exception("Could not read Windows registry key `" + regKey + "'\n" + ex.toString()); + int i = line.indexOf("REG_SZ"); + if(i == -1) + { + continue; + } + oldDataDir = line.substring(i + "REG_SZ".length(), line.length()).trim(); + break; } - catch(java.lang.InterruptedException ex) + + if(oldDataDir == null) { - throw new Exception("Could not read Windows registry key `" + regKey + "'\n" + ex.toString()); + JOptionPane.showMessageDialog(getMainFrame(), + "Could not get Documents dir from Windows registry key `" + regKey + "'", + "Initialization Exception", + JOptionPane.ERROR_MESSAGE); + return; } + oldDataDir = Paths.get(oldDataDir, "ZeroC", "IceGrid Admin", "KeyStore").toString(); } - else + catch(java.io.IOException ex) + { + JOptionPane.showMessageDialog(getMainFrame(), + "Could not read Windows registry key `" + regKey + "'\n" + ex.toString(), + "Initialization Exception", + JOptionPane.ERROR_MESSAGE); + return; + } + catch(java.lang.InterruptedException ex) + { + JOptionPane.showMessageDialog(getMainFrame(), + "Could not read Windows registry key `" + regKey + "'\n" + ex.toString(), + "Initialization Exception", + JOptionPane.ERROR_MESSAGE); + return; + } + } + else if(System.getProperty("os.name").startsWith("Mac OS")) + { + oldDataDir = Paths.get(System.getProperty("user.home"), ".ZeroC", "IceGrid Admin", "KeyStore").toString(); + } + + if(oldDataDir != null) + { + String dataDir = getDataDirectory(); + if(new File(dataDir).isDirectory() && new File(dataDir).list().length == 0 && + new File(oldDataDir).isDirectory() && new File(oldDataDir).list().length > 0) { - _dataDir = System.getProperty("user.home") + File.separator + ".ZeroC" + File.separator + - "IceGrid Admin" + File.separator + "KeyStore"; + for(File f : new File(oldDataDir).listFiles()) + { + try + { + Files.copy(Paths.get(oldDataDir, f.getName()), + Paths.get(dataDir, f.getName())); + new File(Paths.get(oldDataDir, f.getName()).toString()).delete(); + } + catch(java.io.IOException ex) + { + JOptionPane.showMessageDialog(getMainFrame(), + "Could not move `" + + Paths.get(oldDataDir, f.getName()).toString() + "' to " + + "`" + Paths.get(oldDataDir, f.getName()).toString() + "'", + "Initialization Exception", + JOptionPane.ERROR_MESSAGE); + return; + } + } } } - if(!new File(_dataDir).isDirectory()) + } + + public String getDataDirectory() + { + String dataDir = null; + if(System.getProperty("os.name").startsWith("Windows")) + { + dataDir = Paths.get(System.getenv("APPDATA"), "..", "Local", "ZeroC", + "IceGrid Admin", "KeyStore").toString(); + } + else if(System.getProperty("os.name").startsWith("Mac OS")) { - new File(_dataDir).mkdirs(); + dataDir = Paths.get(System.getProperty("user.home"), "Library", "Application Support", "ZeroC", + "IceGrid Admin", "KeyStore").toString(); } - return _dataDir; + else + { + dataDir = Paths.get(System.getProperty("user.home"), ".ZeroC", "IceGrid Admin", "KeyStore").toString(); + } + + if(!new File(dataDir).isDirectory()) + { + new File(dataDir).mkdirs(); + } + + return dataDir; } public IGraphView[] getGraphViews() @@ -3723,7 +3788,6 @@ public class Coordinator getScaledInstance(16, 16, java.awt.Image.SCALE_SMOOTH )); } - private String _dataDir; private final com.zeroc.Ice.InitializationData _initData; private com.zeroc.Ice.Communicator _communicator; diff --git a/java/src/IceGridGUI/src/main/java/com/zeroc/IceGridGUI/Main.java b/java/src/IceGridGUI/src/main/java/com/zeroc/IceGridGUI/Main.java index a80d710c91f..64376e25efa 100644 --- a/java/src/IceGridGUI/src/main/java/com/zeroc/IceGridGUI/Main.java +++ b/java/src/IceGridGUI/src/main/java/com/zeroc/IceGridGUI/Main.java @@ -119,7 +119,7 @@ public class Main extends JFrame }); _coordinator = new Coordinator(this, args, Preferences.userRoot().node("IceGridGUI")); - + _coordinator.tryMigrateDataDirectory(); _coordinator.showMainFrame(); } |