示例#1
0
        public string GetStringValue(string name)
        {
            if (name == null)
            {
                throw new ArgumentNullException("name");
            }

            return(NativeApiHelper.GetStringValue(_app, name));
        }
示例#2
0
        public bool GetPropertyBoolValue(string name)
        {
            if (name == null)
            {
                throw new ArgumentNullException("name");
            }

            return(NativeApiHelper.GetBoolValue(Properties, name));
        }
示例#3
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);
                }
            }
        }
示例#4
0
        private static ManifestInfo GetAppInfoFromManifest(string manifestFilePath)
        {
            if (File.Exists(manifestFilePath))
            {
                var factory = (NativeApiHelper.IAppxFactory) new NativeApiHelper.AppxFactory();

                IStream manifestStream;

                NativeApiHelper.SHCreateStreamOnFileEx(manifestFilePath, STGM_SHARE_DENY_NONE, 0, false, IntPtr.Zero, out manifestStream);

                if (manifestStream != null)
                {
                    var manifestInfo = new ManifestInfo();

                    var reader     = factory.CreateManifestReader(manifestStream);
                    var properties = reader.GetProperties();

                    manifestInfo.Properties = properties;

                    var apps = reader.GetApplications();

                    while (apps.GetHasCurrent())
                    {
                        var app = apps.GetCurrent();
                        var manifestApplication = new ManifestApplication(app);

                        manifestApplication.AppListEntry      = NativeApiHelper.GetStringValue(app, "AppListEntry");
                        manifestApplication.Description       = NativeApiHelper.GetStringValue(app, "Description");
                        manifestApplication.DisplayName       = NativeApiHelper.GetStringValue(app, "DisplayName");
                        manifestApplication.EntryPoint        = NativeApiHelper.GetStringValue(app, "EntryPoint");
                        manifestApplication.Executable        = NativeApiHelper.GetStringValue(app, "Executable");
                        manifestApplication.Id                = NativeApiHelper.GetStringValue(app, "Id");
                        manifestApplication.Logo              = NativeApiHelper.GetStringValue(app, "Logo");
                        manifestApplication.SmallLogo         = NativeApiHelper.GetStringValue(app, "SmallLogo");
                        manifestApplication.StartPage         = NativeApiHelper.GetStringValue(app, "StartPage");
                        manifestApplication.Square150x150Logo = NativeApiHelper.GetStringValue(app, "Square150x150Logo");
                        manifestApplication.Square30x30Logo   = NativeApiHelper.GetStringValue(app, "Square30x30Logo");
                        manifestApplication.BackgroundColor   = NativeApiHelper.GetStringValue(app, "BackgroundColor");
                        manifestApplication.ForegroundText    = NativeApiHelper.GetStringValue(app, "ForegroundText");
                        manifestApplication.WideLogo          = NativeApiHelper.GetStringValue(app, "WideLogo");
                        manifestApplication.Wide310x310Logo   = NativeApiHelper.GetStringValue(app, "Wide310x310Logo");
                        manifestApplication.ShortName         = NativeApiHelper.GetStringValue(app, "ShortName");
                        manifestApplication.Square310x310Logo = NativeApiHelper.GetStringValue(app, "Square310x310Logo");
                        manifestApplication.Square70x70Logo   = NativeApiHelper.GetStringValue(app, "Square70x70Logo");
                        manifestApplication.MinWidth          = NativeApiHelper.GetStringValue(app, "MinWidth");
                        manifestInfo.Apps.Add(manifestApplication);
                        apps.MoveNext();
                    }
                    Marshal.ReleaseComObject(manifestStream);

                    return(manifestInfo);
                }
                else
                {
                    Debug.WriteLine("Call to SHCreateStreamOnFileEx failed on : " + manifestFilePath);
                }
            }
            else
            {
                Debug.WriteLine("Manifest File Missing: " + manifestFilePath);
            }

            return(null);
        }
示例#5
0
 public string LoadResourceString(string resource)
 {
     return(NativeApiHelper.LoadResourceString(FullName, resource));
 }