public PackageInfoDetailWindow(PackageInfo packageInfo)
        {
            InitializeComponent();

            List<DataVO> dataList = new List<DataVO>();
            foreach (PropertyInfo propety in typeof(PackageInfo).GetProperties()) {
                object obj = propety.GetValue(packageInfo, null);
                string value = obj == null ? string.Empty : obj.ToString();
                dataList.Add(new DataVO
                {
                    Key = propety.Name,
                    Value = value
                });
            };

            TextBlockTitle.Text = packageInfo.RecommendedFileName;
            ListViewOutput.ItemsSource = dataList;

            ListViewOutput.Focus();
        }
Beispiel #2
0
        public PackageInfo GetPackageInfo(string ipaFilePath)
        {
            string payloadName;
            PackageInfo packageInfo = null;

            try {
                using (ZipFile zip = ZipFile.Read(ipaFilePath, new ReadOptions { Encoding = Encoding.UTF8 })) {
                    ZipEntry infoPlistZipEntry = zip.Entries.Where(e => e.FileName.EndsWith(@".app/Info.plist")).FirstOrDefault();

                    // Info.plist
                    if (infoPlistZipEntry != null) {
                        // zipentry filename example: "Payload/GoodReaderIPad.app/Info.plist"
                        payloadName = infoPlistZipEntry.FileName.Substring(8, infoPlistZipEntry.FileName.IndexOf(@".app/Info.plist") - 8);
                        //payloadName = infoPlistZipEntry.FileName;

                        using (var ms = new MemoryStream()) {
                            infoPlistZipEntry.Extract(ms);

                            ms.Seek(0, SeekOrigin.Begin);
                            plistType plType = Plist.getPlistType(ms);

                            ms.Seek(0, SeekOrigin.Begin);
                            object results = Plist.readPlist(ms, plType);

                            if (results != null) {
                                Dictionary<string, object> dict = results as Dictionary<string, object>;

                                string identifier = ReadPropertyAsString(dict, BUNDLE_IDENTIFIER);

                                // icon file
                                CacheIcon(dict, zip, identifier);

                                packageInfo = new PackageInfo
                                {
                                    OriginalFile = ipaFilePath,
                                    DisplayName = ReadPropertyAsString(dict, BUNDLE_DISPLAY_NAME),
                                    PayloadName = payloadName,
                                    Identifier = identifier,
                                    ShortVersion = ReadPropertyAsString(dict, BUNDLE_SHORT_VERSION_STRING),
                                    Version = ReadPropertyAsString(dict, BUNDLE_VERSION),
                                    Name = ReadPropertyAsString(dict, BUNDLE_NAME),
                                    Excutbale = ReadPropertyAsString(dict, BUNDLE_EXECUTABLE),
                                    MinimumOsVersion = ReadPropertyAsString(dict, BUNDLE_MININUM_OS_VERSION),
                                    AppType = ReadDeviceFamily(dict),
                                    IsProcessed = true
                                };
                            }
                        }
                    }

                    if (packageInfo != null) {
                        // iTunesMetadata.plist
                        ZipEntry metaPlistZipEntry = zip.Entries.Where(e => e.FileName == "iTunesMetadata.plist").FirstOrDefault();
                        if (metaPlistZipEntry != null) {
                            try {
                                // initialize its id to -1, even if the later processing fails to find the id,
                                // this will indicate iTunesMetadata.plist is found and processed
                                packageInfo.ItunesId = -1;
                                using (var ms = new MemoryStream()) {
                                    metaPlistZipEntry.Extract(ms);

                                    ms.Seek(0, SeekOrigin.Begin);
                                    plistType plType = Plist.getPlistType(ms);

                                    ms.Seek(0, SeekOrigin.Begin);
                                    object results = Plist.readPlist(ms, plType);

                                    if (results != null) {
                                        Dictionary<string, object> dict = results as Dictionary<string, object>;
                                        packageInfo.ItunesId = ReadPropertyAsInt(dict, METADATA_ITEM_ID);
                                    }
                                }
                            }
                            catch (Exception e) {
                                // TODO
                            }
                        }

                        // iTunesArtwork
                        ZipEntry itunesArtworkZipEntry = zip.Entries.Where(e => e.FileName == "iTunesArtwork").FirstOrDefault();
                        if (itunesArtworkZipEntry != null) {
                            try {
                                string localArtworkFile = string.Format(@"{0}\{1}_artwork.png", CACHE_DIR, packageInfo.Identifier);
                                string localArtworkFileSmall = string.Format(@"{0}\{1}_artwork_small.png", CACHE_DIR, packageInfo.Identifier);
                                if (!File.Exists(localArtworkFile)) {
                                    using (var fs = new FileStream(localArtworkFile, FileMode.Create)) {
                                        itunesArtworkZipEntry.Extract(fs);
                                    }

                                    using (var source = Image.FromFile(localArtworkFile)) {
                                        var bmp = new Bitmap(THUMBNAIL_SIZE, THUMBNAIL_SIZE);
                                        using (var g = Graphics.FromImage(bmp)) {
                                            g.DrawImage(source, new Rectangle(0, 0, THUMBNAIL_SIZE, THUMBNAIL_SIZE));
                                            g.Save();
                                        }
                                        bmp.Save(localArtworkFileSmall);
                                    }

                                    //PNGConvertor.Convert(localIconFile);
                                }
                            }
                            catch (Exception e) {
                                // TODO
                            }
                        }

                    }
                }
            }
            catch (Exception e) {
                if (packageInfo == null) {
                    packageInfo = new PackageInfo
                    {
                        OriginalFile = ipaFilePath,
                        IsProcessed = false,
                        ProcessingRemarks = e.Message
                    };
                }
            }

            return packageInfo;
        }
Beispiel #3
0
        private void Analyze()
        {
            SimpleFileLogger logger = GetAnalyzeLogger();

            // create cache dir if not available
            if (Directory.Exists(PackageService.CACHE_DIR)) {
                Directory.Delete(PackageService.CACHE_DIR, true);
            }
            Directory.CreateDirectory(PackageService.CACHE_DIR);

            AnalyzedCount = 0;
            AppTypeCountUniversal = 0;
            AppTypeCountIphone = 0;
            AppTypeCountIpad = 0;
            AppTypeCountUnknown = 0;

            Analyzed = false;

            string[] ipaFiles = Directory.GetFiles(SourceDir, "*.ipa", IsSourceDirRecursive ? SearchOption.AllDirectories : SearchOption.TopDirectoryOnly);

            TotalFilesCount = ipaFiles.Count();
            int counter = 0;

            foreach (string file in ipaFiles) {
                if (_stopAnalyzing) {
                    _stopAnalyzing = false;
                    break;
                }

                PackageInfo pkgInfo = null;
                _analyzeBgWorker.ReportProgress((counter++ * 100) / TotalFilesCount, file);
                try {
                    pkgInfo = PackageService.Instance.GetPackageInfo(file);
                    logger.LogInfo("analyzed " + file + ", recommeded name: " + pkgInfo.RecommendedFileName);
                    _analyzeBgWorker.ReportProgress((counter * 100) / TotalFilesCount, pkgInfo);
                }
                catch (Exception e) {
                    logger.LogError("failed to analyze " + file + ". " + e);
                    pkgInfo = new PackageInfo
                    {
                        OriginalFile = file,
                        IsProcessed = false,
                        ProcessingRemarks = e.Message
                    };
                    _analyzeBgWorker.ReportProgress((counter * 100) / TotalFilesCount, pkgInfo);
                }
            }

            Analyzed = true;
        }