|
import java.io.*;
|
import java.awt.*;
|
import java.net.URL;
|
import java.util.zip.ZipInputStream;
|
|
public class cTools
|
{
|
static byte[] bytes = new byte[16384];
|
|
static private void GetRemoteZip(String url, String dir, String id, String name, String icon)
|
{
|
String filename = name + "_" + id;
|
|
String location = dir + "/" + filename;
|
|
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;
|
|
String modelName = null;
|
|
try
|
{
|
u = new java.net.URL(url + id);
|
is = u.openStream();
|
|
zis = new java.util.zip.ZipInputStream(is);
|
|
new java.io.File(location).mkdirs();
|
|
// now iterate through each item in the stream. The get next
|
// entry call will return a ZipEntry for each file in the stream
|
java.util.zip.ZipEntry entry;
|
while ((entry = zis.getNextEntry()) != null)
|
{
|
String entryName = entry.getName().toLowerCase();
|
|
if (entryName.endsWith(".gsm"))
|
{
|
// ArchiCAD
|
continue;
|
}
|
|
if (entryName.endsWith(".max"))
|
{
|
// 3DS MAX
|
continue;
|
}
|
|
if (entryName.endsWith(".3ds") || entryName.endsWith(".obj"))
|
{
|
modelName = entry.getName();
|
}
|
|
String s = String.format("Entry: %s len %d added %TD",
|
entry.getName(), entry.getSize(),
|
new java.util.Date(entry.getTime()));
|
System.out.println(s);
|
|
// Once we get the entry from the stream, the stream is
|
// positioned read to read the raw data, and we keep
|
// 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)
|
{
|
System.err.println("Ouch - a MalformedURLException happened.");
|
mue.printStackTrace();
|
//System.exit(2);
|
} catch (IOException ioe)
|
{
|
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
|
{
|
try
|
{
|
if (is != null)
|
{
|
is.close();
|
}
|
} catch (IOException ioe)
|
{
|
}
|
}
|
|
// System.out.println("length = " + total);
|
|
// try
|
// {
|
// Runtime.getRuntime().exec("/usr/local/bin/wget https://archive3d.net/?a=download&do=get&id=7caca905");
|
// }
|
// catch (Exception e)
|
// {
|
// e.printStackTrace();
|
// }
|
java.awt.image.BufferedImage image;
|
|
try
|
{
|
u = new java.net.URL(icon);
|
is = u.openStream();
|
|
// image = (java.awt.image.BufferedImage)javax.imageio.ImageIO.read(u);
|
//
|
// //String[] g = javax.imageio.ImageIO.getWriterFormatNames();
|
//
|
// javax.imageio.ImageIO.write(image, "jpg", new File(location + "/" + name + id + ".jpg"));
|
|
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)
|
{
|
e.printStackTrace();
|
}
|
}
|
|
static private void TransferFile(String outpath, InputStream zis) throws IOException
|
{
|
FileOutputStream output = null;
|
try
|
{
|
output = new FileOutputStream(outpath);
|
int len = 0;
|
while ((len = zis.read(bytes)) > 0)
|
{
|
output.write(bytes, 0, len);
|
}
|
} finally
|
{
|
// we must always close the output file
|
if (output != null)
|
{
|
output.close();
|
}
|
}
|
}
|
|
static void Archive(javax.swing.JFrame frame)
|
{
|
FileDialog browser = new FileDialog(frame, "Select archive to extract...", FileDialog.LOAD);
|
browser.setVisible(true);
|
String filename = browser.getFile();
|
if (filename != null && filename.length() > 0)
|
{
|
try
|
{
|
RandomAccessFile file = new RandomAccessFile(browser.getDirectory() + filename, "r");
|
String str;
|
while ((str = file.readLine()) != null)
|
{
|
System.out.println(str);
|
|
String cat = "nocat";
|
|
String[] split = str.split("category=");
|
|
if (split.length > 1)
|
{
|
String[] split2 = split[1].split(":");
|
|
cat = split2[0];
|
|
String[] split3 = cat.split("&");
|
|
cat = split3[0];
|
|
////
|
str = split2[1];
|
|
int i = 2;
|
while (i < split2.length)
|
{
|
str += ":" + split2[i++];
|
}
|
}
|
|
split = str.split("id=");
|
|
str = split[1];
|
split = str.split("\" title=\"Download ");
|
|
String id = split[0];
|
|
str = split[1];
|
split = str.split(" 3D Model\"><img src=\"");
|
|
String name = split[0];
|
|
str = split[1];
|
split = str.split("\" alt");
|
|
String icon = split[0];
|
|
GetRemoteZip("https://archive3d.net/?a=download&do=get&id=", browser.getDirectory() + "/" + cat, id, name, icon);
|
|
// To avoid network overload.
|
Thread.sleep(1000);
|
}
|
|
file.close();
|
} catch (Exception e)
|
{
|
e.printStackTrace();
|
}
|
}
|
}
|
}
|