Import config from file

This commit is contained in:
Laurent Clouet
2015-04-07 20:07:53 +01:00
parent d07fe1b9fc
commit 34957be7a8
2 changed files with 22 additions and 4 deletions

View File

@@ -42,6 +42,7 @@ import com.sheepit.client.ShutdownHook;
import com.sheepit.client.hardware.gpu.GPU;
import com.sheepit.client.hardware.gpu.GPUDevice;
import com.sheepit.client.network.ProxyAuthenticator;
import com.sheepit.client.standalone.swing.SettingsLoader;
public class Worker {
@Option(name = "-server", usage = "Render-farm server, default https://www.sheepit-renderfarm.com", metaVar = "URL", required = false)
@@ -83,6 +84,9 @@ public class Worker {
@Option(name = "-ui", usage = "Specify the user interface to use, default 'swing', available 'oneline', 'text', 'swing' (graphical)", required = false)
private String ui_type = "swing";
@Option(name = "-config", usage = "Specify the configuration file", required = false)
private String config_file = null;
@Option(name = "--version", usage = "Display application version", required = false, handler = VersionParameterHandler.class)
private VersionParameterHandler versionHandler;
@@ -257,6 +261,16 @@ public class Worker {
config.setComputeMethod(compute_method);
if (config_file != null) {
if (new File(config_file).exists() == false) {
System.err.println("Configuration file not found.");
System.err.println("Aborting");
System.exit(2);
}
new SettingsLoader(config_file).merge(config);
}
Log.getInstance(config).debug("client version " + config.getJarVersion());
Gui gui;

View File

@@ -24,11 +24,15 @@ public class SettingsLoader {
private String autoSignIn;
public SettingsLoader() {
generateFilePath();
path = getDefaultFilePath();
}
public SettingsLoader(String path_) {
path = path_;
}
public SettingsLoader(String login_, String password_, ComputeType computeMethod_, GPUDevice gpu_, String cacheDir_, boolean autoSignIn_) {
generateFilePath();
path = getDefaultFilePath();
login = login_;
password = password_;
cacheDir = cacheDir_;
@@ -47,8 +51,8 @@ public class SettingsLoader {
}
}
private void generateFilePath() {
path = System.getProperty("user.home") + File.separator + ".sheepit.conf";
public static String getDefaultFilePath() {
return System.getProperty("user.home") + File.separator + ".sheepit.conf";
}
public String getFilePath() {