From bb1df852736f62928de6d8e1a1eeac3a81a39b6f Mon Sep 17 00:00:00 2001 From: Louis Date: Wed, 15 Jan 2020 21:58:11 +0100 Subject: [PATCH] Add default user data folder for mac --- src/clientP2P/ClientP2P.java | 6 +++++- src/serverP2P/ServerP2P.java | 7 ++++++- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/src/clientP2P/ClientP2P.java b/src/clientP2P/ClientP2P.java index 7c9e7de..b32aa63 100644 --- a/src/clientP2P/ClientP2P.java +++ b/src/clientP2P/ClientP2P.java @@ -23,7 +23,11 @@ public class ClientP2P { d += "."; } } - } else { + } else if (os.equals("Mac")||os.equals("Mac OS X") { + /* Apple MacOS X User Data Directory + * https://developer.apple.com/library/archive/qa/qa1170/_index.html */ + d = System.getProperty("user.home") + "/Library/"; + } else { d = "."; } d += "/P2P_JAVA_PROJECT_CLIENT/"; diff --git a/src/serverP2P/ServerP2P.java b/src/serverP2P/ServerP2P.java index 399ad31..6587423 100644 --- a/src/serverP2P/ServerP2P.java +++ b/src/serverP2P/ServerP2P.java @@ -11,7 +11,8 @@ public class ServerP2P { /* Follow XDG Base Directory Specification * https://specifications.freedesktop.org/basedir-spec/basedir-spec-latest.html */ - if (System.getProperty("os.name").equals("Linux")) { + String os = System.getProperty("os.name"); + if (os.equals("Linux")) { d = System.getenv().get("XDG_DATA_HOME"); if (d == null || d.equals("")) { d = System.getenv().get("HOME"); @@ -21,6 +22,10 @@ public class ServerP2P { d += "."; } } + } else if (os.equals("Mac")||os.equals("Mac OS X") { + /* Apple MacOS X User Data Directory + * https://developer.apple.com/library/archive/qa/qa1170/_index.html */ + d = System.getProperty("user.home") + "/Library/"; } else { d = "."; }