diff --git a/src/com/sheepit/client/SettingsLoader.java b/src/com/sheepit/client/SettingsLoader.java index 0237335..d49a61a 100644 --- a/src/com/sheepit/client/SettingsLoader.java +++ b/src/com/sheepit/client/SettingsLoader.java @@ -38,6 +38,9 @@ import com.sheepit.client.hardware.gpu.GPU; import com.sheepit.client.hardware.gpu.GPUDevice; import com.sheepit.client.standalone.GuiText; import com.sheepit.client.standalone.GuiTextOneLine; +import com.sheepit.client.os.OS; +import com.sheepit.client.os.Linux; +import com.sheepit.client.os.Mac; import lombok.Data; @Data @@ -128,7 +131,7 @@ public class SettingsLoader { public SettingsLoader(String path_) { if (path_ == null) { - path = getDefaultFilePath(); + path = OS.getOS().getDefaultConfigFilePath(); } else { path = path_; @@ -140,7 +143,7 @@ public class SettingsLoader { Integer maxRenderTime_, String cacheDir_, Boolean autoSignIn_, Boolean useSysTray_, Boolean isHeadless, String ui_, String theme_, Integer priority_) { if (path_ == null) { - path = getDefaultFilePath(); + path = OS.getOS().getDefaultConfigFilePath(); } else { path = path_; @@ -197,10 +200,6 @@ public class SettingsLoader { return option; } - public static String getDefaultFilePath() { - return System.getProperty("user.home") + File.separator + ".sheepit.conf"; - } - public String getFilePath() { return path; } diff --git a/src/com/sheepit/client/os/OS.java b/src/com/sheepit/client/os/OS.java index 744767b..e7ebe24 100644 --- a/src/com/sheepit/client/os/OS.java +++ b/src/com/sheepit/client/os/OS.java @@ -18,6 +18,7 @@ */ package com.sheepit.client.os; +import java.io.File; import java.io.IOException; import java.util.List; import java.util.Map; @@ -113,4 +114,30 @@ public abstract class OS { } return instance; } + + public String getDefaultConfigFilePath() { + String xdgConfigHome = System.getenv("XDG_CONFIG_HOME"); + String userHome = System.getProperty("user.home"); + // fallback xdg config home should be ~/.config/ + if (xdgConfigHome == null || xdgConfigHome.isEmpty()) { + xdgConfigHome = userHome + File.separator + ".config"; + } + // add the config folder to the path + xdgConfigHome += File.separator + "sheepit"; + + // check if file already exists in ~/.config/sheepit/sheepit.conf + File file = new File(xdgConfigHome + File.separator + "sheepit.conf"); + if (file.exists()) { + return file.getAbsolutePath(); + } + // if it doesn't exist, try $HOME/.sheepit.conf + file = new File(userHome + File.separator + ".sheepit.conf"); + if (file.exists()) { + return file.getAbsolutePath(); + } + // if it doesn't exist, create the file in the XDG compliant location + file = new File(xdgConfigHome); + file.mkdirs(); + return file.getAbsolutePath() + File.separator + "sheepit.conf"; + } } diff --git a/src/com/sheepit/client/os/Windows.java b/src/com/sheepit/client/os/Windows.java index fe64f0e..fc81485 100644 --- a/src/com/sheepit/client/os/Windows.java +++ b/src/com/sheepit/client/os/Windows.java @@ -18,6 +18,7 @@ */ package com.sheepit.client.os; +import java.io.File; import java.io.IOException; import java.util.List; import java.util.Map; @@ -175,4 +176,8 @@ public class Windows extends OS { String.format("Windows::shutdownComputer Unable to execute the command 'shutdown /s /f /t 60...' command. Exception %s", e.getMessage())); } } + + @Override public String getDefaultConfigFilePath() { + return System.getProperty("user.home") + File.separator + ".sheepit.conf"; + } }