Пример #1
0
        public static IEnumerable <PackageInfoEx> ToPackageInfoEx(
            IEnumerable <Windows.ApplicationModel.Package> packages,
            bool processLogo = true)
        {
            //var packageTest = packages.FirstOrDefault(p => p.Id.Name.ToLower().Contains("reader"));

            //            if (packageTest != null)
            //            {
            //                var debugOut = "Blah!";
            //            }

            foreach (var package in packages)
            {
                // We don't care about framework
                // packages, these packages are libraries
                // not apps
                if (package.IsFramework)
                {
                    continue;
                }

                string installedLocationPath = null;

                try
                {
                    installedLocationPath = package.InstalledLocation.Path;
                }
                catch (Exception ex)
                {
                    Debug.WriteLine("Look up of install location failed. " + package.Id.Name);
                    continue;
                }

                var manifestPath = Path.Combine(installedLocationPath, "AppxManifest.xml");
                var manifestInfo = GetAppInfoFromManifest(manifestPath);

                if (manifestInfo.Apps != null)
                {
                    // Configured to not display on start menu
                    // so we skip theses
                    var unlistedApps = manifestInfo.Apps.Where(p => p?.AppListEntry == "none").ToList();
                    var listedApps   = manifestInfo.Apps.Except(unlistedApps);

                    foreach (var application in listedApps)
                    {
                        var packageInfoEx = new PackageInfoEx();

                        var fullName = package.Id.FullName;

                        var displayName = NativeApiHelper.LoadResourceString(fullName, application.DisplayName);

                        // Can't get display name, probably not
                        // an app we care about
                        if (string.IsNullOrWhiteSpace(displayName))
                        {
                            Debug.WriteLine(manifestPath);
                            continue;
                        }

                        packageInfoEx.DisplayName = displayName;

                        var description = NativeApiHelper.LoadResourceString(fullName, application.Description);

                        if (!string.IsNullOrWhiteSpace(description))
                        {
                            packageInfoEx.Description = description;
                        }

                        var logoPath = GetBestLogoPath(manifestInfo, application, installedLocationPath);
                        packageInfoEx.FullLogoPath = logoPath;
                        packageInfoEx.AppInfo      = application;

                        //                        package.Description = package.GetPropertyStringValue("Description");
                        //                        package.DisplayName = package.GetPropertyStringValue("DisplayName");
                        //                        package.Logo = package.GetPropertyStringValue("Logo");
                        //                        package.PublisherDisplayName = package.GetPropertyStringValue("PublisherDisplayName");
                        //                        package.IsFramework = package.GetPropertyBoolValue("Framework");

                        packageInfoEx.FullName = fullName;
                        packageInfoEx.Name     = package.Id.Name;

                        yield return(packageInfoEx);
                    }
                }
                else
                {
                    Debug.WriteLine("Manifest has no apps defined: " + manifestPath);
                }
            }
        }
Пример #2
0
 public string LoadResourceString(string resource)
 {
     return(NativeApiHelper.LoadResourceString(FullName, resource));
 }