From cb37a129d1adb403019c96e798e86e2da9667f15 Mon Sep 17 00:00:00 2001
From: Normand Briere <nbriere@noware.ca>
Date: Sun, 17 Nov 2019 17:56:04 -0500
Subject: [PATCH] Maze

---
 cTools.java |   57 ++++++++++++++++++++++++++++++++++++++++++++++++++++-----
 1 files changed, 52 insertions(+), 5 deletions(-)

diff --git a/cTools.java b/cTools.java
index b48b0c1..03650a5 100644
--- a/cTools.java
+++ b/cTools.java
@@ -1,6 +1,7 @@
 
 import java.io.*;
 import java.awt.*;
+import java.net.URL;
 import java.util.zip.ZipInputStream;
 
 public class cTools
@@ -15,6 +16,16 @@
 
         java.net.URL u;
         InputStream is = null;
+        
+        if (new File(location).exists())
+        {
+            // Already downloaded
+            System.out.println(location + ": Already downloaded");
+            
+            GetIcon(icon, location, "icon");
+            
+            return;
+        }
         
         java.util.zip.ZipInputStream zis;
 
@@ -39,13 +50,13 @@
                 if (entryName.endsWith(".gsm"))
                 {
                     // ArchiCAD
-                //    continue;
+                    continue;
                 }
 
                 if (entryName.endsWith(".max"))
                 {
                     // 3DS MAX
-                //    continue;
+                    continue;
                 }
 
                 if (entryName.endsWith(".3ds") || entryName.endsWith(".obj"))
@@ -63,6 +74,8 @@
                 // reading until read returns 0 or less.
                 String outpath = location + "/" + entry.getName();
                 
+                //new java.io.File(outpath).mkdirs();
+            
                 TransferFile(outpath, zis);
             }
         } catch (java.net.MalformedURLException mue)
@@ -72,8 +85,13 @@
             //System.exit(2);
         } catch (IOException ioe)
         {
-            //System.err.println("Oops - an IOException happened.");
-            //ioe.printStackTrace();
+            System.err.println("Oops - an IOException happened.");
+            ioe.printStackTrace();
+            //System.exit(3);
+        } catch (IllegalArgumentException iae)
+        {
+            System.err.println("Oops - an IllegalArgumentException happened.");
+            iae.printStackTrace();
             //System.exit(3);
         } finally
         {
@@ -114,6 +132,35 @@
             modelName = modelName.substring(0, modelName.length() - 4);
             
             TransferFile(location + "/" + modelName + ".jpg", is);
+            
+            GetIcon(icon, location, "icon");
+        }
+        catch (Exception e)
+        {
+            e.printStackTrace();
+        }
+    }
+
+    private static void GetIcon(String icon, String location, String iconName)
+    {
+        URL u;
+        InputStream is;
+        try
+        {
+            //icon = https://storage3d.com/storage/2008.08/resized/7142f85f2575b35078f15feddaf8b315_64x64.jpg
+            
+            String[] split = icon.split("resized/");
+            
+            icon = split[0] + split[1];
+            
+            split = icon.split("_64x64");
+            
+            icon = split[0] + ".jpg";
+            
+            u = new java.net.URL(icon);
+            is = u.openStream();
+
+            TransferFile(location + "/" + iconName + ".jpg", is);
         }
         catch (Exception e)
         {
@@ -201,7 +248,7 @@
                     GetRemoteZip("https://archive3d.net/?a=download&do=get&id=", browser.getDirectory() + "/" + cat, id, name, icon);
                     
                     // To avoid network overload.
-                    Thread.sleep(2000);
+                    Thread.sleep(1000);
                 }
                 
                 file.close();

--
Gitblit v1.6.2