Redefine property path

This commit is contained in:
Oystein Kristoffer Tveit 2021-04-20 20:38:57 +02:00
parent 86b7be7647
commit c865a38349
1 changed files with 8 additions and 3 deletions

View File

@ -18,7 +18,10 @@ import app.model.Model;
public class SettingsProvider implements SettingsProviderI {
private static EventBus eventBus;
private static final String SETTINGS_PATH = "/BNNsettings/settings.dat";
private static final String SETTINGS_PATH =
(System.getProperty("os.name").startsWith("Windows"))
? System.getProperty("user.home") + "\\AppData\\Roaming\\/BNNsettings.dat"
: System.getProperty("user.home") + System.getProperty("file.separator") + ".BNNsettings.dat";
public SettingsProvider(EventBus eB) {
setEventBus(eB);
@ -34,7 +37,7 @@ public class SettingsProvider implements SettingsProviderI {
public void loadSettings() {
List<String> settings = new ArrayList<>();
List<String> legalSettings = Arrays.asList("Java", "Markdown", "Monokai", "Solarized Light");
try (Scanner sc = new Scanner(new File(getClass().getResource(SETTINGS_PATH).getPath()))) {
try (Scanner sc = new Scanner(new File(SETTINGS_PATH))) {
while (sc.hasNextLine()) {
var nextLine = sc.nextLine().trim();
@ -53,6 +56,7 @@ public class SettingsProvider implements SettingsProviderI {
}
} catch (IOException e) {
System.err.println("[WARNING] Couldn't read settings file. Using defaults");
eventBus.post(new LanguageChangedEvent("Java"));
eventBus.post(new ThemeChangedEvent("Monokai"));
}
@ -61,11 +65,12 @@ public class SettingsProvider implements SettingsProviderI {
@Override
public void saveSettings() {
try (PrintWriter writer = new PrintWriter(new File(getClass().getResource(SETTINGS_PATH).getPath()))) {
try (PrintWriter writer = new PrintWriter(new File(SETTINGS_PATH))) {
writer.println("- Settings:");
writer.println("Programming Language = " + Model.getLanguage().getName());
writer.println("Theme = " + Model.getTheme());
} catch (IOException e) {
System.err.println("[ERROR] Couldn't write to settings file.");
System.err.println(e);
}