2002-11-15 12:28:36 +00:00
|
|
|
package installer;
|
|
|
|
|
2002-11-18 17:23:19 +00:00
|
|
|
import java.io.*;
|
|
|
|
import java.util.*;
|
|
|
|
import java.util.zip.*;
|
|
|
|
import java.awt.*;
|
|
|
|
import java.awt.event.*;
|
|
|
|
import javax.swing.*;
|
|
|
|
|
|
|
|
public class ZipData
|
|
|
|
{
|
2003-01-16 11:02:49 +00:00
|
|
|
public ZipData(String file) {
|
2002-11-18 17:23:19 +00:00
|
|
|
}
|
|
|
|
|
2003-01-16 11:02:49 +00:00
|
|
|
public boolean extractEntry(String entry, String destination,
|
|
|
|
JLabel statusLabel) {
|
|
|
|
|
|
|
|
OutputStream out = null;
|
|
|
|
InputStream in = null;
|
|
|
|
|
|
|
|
System.out.println("Copying: " + entry);
|
|
|
|
System.out.println("To: " + destination);
|
|
|
|
|
2002-11-22 10:34:36 +00:00
|
|
|
if (statusLabel != null) {
|
|
|
|
statusLabel.setText("Copying " + entry);
|
|
|
|
}
|
2003-01-16 11:02:49 +00:00
|
|
|
|
2003-02-06 17:19:52 +00:00
|
|
|
String entryName;
|
2003-01-16 11:02:49 +00:00
|
|
|
if (entry.lastIndexOf("/") != -1) {
|
2003-02-06 17:19:52 +00:00
|
|
|
entryName = entry.substring(entry.lastIndexOf("/") + 1);
|
2002-11-18 17:23:19 +00:00
|
|
|
}
|
2003-01-16 11:02:49 +00:00
|
|
|
else {
|
2003-02-06 17:19:52 +00:00
|
|
|
entryName = entry;
|
2002-11-18 17:23:19 +00:00
|
|
|
}
|
|
|
|
|
2003-02-06 17:19:52 +00:00
|
|
|
String destName;
|
|
|
|
if (destination.lastIndexOf(File.separator) != -1) {
|
|
|
|
destName = destination.substring(destination.lastIndexOf(File.separator) + 1);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
destName = destination;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!destName.equals(entryName))
|
|
|
|
destination = destination.concat(entryName);
|
|
|
|
|
2003-01-16 11:02:49 +00:00
|
|
|
System.out.println("Unzipping " + entry + " to " + destination);
|
2002-11-18 17:23:19 +00:00
|
|
|
|
2003-01-16 11:02:49 +00:00
|
|
|
try {
|
|
|
|
out = new FileOutputStream(destination);
|
2002-11-22 10:34:36 +00:00
|
|
|
}
|
2003-01-16 11:02:49 +00:00
|
|
|
catch (IOException ioe) {
|
|
|
|
System.err.println("Error opening " + destination +
|
|
|
|
": " + ioe.getMessage());
|
2002-11-18 17:23:19 +00:00
|
|
|
|
2003-01-16 11:02:49 +00:00
|
|
|
if (statusLabel != null)
|
|
|
|
statusLabel.setText("Error opening" + destination +
|
|
|
|
"see SFramework.log for more information");
|
2002-11-18 17:23:19 +00:00
|
|
|
|
2003-01-16 11:02:49 +00:00
|
|
|
return false;
|
|
|
|
}
|
2002-11-18 17:23:19 +00:00
|
|
|
|
2003-01-16 11:02:49 +00:00
|
|
|
if (entry.startsWith("/") == false)
|
|
|
|
entry = "/" + entry;
|
2002-11-18 17:23:19 +00:00
|
|
|
|
2003-01-16 11:02:49 +00:00
|
|
|
in = this.getClass().getResourceAsStream(entry);
|
|
|
|
if (in == null) {
|
|
|
|
System.err.println("File " + entry + " not found in jar file");
|
2002-11-18 17:23:19 +00:00
|
|
|
|
2003-01-16 11:02:49 +00:00
|
|
|
if (statusLabel != null)
|
|
|
|
statusLabel.setText("Failed extracting " + entry +
|
|
|
|
"see SFramework.log for more information");
|
2002-11-18 17:23:19 +00:00
|
|
|
|
2003-01-16 11:02:49 +00:00
|
|
|
return false;
|
2002-11-18 17:23:19 +00:00
|
|
|
}
|
|
|
|
|
2003-01-16 11:02:49 +00:00
|
|
|
try {
|
|
|
|
byte[] bytes = new byte[1024];
|
|
|
|
int len;
|
2002-11-18 17:23:19 +00:00
|
|
|
|
2003-01-16 11:02:49 +00:00
|
|
|
while ((len = in.read(bytes)) != -1)
|
|
|
|
out.write(bytes, 0, len);
|
2002-11-18 17:23:19 +00:00
|
|
|
}
|
2003-01-16 11:02:49 +00:00
|
|
|
catch (IOException ioe) {
|
|
|
|
System.err.println("Error writing " + destination + ": " +
|
|
|
|
ioe.getMessage());
|
|
|
|
|
|
|
|
if (statusLabel != null)
|
|
|
|
statusLabel.setText("Failed writing " + destination +
|
|
|
|
"see SFramework.log for more information");
|
|
|
|
return false;
|
2002-11-18 17:23:19 +00:00
|
|
|
}
|
2003-01-16 11:02:49 +00:00
|
|
|
finally {
|
|
|
|
try {
|
|
|
|
in.close();
|
|
|
|
out.close();
|
|
|
|
}
|
|
|
|
catch (IOException ioe) {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return true;
|
2002-11-18 17:23:19 +00:00
|
|
|
}
|
|
|
|
}
|