totalSizeExtract = 0;
int jarNum = i - (urlList.length - nativeJarCount); // used for progressbar
// calculate the size of the files to extract for progress bar
while (entities.hasMoreElements()) {
JarEntry entry = (JarEntry) entities.nextElement();
// skip directories and anything in directories
// conveniently ignores the manifest
if (entry.isDirectory() || entry.getName().indexOf('/') != -1) {
continue;
}
totalSizeExtract += entry.getSize();
}
currentSizeExtract = 0;
// reset point to begining by getting list of file again
entities = jarFile.entries();
// extract all files from the jar
while (entities.hasMoreElements()) {
JarEntry entry = (JarEntry) entities.nextElement();
// skip directories and anything in directories
// conveniently ignores the manifest
if (entry.isDirectory() || entry.getName().indexOf('/') != -1) {
continue;
}
// check if native file already exists if so delete it to make room for new one
// useful when using the reload button on the browser
File f = new File(path + "natives" + File.separator + entry.getName());
if (f.exists()) {
if (!f.delete()) {
continue; // unable to delete file, it is in use, skip extracting it
}
}
debug_sleep(1000);
InputStream in = jarFile.getInputStream(jarFile.getEntry(entry.getName()));
OutputStream out = new FileOutputStream(path + "natives" + File.separator + entry.getName());
int bufferSize;
byte buffer[] = new byte[65536];
while ((bufferSize = in.read(buffer, 0, buffer.length)) != -1) {
debug_sleep(10);
out.write(buffer, 0, bufferSize);
currentSizeExtract += bufferSize;
// update progress bar
percentage = 65 + (int)(percentageParts * (jarNum + currentSizeExtract/(float)totalSizeExtract));
subtaskMessage = "Extracting: " + entry.getName() + " " + ((currentSizeExtract * 100) / totalSizeExtract) + "%";
}
// validate if the certificate for native file is correct
validateCertificateChain(certificate, entry.getCertificates());
in.close();
out.close();
}
subtaskMessage = "";