summaryrefslogtreecommitdiff
path: root/games-puzzle/magiccube4d/files/magiccube4d-xdg-config.patch
blob: e60ec6125c1c223391b2f18d8f384d9f67970491 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
From 7430d876b0efdb3f828a92df60a9e2d4d7ebc113 Mon Sep 17 00:00:00 2001
From: James Le Cuirot <chewi@gentoo.org>
Date: Sat, 17 Aug 2024 23:31:43 +0100
Subject: [PATCH] Write config to XDG_CONFIG_HOME or ~/.config unless old
 config exists or on Win

Storing configuration outside a standard user configuration directory is bad
practise and very unhelpful for distributions wanting to package this software.

This respects the old configuation location for compatibility.

XDG_CONFIG_HOME or ~/.config should make sense on just about any non-Windows OS.
---
 src/com/superliminal/util/PropertyManager.java | 18 ++++++++++++++++--
 1 file changed, 16 insertions(+), 2 deletions(-)

diff --git a/src/com/superliminal/util/PropertyManager.java b/src/com/superliminal/util/PropertyManager.java
index 80567fc..2a6de12 100644
--- a/src/com/superliminal/util/PropertyManager.java
+++ b/src/com/superliminal/util/PropertyManager.java
@@ -4,6 +4,8 @@ import java.util.*;
 import java.io.*;
 import java.awt.*;
 import java.net.*;
+import java.nio.file.InvalidPathException;
+import java.nio.file.Paths;
 
 /**
  * Title: PropertyManager
@@ -101,8 +103,19 @@ public class PropertyManager extends Properties {
      * Applications should load any user-specific property overrides directly into this object
      * and then call setProperty whenever a user action needs to change one.
      */
-    public final static PropertyManager userprefs = new LocalProps(new File(StaticUtils.getBinDir(), PRODUCT_NAME + ".props"));
+    public final static PropertyManager userprefs;
     static {
+        File propsFile = Paths.get(StaticUtils.getBinDir(), PRODUCT_NAME + ".props").toFile();
+
+        if (!propsFile.canWrite() && !System.getProperty("os.name").startsWith("Windows")) {
+            try {
+                propsFile = Paths.get(System.getenv("XDG_CONFIG_HOME"), PRODUCT_NAME + ".props").toFile();
+            } catch (NullPointerException | InvalidPathException e) {
+                propsFile = Paths.get(System.getProperty("user.home"), ".config", PRODUCT_NAME + ".props").toFile();
+            }
+        }
+
+        userprefs = new LocalProps(propsFile);
         System.out.println("Launch dir: " + StaticUtils.getBinDir());
     }
 
@@ -256,8 +269,9 @@ public class PropertyManager extends Properties {
             if(localPropFile == null || storeFailed)
                 return;
             try {
+                localPropFile.getParentFile().mkdirs();
                 this.store(new FileOutputStream(localPropFile), PRODUCT_NAME + " User Preferences");
-            } catch(IOException e) {
+            } catch(IOException | SecurityException e) {
                 storeFailed = true; // so as to only give fail msg once
                 if(!localPropFile.canWrite())
                     System.err.println("Can't write");
-- 
2.45.2