diff --git a/ApkManager/Lib/Aapt.cs b/ApkManager/Lib/Aapt.cs index e39a16c..127a774 100644 --- a/ApkManager/Lib/Aapt.cs +++ b/ApkManager/Lib/Aapt.cs @@ -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();