clean up utils a little and throw exception to caller in unzip()

This commit is contained in:
Ben Fry
2023-01-22 10:37:17 -05:00
parent f5205636b5
commit 64b8a32bdc
2 changed files with 27 additions and 26 deletions

View File

@@ -464,7 +464,7 @@ public class Util {
/**
* @param folder source folder to search
* @return a list of .jar and .zip files in that folder
* @return an array of .jar and .zip files in that folder
*/
static public File[] listJarFiles(File folder) {
return folder.listFiles((dir, name) ->
@@ -585,9 +585,9 @@ public class Util {
if (!entry.isDirectory()) {
String name = entry.getName();
// Avoid META-INF because some jokers but .class files in there
// Avoid META-INF because some jokers put .class files in there
// https://github.com/processing/processing/issues/5778
if (name.endsWith(".class") && !name.startsWith("META-INF/")) {
if (name.endsWith(".class") && !name.contains("META-INF/")) {
int slash = name.lastIndexOf('/');
if (slash != -1) {
String packageName = name.substring(0, slash);
@@ -640,31 +640,27 @@ public class Util {
* Extract the contents of a .zip archive into a folder.
* Ignores (does not extract) any __MACOSX files from macOS archives.
*/
static public void unzip(File zipFile, File dest) {
try {
FileInputStream fis = new FileInputStream(zipFile);
CheckedInputStream checksum = new CheckedInputStream(fis, new Adler32());
ZipInputStream zis = new ZipInputStream(new BufferedInputStream(checksum));
ZipEntry entry;
while ((entry = zis.getNextEntry()) != null) {
final String name = entry.getName();
if (!name.startsWith(("__MACOSX"))) {
File currentFile = new File(dest, name);
if (entry.isDirectory()) {
currentFile.mkdirs();
} else {
File parentDir = currentFile.getParentFile();
// Sometimes the directory entries aren't already created
if (!parentDir.exists()) {
parentDir.mkdirs();
}
currentFile.createNewFile();
unzipEntry(zis, currentFile);
static public void unzip(File zipFile, File dest) throws IOException {
FileInputStream fis = new FileInputStream(zipFile);
CheckedInputStream checksum = new CheckedInputStream(fis, new Adler32());
ZipInputStream zis = new ZipInputStream(new BufferedInputStream(checksum));
ZipEntry entry;
while ((entry = zis.getNextEntry()) != null) {
final String name = entry.getName();
if (!name.startsWith(("__MACOSX"))) {
File currentFile = new File(dest, name);
if (entry.isDirectory()) {
currentFile.mkdirs();
} else {
File parentDir = currentFile.getParentFile();
// Sometimes the directory entries aren't already created
if (!parentDir.exists()) {
parentDir.mkdirs();
}
currentFile.createNewFile();
unzipEntry(zis, currentFile);
}
}
} catch (Exception e) {
e.printStackTrace();
}
}

View File

@@ -159,7 +159,12 @@ public class AvailableContribution extends Contribution {
}
return null;
}
Util.unzip(contribArchive, tempFolder);
try {
Util.unzip(contribArchive, tempFolder);
} catch (IOException e) {
e.printStackTrace();
return null;
}
LocalContribution installedContrib = null;
// Find the first legitimate folder in what we just unzipped