change to saving app config file to a location in the user's home dir

basically, save it under ~/.llanfair always.

the reason being is that under certain deployments it's entirely
possible the current directory where the JAR is located _might_ not be
writeable by the application. but the user's home directory should
always be writeable.
This commit is contained in:
Gered 2015-12-01 13:12:41 -05:00
parent 9e9628bacd
commit f1729b3e88
3 changed files with 43 additions and 1 deletions

View file

@ -3,6 +3,7 @@ package org.fenix.llanfair;
import org.fenix.llanfair.config.Settings;
import org.fenix.llanfair.gui.RunPane;
import org.fenix.utils.Resources;
import org.fenix.utils.UserSettings;
import org.fenix.utils.gui.BorderlessFrame;
import org.fenix.utils.locale.LocaleDelegate;
import org.fenix.utils.locale.LocaleEvent;
@ -63,6 +64,9 @@ public class Llanfair extends BorderlessFrame implements TableModelListener,
*/
private Llanfair() {
super( "Llanfair" );
UserSettings.initDirectory();
LocaleDelegate.setDefault( Settings.language.get() );
LocaleDelegate.addLocaleListener( this );

View file

@ -2,6 +2,7 @@ package org.fenix.llanfair.config;
import org.fenix.llanfair.Language;
import org.fenix.llanfair.Run;
import org.fenix.utils.UserSettings;
import org.fenix.utils.config.Configuration;
import java.awt.*;
@ -179,7 +180,7 @@ public class Settings {
* whose value is requested.
*/
private static void retrieve() {
global = Configuration.newInstance( new File( "./llanfair.xml" ) );
global = Configuration.newInstance( new File(UserSettings.getSettingsPath() + File.separator + "llanfair.xml" ) );
if ( global.isEmpty() ) {
setDefaultValues();
}

View file

@ -0,0 +1,37 @@
package org.fenix.utils;
import java.io.File;
public class UserSettings {
private static File settingsPath = new File(System.getProperty("user.home") + File.separator + ".llanfair");
private static File splitsPath = new File(settingsPath.getPath() + File.separator + "splits");
/**
* Checks for the existence of the directory used to store the user's settings for the
* application. If it does not exist, we attempt to create it.
*/
public static void initDirectory() {
Boolean settingsPathExists = settingsPath.exists();
if (!settingsPathExists)
settingsPathExists = settingsPath.mkdir();
if (!splitsPath.exists() && settingsPathExists)
splitsPath.mkdir();
}
/**
* Returns the path to the location where user settings can be saved in.
*/
public static String getSettingsPath() {
return settingsPath.getPath();
}
/**
* Returns the path to the location where splits can be saved in. This is
* located as a subdirectory within the user settings directory.
*/
public static String getSplitsPath() {
return splitsPath.getPath();
}
}