Skip to content

Commit 64b8a32

Browse files
committed
clean up utils a little and throw exception to caller in unzip()
1 parent f520563 commit 64b8a32

File tree

2 files changed

+27
-26
lines changed

2 files changed

+27
-26
lines changed

app/src/processing/app/Util.java

Lines changed: 21 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -464,7 +464,7 @@ static void listFilesImpl(File folder, boolean relative,
464464

465465
/**
466466
* @param folder source folder to search
467-
* @return a list of .jar and .zip files in that folder
467+
* @return an array of .jar and .zip files in that folder
468468
*/
469469
static public File[] listJarFiles(File folder) {
470470
return folder.listFiles((dir, name) ->
@@ -585,9 +585,9 @@ static private void packageListFromZip(String filename, StringList list) {
585585
if (!entry.isDirectory()) {
586586
String name = entry.getName();
587587

588-
// Avoid META-INF because some jokers but .class files in there
588+
// Avoid META-INF because some jokers put .class files in there
589589
// https://github.com/processing/processing/issues/5778
590-
if (name.endsWith(".class") && !name.startsWith("META-INF/")) {
590+
if (name.endsWith(".class") && !name.contains("META-INF/")) {
591591
int slash = name.lastIndexOf('/');
592592
if (slash != -1) {
593593
String packageName = name.substring(0, slash);
@@ -640,31 +640,27 @@ static private void packageListFromFolder(File dir, String sofar,
640640
* Extract the contents of a .zip archive into a folder.
641641
* Ignores (does not extract) any __MACOSX files from macOS archives.
642642
*/
643-
static public void unzip(File zipFile, File dest) {
644-
try {
645-
FileInputStream fis = new FileInputStream(zipFile);
646-
CheckedInputStream checksum = new CheckedInputStream(fis, new Adler32());
647-
ZipInputStream zis = new ZipInputStream(new BufferedInputStream(checksum));
648-
ZipEntry entry;
649-
while ((entry = zis.getNextEntry()) != null) {
650-
final String name = entry.getName();
651-
if (!name.startsWith(("__MACOSX"))) {
652-
File currentFile = new File(dest, name);
653-
if (entry.isDirectory()) {
654-
currentFile.mkdirs();
655-
} else {
656-
File parentDir = currentFile.getParentFile();
657-
// Sometimes the directory entries aren't already created
658-
if (!parentDir.exists()) {
659-
parentDir.mkdirs();
660-
}
661-
currentFile.createNewFile();
662-
unzipEntry(zis, currentFile);
643+
static public void unzip(File zipFile, File dest) throws IOException {
644+
FileInputStream fis = new FileInputStream(zipFile);
645+
CheckedInputStream checksum = new CheckedInputStream(fis, new Adler32());
646+
ZipInputStream zis = new ZipInputStream(new BufferedInputStream(checksum));
647+
ZipEntry entry;
648+
while ((entry = zis.getNextEntry()) != null) {
649+
final String name = entry.getName();
650+
if (!name.startsWith(("__MACOSX"))) {
651+
File currentFile = new File(dest, name);
652+
if (entry.isDirectory()) {
653+
currentFile.mkdirs();
654+
} else {
655+
File parentDir = currentFile.getParentFile();
656+
// Sometimes the directory entries aren't already created
657+
if (!parentDir.exists()) {
658+
parentDir.mkdirs();
663659
}
660+
currentFile.createNewFile();
661+
unzipEntry(zis, currentFile);
664662
}
665663
}
666-
} catch (Exception e) {
667-
e.printStackTrace();
668664
}
669665
}
670666

app/src/processing/app/contrib/AvailableContribution.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,12 @@ public LocalContribution install(Base base, File contribArchive,
159159
}
160160
return null;
161161
}
162-
Util.unzip(contribArchive, tempFolder);
162+
try {
163+
Util.unzip(contribArchive, tempFolder);
164+
} catch (IOException e) {
165+
e.printStackTrace();
166+
return null;
167+
}
163168

164169
LocalContribution installedContrib = null;
165170
// Find the first legitimate folder in what we just unzipped

0 commit comments

Comments
 (0)