cb.setBackground(Color.green);
}
// Extract JRE from installer's ZIP if present => gives feedback
if (installer.zip!=null) {
ZipFile zip = new ZipFile(installer.zip);
ZipEntry entry = zip.getEntry("jre");
// Overkill: entry exists and was checked by the installer main function
if (entry==null) throw new IOException("Internal Error!");
Enumeration enumEntries = zip.entries();
while (enumEntries.hasMoreElements()) {
entry = (ZipEntry)enumEntries.nextElement();
if (!entry.getName().startsWith("jre")) continue;
File f = new File(location, entry.getName());
if (entry.isDirectory()) {
f.mkdirs(); // TODO: handle installation failed
continue;
}
if (f.exists() && (!overwriteAll)) {
Object[] options = new Object[] {
Installer.resources.getString("yes"),
Installer.resources.getString("yesAll"),
Installer.resources.getString("no"),
Installer.resources.getString("cancel"),
};
int res = JOptionPane.showOptionDialog(
installer,
Installer.resources.getString("overwriteFile")+f.getAbsolutePath(),
Installer.resources.getString("overwriteTitle"),
JOptionPane.DEFAULT_OPTION,
JOptionPane.QUESTION_MESSAGE,
null,
options,
options[0]);
if (res==2) continue;
if ((res==JOptionPane.CLOSED_OPTION) || (res == 3)) break; // TODO: handle installation failed
if (res==1) overwriteAll = true;
}
long size = entry.getSize();
if (size!=-1) {
progress.setIndeterminate(false);
progress.setMinimum(0);
progress.setMaximum((int)size);
progress.setValue(0);
}
else progress.setIndeterminate(true);
progress.setString(Installer.resources.getString("installingJRE")+" : "+f.getAbsolutePath());
progress.setStringPainted(true);
FileOutputStream fos = new FileOutputStream(f);
InputStream zipStream = zip.getInputStream(entry);
int nread;
while ((nread = zipStream.read(data)) !=-1) {
fos.write(data,0,nread);
try {
SwingUtilities.invokeAndWait(new BarUpdater(nread));
} catch (InterruptedException e1) {
} catch (InvocationTargetException e1) {
}
}
fos.flush();
fos.close();
}
zip.close();
}
// Else copy file by file the JRE directory
else if (installer.jre!=null) {
progress.setMinimum(0);