X-Git-Url: http://gitweb.fperrin.net/?a=blobdiff_plain;f=tim%2Fprune%2Ffunction%2FSaveConfig.java;h=af7eb83e20eee289c03f2588e1a27fe67f14eca5;hb=649c5da6ee1bbc590699e11a92316ece2ea8512d;hp=0f2339f7ea84708cdd44eeb30d08927516d7cbc2;hpb=112bb0c9b46894adca9a33ed8c99ea712b253185;p=GpsPrune.git diff --git a/tim/prune/function/SaveConfig.java b/tim/prune/function/SaveConfig.java index 0f2339f..af7eb83 100644 --- a/tim/prune/function/SaveConfig.java +++ b/tim/prune/function/SaveConfig.java @@ -20,9 +20,9 @@ import javax.swing.JLabel; import javax.swing.JPanel; import tim.prune.App; -import tim.prune.Config; import tim.prune.GenericFunction; import tim.prune.I18nManager; +import tim.prune.config.Config; /** * Class to provide the function to save the config settings @@ -128,23 +128,46 @@ public class SaveConfig extends GenericFunction private void finish() { File configFile = Config.getConfigFile(); - if (configFile == null) {configFile = new File(".pruneconfig");} + if (configFile == null) {configFile = Config.HOME_CONFIG_FILE;} JFileChooser chooser = new JFileChooser(configFile.getAbsoluteFile().getParent()); chooser.setSelectedFile(configFile); int response = chooser.showSaveDialog(_parentFrame); if (response == JFileChooser.APPROVE_OPTION) { File saveFile = chooser.getSelectedFile(); - try - { - Config.getAllConfig().store(new FileOutputStream(saveFile), "Prune config file"); - } - catch (IOException ioe) { - _app.showErrorMessageNoLookup(getNameKey(), - I18nManager.getText("error.save.failed") + " : " + ioe.getMessage()); - } + saveConfig(saveFile); } _dialog.dispose(); _dialog = null; } + + /** + * Autosave the settings file without any prompts + */ + public void silentSave() + { + saveConfig(Config.getConfigFile()); + } + + /** + * Actually save the config file + * @param inSaveFile file to save to + */ + private void saveConfig(File inSaveFile) + { + FileOutputStream outStream = null; + try + { + outStream = new FileOutputStream(inSaveFile); + Config.getAllConfig().store(outStream, "GpsPrune config file"); + } + catch (IOException ioe) { + _app.showErrorMessageNoLookup(getNameKey(), + I18nManager.getText("error.save.failed") + " : " + ioe.getMessage()); + } + catch (NullPointerException npe) {} // no config file given + finally { + try {outStream.close();} catch (Exception e) {} + } + } }