fixes #26: xdg spec
This commit is contained in:
committed by
Sheepit Renderfarm
parent
6da387a288
commit
ba1f865316
@@ -38,6 +38,9 @@ import com.sheepit.client.hardware.gpu.GPU;
|
|||||||
import com.sheepit.client.hardware.gpu.GPUDevice;
|
import com.sheepit.client.hardware.gpu.GPUDevice;
|
||||||
import com.sheepit.client.standalone.GuiText;
|
import com.sheepit.client.standalone.GuiText;
|
||||||
import com.sheepit.client.standalone.GuiTextOneLine;
|
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;
|
import lombok.Data;
|
||||||
|
|
||||||
@Data
|
@Data
|
||||||
@@ -128,7 +131,7 @@ public class SettingsLoader {
|
|||||||
|
|
||||||
public SettingsLoader(String path_) {
|
public SettingsLoader(String path_) {
|
||||||
if (path_ == null) {
|
if (path_ == null) {
|
||||||
path = getDefaultFilePath();
|
path = OS.getOS().getDefaultConfigFilePath();
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
path = path_;
|
path = path_;
|
||||||
@@ -140,7 +143,7 @@ public class SettingsLoader {
|
|||||||
Integer maxRenderTime_, String cacheDir_, Boolean autoSignIn_, Boolean useSysTray_, Boolean isHeadless,
|
Integer maxRenderTime_, String cacheDir_, Boolean autoSignIn_, Boolean useSysTray_, Boolean isHeadless,
|
||||||
String ui_, String theme_, Integer priority_) {
|
String ui_, String theme_, Integer priority_) {
|
||||||
if (path_ == null) {
|
if (path_ == null) {
|
||||||
path = getDefaultFilePath();
|
path = OS.getOS().getDefaultConfigFilePath();
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
path = path_;
|
path = path_;
|
||||||
@@ -197,10 +200,6 @@ public class SettingsLoader {
|
|||||||
return option;
|
return option;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String getDefaultFilePath() {
|
|
||||||
return System.getProperty("user.home") + File.separator + ".sheepit.conf";
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getFilePath() {
|
public String getFilePath() {
|
||||||
return path;
|
return path;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -18,6 +18,7 @@
|
|||||||
*/
|
*/
|
||||||
package com.sheepit.client.os;
|
package com.sheepit.client.os;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
@@ -113,4 +114,30 @@ public abstract class OS {
|
|||||||
}
|
}
|
||||||
return instance;
|
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";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -18,6 +18,7 @@
|
|||||||
*/
|
*/
|
||||||
package com.sheepit.client.os;
|
package com.sheepit.client.os;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
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()));
|
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";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user