Ian Vink
Ian Vink

Reputation: 68790

MonoDroid: Unzipping an Asset

MonoDroid appears to be missing the Android.Uitl.Zip namespace.

Is there a way with Mono for Android to unzip an asset to the documents folder?

Here's how in Java: http://www.jondev.net/articles/Unzipping_Files_with_Android_(Programmatically)

Upvotes: 0

Views: 868

Answers (1)

Ash
Ash

Reputation: 26

I was trying to do the same thing and had to resort to a third-party library. Others have suggested SharpZipLib, but the license might be a problem if you're not working on an open-source project. DotNetZip is also open-source but it has a more permissive license, and I was able to use the source code in Mono for Android without too many headaches. I've only used it to extract zips so far, so you may have to do some debugging if you want to use any of the other functionality.

Here's the procedure I used:

  1. Grab the source code from http://dotnetzip.codeplex.com/SourceControl/list/changesets.

  2. Copy the Zip, Zlib and CommonSrc directories into your Android Mono project. Only copy the .cs files and don't copy any of the subdirectories.

  3. Delete the ZipFile.SaveSelfExtractor.cs file from the Zip directory.

  4. Comment out this line from the ValidateOutput function in ZipEntry.Extract.cs.

    outFileName = outFileName.Replace("/","\\");
    

Once I did all that, extracting was pretty simple:

using Ionic.Zip;
Zipfile zip = ZipFile.Read(archivepath);
zip.ExtractAll(extractpath);

Upvotes: 1

Related Questions