Use XDG_CONFIG_HOME
This commit is contained in:
parent
837b08c4cb
commit
0704a4a931
@ -118,12 +118,10 @@ public class MainController implements Initializable {
|
||||
XmlMapper xmlMapper = new XmlMapper();
|
||||
xmlMapper.registerModule(new JavaTimeModule());
|
||||
String userHome = System.getProperty("user.home");
|
||||
// TODO: XDG
|
||||
Path directoryPath = Paths.get(userHome, ".numbers-station");
|
||||
Path filePath = directoryPath.resolve("settings.xml");
|
||||
try {
|
||||
|
||||
// Create the directory if it doesn't exist
|
||||
Path filePath = MainSettings.getSettingsFilePath();
|
||||
Path directoryPath = filePath.getParent();
|
||||
try {
|
||||
if (!Files.exists(directoryPath)) {
|
||||
Files.createDirectories(directoryPath);
|
||||
}
|
||||
|
@ -25,6 +25,21 @@ public class MainSettings {
|
||||
stations.add(new StationSettings("Station 1"));
|
||||
}
|
||||
|
||||
public static Path getSettingsFilePath() {
|
||||
String configHome = System.getenv("XDG_CONFIG_HOME");
|
||||
Path directoryPath;
|
||||
Path filePath;
|
||||
|
||||
if (configHome != null && !configHome.isEmpty()) {
|
||||
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");
|
||||
}
|
||||
|
||||
public ArrayList<StationSettings> getStations() {
|
||||
return stations;
|
||||
}
|
||||
@ -58,11 +73,9 @@ public class MainSettings {
|
||||
xmlMapper.registerModule(new JavaTimeModule());
|
||||
xmlMapper.configure(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS, false);
|
||||
try {
|
||||
String userHome = System.getProperty("user.home");
|
||||
Path directoryPath = Paths.get(userHome, ".numbers-station");
|
||||
Path filePath = directoryPath.resolve("settings.xml");
|
||||
Path filePath = getSettingsFilePath();
|
||||
Path directoryPath = filePath.getParent();
|
||||
|
||||
// Create the directory if it doesn't exist
|
||||
if (!Files.exists(directoryPath)) {
|
||||
Files.createDirectories(directoryPath);
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user