Allow user to set the computer name
This commit is contained in:
@@ -24,6 +24,8 @@ import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.InputStreamReader;
|
||||
import java.net.InetAddress;
|
||||
import java.net.UnknownHostException;
|
||||
import java.util.Arrays;
|
||||
import java.util.Calendar;
|
||||
import java.util.LinkedList;
|
||||
@@ -58,11 +60,13 @@ public class Configuration {
|
||||
private boolean autoSignIn;
|
||||
private String UIType;
|
||||
private int tileSize;
|
||||
private String hostname;
|
||||
|
||||
public Configuration(File cache_dir_, String login_, String password_) {
|
||||
this.login = login_;
|
||||
this.password = password_;
|
||||
this.proxy = null;
|
||||
this.hostname = this.getDefaultHostname();
|
||||
this.static_exeDirName = "exe";
|
||||
this.maxUploadingJob = 1;
|
||||
this.nbCores = -1; // ie not set
|
||||
@@ -83,6 +87,7 @@ public class Configuration {
|
||||
this.tileSize = -1; // ie not set
|
||||
}
|
||||
|
||||
|
||||
public String toString() {
|
||||
return String.format("Configuration (workingDirectory '%s')", this.workingDirectory.getAbsolutePath());
|
||||
}
|
||||
@@ -268,6 +273,23 @@ public class Configuration {
|
||||
return this.tileSize;
|
||||
}
|
||||
|
||||
public void setHostname(String hostname_) {
|
||||
this.hostname = hostname_;
|
||||
}
|
||||
|
||||
public String getHostname() {
|
||||
return this.hostname;
|
||||
}
|
||||
|
||||
public String getDefaultHostname() {
|
||||
try {
|
||||
return InetAddress.getLocalHost().getHostName();
|
||||
}
|
||||
catch (UnknownHostException e) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public void cleanWorkingDirectory() {
|
||||
this.cleanDirectory(this.workingDirectory);
|
||||
this.cleanDirectory(this.storageDirectory);
|
||||
|
||||
@@ -34,12 +34,10 @@ import java.io.StringWriter;
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.net.ConnectException;
|
||||
import java.net.HttpURLConnection;
|
||||
import java.net.InetAddress;
|
||||
import java.net.MalformedURLException;
|
||||
import java.net.NoRouteToHostException;
|
||||
import java.net.URL;
|
||||
import java.net.URLEncoder;
|
||||
import java.net.UnknownHostException;
|
||||
import java.security.KeyManagementException;
|
||||
import java.security.NoSuchAlgorithmException;
|
||||
import java.security.cert.CertificateException;
|
||||
@@ -184,14 +182,6 @@ public class Server extends Thread implements HostnameVerifier, X509TrustManager
|
||||
OS os = OS.getOS();
|
||||
HttpURLConnection connection = null;
|
||||
try {
|
||||
String hostname;
|
||||
try {
|
||||
hostname = InetAddress.getLocalHost().getHostName();
|
||||
}
|
||||
catch (UnknownHostException e) {
|
||||
this.log.error("Server::getConfiguration failed to get hostname (exception: " + e + ")");
|
||||
hostname = "";
|
||||
}
|
||||
String url_contents = String.format("%s%s?login=%s&password=%s&cpu_family=%s&cpu_model=%s&cpu_model_name=%s&cpu_cores=%s&os=%s&ram=%s&bits=%s&version=%s&hostname=%s&extras=%s",
|
||||
this.base_url,
|
||||
"/server/config.php",
|
||||
@@ -205,7 +195,7 @@ public class Server extends Thread implements HostnameVerifier, X509TrustManager
|
||||
os.getMemory(),
|
||||
URLEncoder.encode(os.getCPU().arch(), "UTF-8"),
|
||||
this.user_config.getJarVersion(),
|
||||
URLEncoder.encode(hostname, "UTF-8"),
|
||||
URLEncoder.encode(this.user_config.getHostname(), "UTF-8"),
|
||||
this.user_config.getExtras());
|
||||
this.log.debug("Server::getConfiguration url " + url_contents);
|
||||
|
||||
|
||||
@@ -43,6 +43,7 @@ public class SettingsLoader {
|
||||
private String login;
|
||||
private String password;
|
||||
private String proxy;
|
||||
private String hostname;
|
||||
private String computeMethod;
|
||||
private String gpu;
|
||||
private String cores;
|
||||
@@ -62,11 +63,12 @@ public class SettingsLoader {
|
||||
path = path_;
|
||||
}
|
||||
|
||||
public SettingsLoader(String login_, String password_, String proxy_, ComputeType computeMethod_, GPUDevice gpu_, int cores_, int maxRam_, int maxRenderTime_, String cacheDir_, boolean autoSignIn_, String ui_, String tileSize_, int priority_) {
|
||||
public SettingsLoader(String login_, String password_, String proxy_, String hostname_, ComputeType computeMethod_, GPUDevice gpu_, int cores_, int maxRam_, int maxRenderTime_, String cacheDir_, boolean autoSignIn_, String ui_, String tileSize_, int priority_) {
|
||||
path = getDefaultFilePath();
|
||||
login = login_;
|
||||
password = password_;
|
||||
proxy = proxy_;
|
||||
hostname = hostname_;
|
||||
cacheDir = cacheDir_;
|
||||
autoSignIn = String.valueOf(autoSignIn_);
|
||||
ui = ui_;
|
||||
@@ -145,6 +147,10 @@ public class SettingsLoader {
|
||||
prop.setProperty("proxy", proxy);
|
||||
}
|
||||
|
||||
if (hostname != null) {
|
||||
prop.setProperty("hostname", hostname);
|
||||
}
|
||||
|
||||
if (autoSignIn != null) {
|
||||
prop.setProperty("auto-signin", autoSignIn);
|
||||
}
|
||||
@@ -193,6 +199,7 @@ public class SettingsLoader {
|
||||
this.login = null;
|
||||
this.password = null;
|
||||
this.proxy = null;
|
||||
this.hostname = null;
|
||||
this.computeMethod = null;
|
||||
this.gpu = null;
|
||||
this.cacheDir = null;
|
||||
@@ -249,6 +256,10 @@ public class SettingsLoader {
|
||||
this.proxy = prop.getProperty("proxy");
|
||||
}
|
||||
|
||||
if (prop.containsKey("hostname")) {
|
||||
this.hostname = prop.getProperty("hostname");
|
||||
}
|
||||
|
||||
if (prop.containsKey("auto-signin")) {
|
||||
this.autoSignIn = prop.getProperty("auto-signin");
|
||||
}
|
||||
@@ -302,6 +313,10 @@ public class SettingsLoader {
|
||||
config.setProxy(proxy);
|
||||
}
|
||||
|
||||
if ((config.getHostname() == null || config.getHostname().isEmpty() || config.getHostname().equals(config.getDefaultHostname())) && hostname != null) {
|
||||
config.setHostname(hostname);
|
||||
}
|
||||
|
||||
if (config.getPriority() == 19) { // 19 is default value
|
||||
config.setUsePriority(priority);
|
||||
}
|
||||
|
||||
@@ -119,7 +119,7 @@ public class GuiSwing extends JFrame implements Gui {
|
||||
}
|
||||
|
||||
setTitle("SheepIt Render Farm");
|
||||
setSize(520, 660);
|
||||
setSize(520, 680);
|
||||
|
||||
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
||||
|
||||
|
||||
@@ -75,6 +75,7 @@ public class Settings implements Activity {
|
||||
private JSpinner renderTime;
|
||||
private JSlider priority;
|
||||
private JTextField proxy;
|
||||
private JTextField hostname;
|
||||
|
||||
private JCheckBox saveFile;
|
||||
private JCheckBox autoSignIn;
|
||||
@@ -307,7 +308,7 @@ public class Settings implements Activity {
|
||||
parent.getContentPane().add(compute_devices_panel, constraints);
|
||||
|
||||
// other
|
||||
JPanel advanced_panel = new JPanel(new GridLayout(4, 2));
|
||||
JPanel advanced_panel = new JPanel(new GridLayout(5, 2));
|
||||
advanced_panel.setBorder(BorderFactory.createTitledBorder("Advanced options"));
|
||||
|
||||
JLabel proxyLabel = new JLabel("Proxy:");
|
||||
@@ -320,6 +321,12 @@ public class Settings implements Activity {
|
||||
advanced_panel.add(proxyLabel);
|
||||
advanced_panel.add(proxy);
|
||||
|
||||
JLabel hostnameLabel = new JLabel("Computer name:");
|
||||
hostname = new JTextField();
|
||||
hostname.setText(parent.getConfiguration().getHostname());
|
||||
|
||||
advanced_panel.add(hostnameLabel);
|
||||
advanced_panel.add(hostname);
|
||||
|
||||
JLabel renderTimeLabel = new JLabel("Max time per frame (in minute):");
|
||||
int val = 0;
|
||||
@@ -592,8 +599,13 @@ public class Settings implements Activity {
|
||||
cachePath = config.getStorageDir().getAbsolutePath();
|
||||
}
|
||||
|
||||
String hostnameText = null;
|
||||
if (hostname.getText() != null && hostname.getText().equals(parent.getConfiguration().getHostname()) == false) {
|
||||
hostnameText = hostname.getText();
|
||||
}
|
||||
|
||||
if (saveFile.isSelected()) {
|
||||
new SettingsLoader(login.getText(), new String(password.getPassword()), proxyText, method, selected_gpu, cpu_cores, max_ram, max_rendertime, cachePath, autoSignIn.isSelected(), GuiSwing.type, tile, priority.getValue()).saveFile();
|
||||
new SettingsLoader(login.getText(), new String(password.getPassword()), proxyText, hostnameText, method, selected_gpu, cpu_cores, max_ram, max_rendertime, cachePath, autoSignIn.isSelected(), GuiSwing.type, tile, priority.getValue()).saveFile();
|
||||
}
|
||||
else {
|
||||
try {
|
||||
|
||||
Reference in New Issue
Block a user