Factor out config path
This commit is contained in:
@ -52,8 +52,24 @@ public class Main extends Application {
|
||||
private static final Logger logger = Logger.getLogger(Main.class.getName());
|
||||
// TODO: get git info
|
||||
private static final String VERSION = "0.0.1";
|
||||
private static Path configPath = null;
|
||||
private static Path statePath = null;
|
||||
|
||||
public static Path getConfigPath() {
|
||||
if (configPath == null) {
|
||||
String configHome = System.getenv("XDG_CONFIG_HOME");
|
||||
|
||||
if (configHome != null && !configHome.isEmpty() && Paths.get(configHome).isAbsolute()) {
|
||||
configPath = Paths.get(configHome, "numbers-station");
|
||||
} else {
|
||||
String userHome = System.getProperty("user.home");
|
||||
configPath = Paths.get(userHome, ".config", "numbers-station");
|
||||
}
|
||||
}
|
||||
|
||||
return configPath;
|
||||
}
|
||||
|
||||
public static Path getStatePath() {
|
||||
if (statePath == null) {
|
||||
String stateHome = System.getenv("XDG_STATE_HOME");
|
||||
|
@ -31,17 +31,7 @@ public class MainSettings {
|
||||
}
|
||||
|
||||
public static Path getSettingsFilePath() {
|
||||
String configHome = System.getenv("XDG_CONFIG_HOME");
|
||||
Path directoryPath;
|
||||
|
||||
if (configHome != null && !configHome.isEmpty() && Paths.get(configHome).isAbsolute()) {
|
||||
directoryPath = Paths.get(configHome, "numbers-station");
|
||||
} else {
|
||||
String userHome = System.getProperty("user.home");
|
||||
directoryPath = Paths.get(userHome, ".config", "numbers-station");
|
||||
}
|
||||
|
||||
return directoryPath.resolve("main-settings.xml");
|
||||
return Main.getConfigPath().resolve("main-settings.xml");
|
||||
}
|
||||
|
||||
public ArrayList<StationSettings> getStations() {
|
||||
|
@ -128,22 +128,12 @@ public class StationSettings {
|
||||
}
|
||||
|
||||
public Path stationPath() {
|
||||
String configHome = System.getenv("XDG_CONFIG_HOME");
|
||||
Path directoryPath;
|
||||
|
||||
if (configHome != null && !configHome.isEmpty() && Paths.get(configHome).isAbsolute()) {
|
||||
directoryPath = Paths.get(configHome, "numbers-station");
|
||||
} else {
|
||||
String userHome = System.getProperty("user.home");
|
||||
directoryPath = Paths.get(userHome, ".config", "numbers-station");
|
||||
}
|
||||
|
||||
String stationDirName = null;
|
||||
try {
|
||||
stationDirName = java.net.URLEncoder.encode(name, "UTF-8");
|
||||
} catch(UnsupportedEncodingException e) {} // We know UTF-8 is supported
|
||||
|
||||
return directoryPath.resolve(stationDirName);
|
||||
return Main.getConfigPath().resolve(stationDirName);
|
||||
}
|
||||
|
||||
public String generateMessage(int generationAttempts) throws MessageGenerationException {
|
||||
|
Reference in New Issue
Block a user