NUR/pkgs/JAVMovieScraper/0002-respectXDG.patch

79 lines
3.9 KiB
Diff

From a347ad085f22d0282ad64926533f2b585e9c3a5c Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Daniel=20L=C3=B8vbr=C3=B8tte=20Olsen?= <daniel@dodsorf.as>
Date: Sun, 3 Nov 2019 13:55:09 +0100
Subject: [PATCH 2/3] respectXDG
---
.../AllAmalgamationOrderingPreferences.java | 7 +++++--
.../doctord/model/preferences/Settings.java | 10 +++++++---
2 files changed, 12 insertions(+), 5 deletions(-)
diff --git a/src/main/java/moviescraper/doctord/controller/amalgamation/AllAmalgamationOrderingPreferences.java b/src/main/java/moviescraper/doctord/controller/amalgamation/AllAmalgamationOrderingPreferences.java
index ac9cf4e..ce57ee3 100644
--- a/src/main/java/moviescraper/doctord/controller/amalgamation/AllAmalgamationOrderingPreferences.java
+++ b/src/main/java/moviescraper/doctord/controller/amalgamation/AllAmalgamationOrderingPreferences.java
@@ -29,7 +29,8 @@ import moviescraper.doctord.controller.siteparsingprofile.specific.TheMovieDatab
public class AllAmalgamationOrderingPreferences {
Map<ScraperGroupName, ScraperGroupAmalgamationPreference> allAmalgamationOrderingPreferences;
- private static final String settingsFileName = "AmalgamationSettings.json";
+ private final static String folderNameOfSettings = (System.getenv("XDG_CONFIG_HOME") != null ? System.getenv("XDG_CONFIG_HOME") : System.getenv("HOME")) + "/.config/JAVMovieSraper";
+ private static final String settingsFileName = folderNameOfSettings + "/AmalgamationSettings.json";
public AllAmalgamationOrderingPreferences() {
allAmalgamationOrderingPreferences = new Hashtable<>();
@@ -89,7 +90,9 @@ public class AllAmalgamationOrderingPreferences {
}
public void saveToPreferencesFile() {
- try (FileOutputStream outputStream = new FileOutputStream(settingsFileName); JsonWriter jw = new JsonWriter(outputStream);) {
+ File f = new File(settingsFileName);
+ f.getParentFile().mkdirs();
+ try (FileOutputStream outputStream = new FileOutputStream(f); JsonWriter jw = new JsonWriter(outputStream);) {
jw.write(this);
System.out.println("Saved amalgamation preferences to " + settingsFileName);
} catch (IOException e1) {
diff --git a/src/main/java/moviescraper/doctord/model/preferences/Settings.java b/src/main/java/moviescraper/doctord/model/preferences/Settings.java
index 5810bf3..84fdde2 100644
--- a/src/main/java/moviescraper/doctord/model/preferences/Settings.java
+++ b/src/main/java/moviescraper/doctord/model/preferences/Settings.java
@@ -3,6 +3,7 @@ package moviescraper.doctord.model.preferences;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
+import java.io.File;
import java.io.IOException;
import java.util.InvalidPropertiesFormatException;
import java.util.Properties;
@@ -10,7 +11,8 @@ import java.util.Properties;
public class Settings {
private final static Properties programPreferences = new Properties();
- private static final String fileNameOfPreferences = "settings.xml";
+ private final static String folderNameOfPreferences = (System.getenv("XDG_CONFIG_HOME") != null ? System.getenv("XDG_CONFIG_HOME") : System.getenv("HOME")) + "/.config/JAVMovieSraper";
+ private static final String fileNameOfPreferences = folderNameOfPreferences + "/settings.xml";
protected interface Key {
String getKey();
@@ -39,7 +41,9 @@ public class Settings {
}
public static void savePreferences() {
- try (FileOutputStream settingsOutputStream = new FileOutputStream(fileNameOfPreferences);) {
+ File f = new File(fileNameOfPreferences);
+ f.getParentFile().mkdirs();
+ try (FileOutputStream settingsOutputStream = new FileOutputStream(f);) {
programPreferences.storeToXML(settingsOutputStream, "");
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
@@ -115,4 +119,4 @@ public class Settings {
public String toString() {
return programPreferences.toString();
}
-}
\ No newline at end of file
+}
--
2.19.3