diff --git a/src/main/java/com/sheepit/client/Client.java b/src/main/java/com/sheepit/client/Client.java index 32fc9f7..38c4311 100644 --- a/src/main/java/com/sheepit/client/Client.java +++ b/src/main/java/com/sheepit/client/Client.java @@ -1164,6 +1164,12 @@ import okhttp3.HttpUrl; frame.delete(); ajob.setOutputImagePath(null); + if (ajob.getPreviewImagePath() != null) { + frame = new File(ajob.getPreviewImagePath()); + frame.delete(); + ajob.setPreviewImagePath(null); + } + return confirmJobReturnCode; } diff --git a/src/main/java/com/sheepit/client/Job.java b/src/main/java/com/sheepit/client/Job.java index 9a0cf0c..26becc9 100644 --- a/src/main/java/com/sheepit/client/Job.java +++ b/src/main/java/com/sheepit/client/Job.java @@ -40,6 +40,7 @@ import java.text.SimpleDateFormat; import java.time.Duration; import java.time.Instant; import java.util.ArrayList; +import java.util.Arrays; import java.util.Date; import java.util.HashMap; import java.util.List; @@ -63,6 +64,8 @@ import java.util.regex.Pattern; private String rendererMD5; private String id; private String outputImagePath; + + private String previewImagePath; private long outputImageSize; private String path; // path inside of the archive private String rendererCommand; @@ -502,7 +505,7 @@ import java.util.regex.Pattern; } if (files.length != 0) { - new File(files[0].getAbsolutePath()).delete(); + Arrays.stream(files).forEach( file -> new File(file.getAbsolutePath()).delete()); } if (isServerBlockJob()) { return Error.Type.RENDERER_KILLED_BY_SERVER; @@ -547,6 +550,15 @@ import java.util.regex.Pattern; return Error.Type.NOOUTPUTFILE; } else { + if (files.length == 2) { + Arrays.sort(files); //in case of an exr we end up with 2 images, the output as an exr and the preview as a jpg, we want to ensure the output comes first + String path = files[1].getAbsolutePath(); + String extension = path.substring(path.lastIndexOf(".") + 1).toLowerCase(); + if ("jpg".equals(extension)) { + setPreviewImagePath(files[1].getAbsolutePath()); + } + } + setOutputImagePath(files[0].getAbsolutePath()); this.outputImageSize = new File(getOutputImagePath()).length(); log.debug(String.format("Job::render pictureFilename: %s, size: %d'", getOutputImagePath(), this.outputImageSize)); diff --git a/src/main/java/com/sheepit/client/Utils.java b/src/main/java/com/sheepit/client/Utils.java index 1e6f464..6e6e041 100644 --- a/src/main/java/com/sheepit/client/Utils.java +++ b/src/main/java/com/sheepit/client/Utils.java @@ -41,11 +41,21 @@ import java.security.MessageDigest; import java.security.NoSuchAlgorithmException; import java.util.Calendar; import java.util.Date; +import java.util.HashMap; +import java.util.Map; import java.util.TimeZone; import java.util.regex.Matcher; import java.util.regex.Pattern; public class Utils { + + private static Map mimeTypes = new HashMap<>(); + + static { + mimeTypes.put(".tga", "image/tga"); + mimeTypes.put(".exr", "image/x-exr"); + } + public static int unzipFileIntoDirectory(String zipFileName_, String destinationDirectory, char[] password, Log log) { try { ZipFile zipFile = new ZipFile(zipFileName_); @@ -227,12 +237,14 @@ public class Utils { mimeType = URLConnection.guessContentTypeFromName(file); } - if (mimeType == null && file.endsWith(".tga")) { // fallback for TGA - mimeType = "image/tga"; - } - - if (mimeType == null && file.endsWith(".exr")) { // fallback for EXR - mimeType = "image/x-exr"; + if (mimeType == null || (mimeType.equals("image/aces") && file.toLowerCase().endsWith(".exr"))) { + try { + String extension = file.substring(file.lastIndexOf('.')); + mimeType = mimeTypes.get(extension); + } + catch (IndexOutOfBoundsException e) { + e.printStackTrace(); + } } return mimeType; diff --git a/src/main/java/com/sheepit/client/standalone/GuiSwing.java b/src/main/java/com/sheepit/client/standalone/GuiSwing.java index 1ed86e5..b09d0b3 100644 --- a/src/main/java/com/sheepit/client/standalone/GuiSwing.java +++ b/src/main/java/com/sheepit/client/standalone/GuiSwing.java @@ -47,7 +47,6 @@ import javax.swing.border.EmptyBorder; import java.awt.AWTException; import java.awt.Dimension; import java.awt.FontMetrics; -import java.awt.Graphics; import java.awt.Graphics2D; import java.awt.GridBagLayout; import java.awt.Image; @@ -64,7 +63,6 @@ import java.awt.image.BufferedImage; import java.io.IOException; import java.lang.reflect.InvocationTargetException; import java.net.URL; -import java.util.Objects; import java.util.Timer; import java.util.TimerTask; diff --git a/src/main/java/com/sheepit/client/standalone/swing/activity/Working.java b/src/main/java/com/sheepit/client/standalone/swing/activity/Working.java index 67ea0c8..54a1820 100644 --- a/src/main/java/com/sheepit/client/standalone/swing/activity/Working.java +++ b/src/main/java/com/sheepit/client/standalone/swing/activity/Working.java @@ -31,6 +31,7 @@ import java.awt.event.WindowEvent; import java.awt.image.BufferedImage; import java.awt.Image; import java.io.File; +import java.io.IOException; import java.text.DecimalFormat; import java.util.Date; import java.util.Objects; @@ -416,8 +417,16 @@ public class Working implements Activity { icon = new ImageIcon(getClass().getResource("/frame_power_detection.jpg")); } else { + String path = null; try { - String path = lastJob.getOutputImagePath(); + boolean hasPreview = lastJob.getPreviewImagePath() != null; + + if (hasPreview) { + path = lastJob.getPreviewImagePath(); + } + else { + path = lastJob.getOutputImagePath(); + } BufferedImage img = ImageIO.read(new File(path)); float width = img.getWidth(); @@ -433,7 +442,7 @@ public class Working implements Activity { } catch (Exception e) { log.error(String.format("Working::showLastRender() Unable to load/preview rendered frame [%s]. Exception %s", - lastJob.getOutputImagePath(), e.getMessage())); + path, e.getMessage())); } }