Skip to content

Commit

Permalink
lib: aapt: fix icon extract
Browse files Browse the repository at this point in the history
  • Loading branch information
hariimurti committed Jun 6, 2020
1 parent b33d659 commit 651dd30
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions ApkManager/Lib/Aapt.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,17 +25,17 @@ private static BitmapImage GetIconFrom(string pathApk, string pathIcon)
using (var stream = new MemoryStream())
using (var zip = ZipStorer.Open(pathApk, FileAccess.Read))
{
if (!pathIcon.EndsWith(".xml"))
{
var fileEntry = zip.ReadCentralDir().Where(f => f.FilenameInZip.Equals(pathIcon)).SingleOrDefault();
zip.ExtractFile(fileEntry, stream);
}
else
ZipStorer.ZipFileEntry fileEntry = null;
if (pathIcon.EndsWith(".xml"))
{
// try finding png icon from xml path
var icon = Path.GetFileNameWithoutExtension(pathIcon) + ".png";
var fileEntry = zip.ReadCentralDir().Where(f => f.FilenameInZip.EndsWith(icon) && f.FilenameInZip.Contains("hdpi")).LastOrDefault();
zip.ExtractFile(fileEntry, stream);
fileEntry = zip.ReadCentralDir().Where(f => f.FilenameInZip.EndsWith(icon) && f.FilenameInZip.Contains("hdpi")).LastOrDefault();
}
else fileEntry = zip.ReadCentralDir().Where(f => f.FilenameInZip.Equals(pathIcon)).FirstOrDefault();

if (fileEntry != null) zip.ExtractFile(fileEntry, stream);
else throw new Exception("there is no png icon in the apk");

var bitmap = new BitmapImage();
bitmap.BeginInit();
Expand Down

0 comments on commit 651dd30

Please sign in to comment.