Mercurial > 510Connectbot
comparison src/org/tn5250j/GlobalConfigure.java @ 22:e067ee54f638 tn5250
adding tn5250 files
author | Carl Byington <carl@five-ten-sg.com> |
---|---|
date | Tue, 03 Jun 2014 10:40:11 -0700 |
parents | 94abfc6441a4 |
children | 5949eb469a79 |
comparison
equal
deleted
inserted
replaced
21:94abfc6441a4 | 22:e067ee54f638 |
---|---|
35 import java.io.IOException; | 35 import java.io.IOException; |
36 import java.io.PrintWriter; | 36 import java.io.PrintWriter; |
37 import java.util.Hashtable; | 37 import java.util.Hashtable; |
38 import java.util.Properties; | 38 import java.util.Properties; |
39 | 39 |
40 import javax.swing.JOptionPane; | |
41 | |
42 import com.five_ten_sg.connectbot.TerminalView; | 40 import com.five_ten_sg.connectbot.TerminalView; |
43 import org.tn5250j.interfaces.ConfigureFactory; | 41 import org.tn5250j.interfaces.ConfigureFactory; |
44 import org.tn5250j.tools.logging.TN5250jLogFactory; | 42 import org.tn5250j.tools.logging.TN5250jLogFactory; |
45 import org.tn5250j.tools.logging.TN5250jLogger; | 43 import org.tn5250j.tools.logging.TN5250jLogger; |
46 | 44 |
64 */ | 62 */ |
65 static private Properties settings; | 63 static private Properties settings; |
66 | 64 |
67 static private Hashtable registry = new Hashtable(); | 65 static private Hashtable registry = new Hashtable(); |
68 static private Hashtable headers = new Hashtable(); //LUC GORRENS | 66 static private Hashtable headers = new Hashtable(); //LUC GORRENS |
69 | |
70 // Moved to ConfigureFactory | |
71 // static final public String SESSIONS = "sessions"; | |
72 static final public File ses = new File(SESSIONS); | |
73 // static final public String MACROS = "macros"; | |
74 // static final public String KEYMAP = "keymap"; | |
75 | |
76 private final TN5250jLogger log = TN5250jLogFactory.getLogger (this.getClass()); | 67 private final TN5250jLogger log = TN5250jLogFactory.getLogger (this.getClass()); |
77 | 68 |
78 /** | 69 /** |
79 * The constructor is made protected to allow overriding. | 70 * The constructor is made protected to allow overriding. |
80 */ | 71 */ |
189 } | 180 } |
190 catch (FileNotFoundException fnfea) { | 181 catch (FileNotFoundException fnfea) { |
191 log.info(" Information Message: " | 182 log.info(" Information Message: " |
192 + fnfea.getMessage() + ". The file " + settingsFile() | 183 + fnfea.getMessage() + ". The file " + settingsFile() |
193 + " will be created for first time use."); | 184 + " will be created for first time use."); |
194 checkLegacy(); | |
195 saveSettings(); | 185 saveSettings(); |
196 } | 186 } |
197 catch (IOException ioea) { | 187 catch (IOException ioea) { |
198 log.warn("IO Exception accessing File " | 188 log.warn("IO Exception accessing File " |
199 + settingsFile() + " for the following reason : " | 189 + settingsFile() + " for the following reason : " |
201 } | 191 } |
202 catch (SecurityException sea) { | 192 catch (SecurityException sea) { |
203 log.warn("Security Exception for file " | 193 log.warn("Security Exception for file " |
204 + settingsFile() + " This file can not be " | 194 + settingsFile() + " This file can not be " |
205 + "accessed because : " + sea.getMessage()); | 195 + "accessed because : " + sea.getMessage()); |
206 } | |
207 } | |
208 | |
209 private void checkDirs() { | |
210 // we now check to see if the settings directory is a directory. If not then we create it | |
211 File sd = new File(settings.getProperty("emulator.settingsDirectory")); | |
212 if (!sd.isDirectory()) | |
213 sd.mkdirs(); | |
214 } | |
215 | |
216 private void checkLegacy() { | |
217 // we check if the sessions file already exists in the directory | |
218 // if it does exist we are working with an old install so we | |
219 // need to set the settings directory to the users directory | |
220 // SESSIONS is declared as a string, so we just can use the keyword here. | |
221 if(ses.exists()) { | |
222 int cfc; | |
223 cfc = JOptionPane.showConfirmDialog(null, | |
224 "Dear User,\n\n" + | |
225 "Seems you are using an old version of tn5250j.\n" + | |
226 "In meanwhile the application became multi-user capable,\n" + | |
227 "which means ALL the config- and settings-files are\n" + | |
228 "placed in your home-dir to avoid further problems in\n" + | |
229 "the near future.\n\n" + | |
230 "You have the choice to choose if you want the files\n" + | |
231 "to be copied or not, please make your choice !\n\n" + | |
232 "Shall we copy the files to the new location ?", | |
233 "Old install detected", JOptionPane.WARNING_MESSAGE, | |
234 JOptionPane.YES_NO_OPTION); | |
235 if (cfc == 0) { | |
236 // Here we do a checkdir so we know the destination-dir exists | |
237 checkDirs(); | |
238 copyConfigs(SESSIONS); | |
239 copyConfigs(MACROS); | |
240 copyConfigs(KEYMAP); | |
241 } | |
242 else { | |
243 JOptionPane.showMessageDialog(null, | |
244 "Dear User,\n\n" + | |
245 "You choosed not to copy the file.\n" + | |
246 "This means the program will end here.\n\n" + | |
247 "To use this NON-STANDARD behaviour start tn5250j\n" + | |
248 "with -Demulator.settingsDirectory=<settings-dir> \n" + | |
249 "as a parameter to avoid this question all the time.", | |
250 "Using NON-STANDARD behaviour", JOptionPane.WARNING_MESSAGE); | |
251 System.exit(0); | |
252 } | |
253 } | |
254 } | |
255 | |
256 private void copyConfigs(String sesFile) { | |
257 /** Copy the config-files to the user's home-dir */ | |
258 String srcFile = System.getProperty("user.dir") + File.separator + sesFile; | |
259 String dest = System.getProperty("user.home") + | |
260 File.separator + TN5250J_FOLDER + File.separator + sesFile; | |
261 File rmvFile = new File(sesFile); | |
262 try { | |
263 FileReader r = new FileReader(srcFile); | |
264 BufferedReader b = new BufferedReader(r); | |
265 | |
266 FileWriter w = new FileWriter(dest); | |
267 PrintWriter p = new PrintWriter(w); | |
268 String regel = b.readLine(); | |
269 while (regel != null) { | |
270 p.println(regel); | |
271 regel = b.readLine(); | |
272 } | |
273 b.close(); | |
274 p.close(); | |
275 rmvFile.delete(); | |
276 } | |
277 catch (FileNotFoundException e) { | |
278 log.warn(srcFile + " not found !"); | |
279 } | |
280 catch (IOException e) { | |
281 log.warn("Global io-error !"); | |
282 } | |
283 catch (ArrayIndexOutOfBoundsException e) { | |
284 } | 196 } |
285 } | 197 } |
286 | 198 |
287 /** | 199 /** |
288 * Save the settings for the global configuration | 200 * Save the settings for the global configuration |
469 boolean createFile, String header) { | 381 boolean createFile, String header) { |
470 return getProperties(regKey,fileName,false,"",false); | 382 return getProperties(regKey,fileName,false,"",false); |
471 } | 383 } |
472 | 384 |
473 @Override | 385 @Override |
474 public Properties getProperties(String regKey,String fileName, | 386 public Properties getProperties(String regKey, |
475 boolean createFile,String header, | 387 String fileName, |
476 boolean reloadIfLoaded) { | 388 boolean createFile, |
389 String header, | |
390 boolean reloadIfLoaded) { | |
477 | 391 |
478 if (!registry.containsKey(regKey) || reloadIfLoaded) { | 392 if (!registry.containsKey(regKey) || reloadIfLoaded) { |
479 | 393 |
480 FileInputStream in = null; | 394 FileInputStream in = null; |
481 Properties props = new Properties(); | 395 Properties props = new Properties(); |