Пример #1
0
        /// <summary>現ユーザーにインストールされているuwpアプリを列挙する</summary>
        /// <typeparam name="T">ロゴ画像の型</typeparam>
        /// <param name="stream2Logo">ストリームから画像を生成するデリゲート</param>
        /// <returns>アプリ情報</returns>
        public static async IAsyncEnumerable <AppListEntryEx <T> > EnumerateAsync <T>(Func <Stream, string, T> stream2Logo) where T : class
        {
            // AppListEntryが複数あった場合 同一PackageがAppListEntry分列挙される模様
            // カレンダーとメール等
            // アプリ単位で列挙されたほうが嬉しいのでAppListEntry単位にしている
            var packages = new PackageManager().FindPackagesForUser("").Distinct();

            foreach (var package in packages)
            {
                var ex = new PackageEx(package);

                foreach (var entry in await package.GetAppListEntriesAsync())
                {
                    AppListEntryEx <T> result;
                    try
                    {
                        result = await AppListEntryEx <T> .CreateInstanceAsync(ex, entry, stream2Logo);
                    }
                    catch
                    {
                        continue;
                    }

                    yield return(result);
                }
            }
        }
Пример #2
0
        internal static async Task <AppListEntryEx <T> > CreateInstanceAsync(PackageEx package, AppListEntry appListEntry, Func <Stream, string, T> stream2Logo)
        {
            var entry = new AppListEntryEx <T>(package, appListEntry);
            await entry.InitializeAsync(stream2Logo);

            return(entry);
        }
Пример #3
0
        private (string?backgroundColor, string?square44x44Logo) GetVisualElements(PackageEx package, string appId)
        {
            if (package.InstalledLocation != null)
            {
                var manifestPath = Path.Combine(package.InstalledLocation, "AppxManifest.xml");
                var xml          = XDocument.Load(manifestPath);

                var applications    = xml.ElementAnyNS("Package")?.ElementAnyNS("Applications");
                var applicationList = applications?.ElementsAnyNS("Application");
                if (applicationList != null)
                {
                    var e  = applicationList.FirstOrDefault(x => x.AttributeAnyNS("Id")?.Value == appId);
                    var bk = e.ElementAnyNS("VisualElements")?.AttributeAnyNS("BackgroundColor")?.Value;
                    var sl = e.ElementAnyNS("VisualElements")?.AttributeAnyNS("Square44x44Logo")?.Value;
                    return(bk, sl);
                }
            }

            return(null, null);
        }
Пример #4
0
 private AppListEntryEx(PackageEx package, AppListEntry appListEntry)
 {
     Package           = package;
     AppUserModelId    = appListEntry.AppUserModelId;
     this.appListEntry = appListEntry;
 }