Project archive can be password protected
This commit is contained in:
@@ -29,12 +29,14 @@
|
||||
<pathelement location="extern/platform.jar"/>
|
||||
<pathelement location="extern/jna.jar"/>
|
||||
<pathelement location="extern/args4j.jar"/>
|
||||
<pathelement location="extern/zip4j.jar"/>
|
||||
</classpath>
|
||||
</javac>
|
||||
|
||||
<unjar src="extern/platform.jar" dest="build">
|
||||
<filelist dir="." files="extern/jna.jar" />
|
||||
<filelist dir="." files="extern/args4j.jar" />
|
||||
<filelist dir="." files="extern/zip4j.jar" />
|
||||
</unjar>
|
||||
|
||||
<copy file="resources/icon.png" tofile="build/icon.png" overwrite="true" />
|
||||
|
||||
BIN
extern/zip4j.jar
vendored
Normal file
BIN
extern/zip4j.jar
vendored
Normal file
Binary file not shown.
@@ -674,11 +674,18 @@ public class Client {
|
||||
renderer_path_file.mkdir();
|
||||
|
||||
// unzip the archive
|
||||
ret = Utils.unzipFileIntoDirectory(renderer_archive, renderer_path);
|
||||
ret = Utils.unzipFileIntoDirectory(renderer_archive, renderer_path, null);
|
||||
if (ret != 0) {
|
||||
this.gui.error("Client::prepareWorkingDirectory, error with Utils.unzipFileIntoDirectory of the renderer (returned " + ret + ")");
|
||||
return -1;
|
||||
}
|
||||
|
||||
try {
|
||||
File f = new File(ajob.getRendererPath());
|
||||
f.setExecutable(true);
|
||||
}
|
||||
catch (SecurityException e) {
|
||||
}
|
||||
}
|
||||
|
||||
String scene_archive = ajob.getSceneArchivePath();
|
||||
@@ -694,7 +701,7 @@ public class Client {
|
||||
scene_path_file.mkdir();
|
||||
|
||||
// unzip the archive
|
||||
ret = Utils.unzipFileIntoDirectory(scene_archive, scene_path);
|
||||
ret = Utils.unzipFileIntoDirectory(scene_archive, scene_path, ajob.getSceneArchivePassword());
|
||||
if (ret != 0) {
|
||||
this.gui.error("Client::prepareWorkingDirectory, error with Utils.unzipFileIntoDirectory of the scene (returned " + ret + ")");
|
||||
return -2;
|
||||
|
||||
@@ -56,6 +56,7 @@ public class Job {
|
||||
private String script;
|
||||
private boolean useGPU;
|
||||
private String name;
|
||||
private String password;
|
||||
private String extras;
|
||||
private String updateRenderingStatusMethod;
|
||||
private boolean synchronousUpload;
|
||||
@@ -66,7 +67,7 @@ public class Job {
|
||||
private Configuration config;
|
||||
private Log log;
|
||||
|
||||
public Job(Configuration config_, Gui gui_, Log log_, String id_, String frame_, String revision_, String path_, boolean use_gpu, String command_, String script_, String sceneMd5_, String rendererMd5_, String name_, String extras_, boolean synchronous_upload_, String update_method_) {
|
||||
public Job(Configuration config_, Gui gui_, Log log_, String id_, String frame_, String revision_, String path_, boolean use_gpu, String command_, String script_, String sceneMd5_, String rendererMd5_, String name_, String password_, String extras_, boolean synchronous_upload_, String update_method_) {
|
||||
config = config_;
|
||||
id = id_;
|
||||
numFrame = frame_;
|
||||
@@ -77,6 +78,7 @@ public class Job {
|
||||
sceneMD5 = sceneMd5_;
|
||||
rendererMD5 = rendererMd5_;
|
||||
name = name_;
|
||||
password = password_;
|
||||
extras = extras_;
|
||||
synchronousUpload = synchronous_upload_;
|
||||
gui = gui_;
|
||||
@@ -193,6 +195,10 @@ public class Job {
|
||||
return config.workingDirectory.getAbsolutePath() + File.separator + sceneMD5 + ".zip";
|
||||
}
|
||||
|
||||
public String getSceneArchivePassword() {
|
||||
return password;
|
||||
}
|
||||
|
||||
public boolean simultaneousUploadIsAllowed() {
|
||||
return synchronousUpload;
|
||||
}
|
||||
|
||||
@@ -387,7 +387,7 @@ public class Server extends Thread implements HostnameVerifier, X509TrustManager
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
String[] job_node_require_attribute = { "id", "archive_md5", "path", "revision", "use_gpu", "frame", "name", "extras" };
|
||||
String[] job_node_require_attribute = { "id", "archive_md5", "path", "revision", "use_gpu", "frame", "name", "extras", "password" };
|
||||
String[] renderer_node_require_attribute = { "md5", "commandline" };
|
||||
|
||||
for (String e : job_node_require_attribute) {
|
||||
@@ -432,6 +432,7 @@ public class Server extends Thread implements HostnameVerifier, X509TrustManager
|
||||
job_node.getAttribute("archive_md5"),
|
||||
renderer_node.getAttribute("md5"),
|
||||
job_node.getAttribute("name"),
|
||||
job_node.getAttribute("password"),
|
||||
frame_extras,
|
||||
synchronous_upload,
|
||||
update_method
|
||||
|
||||
@@ -34,11 +34,12 @@ import java.util.Date;
|
||||
import java.util.TimeZone;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
import java.util.zip.ZipEntry;
|
||||
import java.util.zip.ZipInputStream;
|
||||
|
||||
import javax.xml.bind.DatatypeConverter;
|
||||
|
||||
import net.lingala.zip4j.core.ZipFile;
|
||||
import net.lingala.zip4j.exception.ZipException;
|
||||
|
||||
import org.w3c.dom.Document;
|
||||
import org.w3c.dom.Element;
|
||||
import org.w3c.dom.NodeList;
|
||||
@@ -47,71 +48,17 @@ import com.sheepit.client.Error.ServerCode;
|
||||
import com.sheepit.client.exception.FermeExceptionNoSpaceLeftOnDevice;
|
||||
|
||||
public class Utils {
|
||||
public static int unzipFileIntoDirectory(String zipFileName_, String jiniHomeParentDirName_) throws FermeExceptionNoSpaceLeftOnDevice {
|
||||
File rootdir = new File(jiniHomeParentDirName_);
|
||||
public static int unzipFileIntoDirectory(String zipFileName_, String destinationDirectory, String password) throws FermeExceptionNoSpaceLeftOnDevice {
|
||||
try {
|
||||
ZipInputStream zis = new ZipInputStream(new FileInputStream(zipFileName_));
|
||||
byte[] buffer = new byte[4096];
|
||||
ZipEntry ze;
|
||||
while ((ze = zis.getNextEntry()) != null) {
|
||||
FileOutputStream fos = null;
|
||||
try {
|
||||
File f = new File(rootdir.getAbsolutePath() + File.separator + ze.getName());
|
||||
if (ze.isDirectory()) {
|
||||
f.mkdirs();
|
||||
continue;
|
||||
}
|
||||
else {
|
||||
f.getParentFile().mkdirs();
|
||||
f.createNewFile();
|
||||
try {
|
||||
f.setExecutable(true);
|
||||
}
|
||||
catch (NoSuchMethodError e2) {
|
||||
// do nothing it's related to the filesystem
|
||||
}
|
||||
}
|
||||
|
||||
fos = new FileOutputStream(f);
|
||||
int numBytes;
|
||||
while ((numBytes = zis.read(buffer, 0, buffer.length)) != -1) {
|
||||
fos.write(buffer, 0, numBytes);
|
||||
}
|
||||
fos.close();
|
||||
}
|
||||
catch (IOException e) {
|
||||
if (noFreeSpaceOnDisk(jiniHomeParentDirName_)) {
|
||||
throw new FermeExceptionNoSpaceLeftOnDevice();
|
||||
}
|
||||
|
||||
Log logger = Log.getInstance(null); // might not print the log since the config is null
|
||||
logger.error("Utils::unzipFileIntoDirectory(" + zipFileName_ + "," + jiniHomeParentDirName_ + ") exception " + e);
|
||||
return -3;
|
||||
}
|
||||
catch (Exception e1) {
|
||||
e1.printStackTrace();
|
||||
}
|
||||
if (fos != null) {
|
||||
try {
|
||||
fos.close();
|
||||
}
|
||||
catch (IOException e) {
|
||||
}
|
||||
}
|
||||
zis.closeEntry();
|
||||
ZipFile zipFile = new ZipFile(zipFileName_);
|
||||
|
||||
if (password != null && zipFile.isEncrypted()) {
|
||||
zipFile.setPassword(password);
|
||||
}
|
||||
zipFile.extractAll(destinationDirectory);
|
||||
}
|
||||
catch (FermeExceptionNoSpaceLeftOnDevice e) {
|
||||
throw e;
|
||||
}
|
||||
catch (IllegalArgumentException e) {
|
||||
Log logger = Log.getInstance(null); // might not print the log since the config is null
|
||||
logger.error("Utils::unzipFileIntoDirectory(" + zipFileName_ + "," + jiniHomeParentDirName_ + ") exception " + e);
|
||||
return -2;
|
||||
}
|
||||
catch (Exception e) {
|
||||
Log logger = Log.getInstance(null); // might not print the log since the config is null
|
||||
logger.error("Utils::unzipFileIntoDirectory(" + zipFileName_ + "," + jiniHomeParentDirName_ + ") exception " + e);
|
||||
catch (ZipException e) {
|
||||
e.printStackTrace();
|
||||
return -1;
|
||||
}
|
||||
return 0;
|
||||
|
||||
Reference in New Issue
Block a user