diff --git a/build.xml b/build.xml index 69558a3..8a5ecc8 100644 --- a/build.xml +++ b/build.xml @@ -29,12 +29,14 @@ + + diff --git a/extern/zip4j.jar b/extern/zip4j.jar new file mode 100644 index 0000000..66a19e4 Binary files /dev/null and b/extern/zip4j.jar differ diff --git a/src/com/sheepit/client/Client.java b/src/com/sheepit/client/Client.java index c6f2105..9f67ad0 100644 --- a/src/com/sheepit/client/Client.java +++ b/src/com/sheepit/client/Client.java @@ -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; diff --git a/src/com/sheepit/client/Job.java b/src/com/sheepit/client/Job.java index f75008c..0fb86af 100644 --- a/src/com/sheepit/client/Job.java +++ b/src/com/sheepit/client/Job.java @@ -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; } diff --git a/src/com/sheepit/client/Server.java b/src/com/sheepit/client/Server.java index 1c0cacc..06356e6 100644 --- a/src/com/sheepit/client/Server.java +++ b/src/com/sheepit/client/Server.java @@ -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 diff --git a/src/com/sheepit/client/Utils.java b/src/com/sheepit/client/Utils.java index 5e0e12e..3cc376e 100644 --- a/src/com/sheepit/client/Utils.java +++ b/src/com/sheepit/client/Utils.java @@ -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;