B4A Library SDZipLibrary improvement

Thanks to @Star-Dust, I have been able to see contain of apk file and moreover to extract files ! I improved a little his code in order to :
  1. Get the possible error of zip/unzip instructions into BA log,
  2. Add the ability to extract a selection of files without creating subfolders,
  3. Suppress the WRITE_EXTERNAL_STORAGE permission which is not usefull for non image files.
Here is the new version of the class.

Getting the error in BA log:
...
} catch(Exception e) {
    ba.Log(e.toString());
    ba.raiseEvent(null, "zip_error");
}
...

Add selection in unzip method:
public void unZipDecompress(String zipFile, String outputFolder, String fileSel) {
            ...
            String fileEntry    = ze.getName();
            String fileName     = fileEntry;
            // Don't create sub folder(s) when file(s) selection
            if (fileSel!="" && fileName.contains("/")) fileName = fileName.substring(fileName.lastIndexOf("/")+1);
            File newFile         = new File(outputFolder + File.separator + fileName);
            new File(newFile.getParent()).mkdirs();
            if (!fileEntry.endsWith("/") && fileEntry.contains(fileSel)) {
                ...
 

Attachments

  • ZipLibrary.bas
    3.9 KB · Views: 18
Top