Skip to content
Snippets Groups Projects
Commit e34d0310 authored by Christophe Geuzaine's avatar Christophe Geuzaine
Browse files

more robust unzip (previous version would fail with directories containing only subdirs)

parent ac730ddf
No related branches found
No related tags found
No related merge requests found
...@@ -73,36 +73,35 @@ public class SplashScreen extends Activity{ ...@@ -73,36 +73,35 @@ public class SplashScreen extends Activity{
/** /**
* Uncompress zip archive into the files directory of the application. * Uncompress zip archive into the files directory of the application.
*/ */
private void ImportZipArchive(InputStream stream) private boolean ImportZipArchive(InputStream stream)
{ {
try { try {
ZipInputStream zipStream = new ZipInputStream(stream); String path = this.getFilesDir().getAbsolutePath() + File.separator;
ZipEntry entry; ZipInputStream zis = new ZipInputStream(stream);
while ((entry = zipStream.getNextEntry()) != null) { byte[] buffer = new byte[1024];
String name = entry.getName(); ZipEntry ze;
FileOutputStream outputStream; while ((ze = zis.getNextEntry()) != null) {
if(name.charAt(name.length()-1) == '/') { String filename = ze.getName();
if (ze.isDirectory()) {
File fmd = new File(path + filename);
fmd.mkdirs();
continue; continue;
} }
else if(name.lastIndexOf("/") > 0) { FileOutputStream fout = new FileOutputStream(path + filename);
File document = this.getFilesDir(); int count;
File currentDirectory = new File(document, name.substring(0, name.lastIndexOf("/"))); while ((count = zis.read(buffer)) != -1) {
currentDirectory.mkdir(); fout.write(buffer, 0, count);
File currentFile = new File(currentDirectory, name.substring(name.lastIndexOf("/")+1));
outputStream = new FileOutputStream(currentFile);
} }
else { fout.close();
outputStream = openFileOutput(name, Context.MODE_PRIVATE); zis.closeEntry();
} }
byte[] buffer = new byte[2048]; zis.close();
for (int i = zipStream.read(buffer, 0, buffer.length); i > 0;
i = zipStream.read(buffer, 0, buffer.length))
outputStream.write(buffer, 0, i);
} }
zipStream.close(); catch(IOException e) {
} e.printStackTrace();
catch (IOException e1) { return false;
e1.printStackTrace();
} }
return true;
} }
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment