Exemplo n.º 1
0
        async Task UwpScanAddLibrary()
        {
            try
            {
                //Get all the installed uwp games
                IEnumerable <GameListEntry> uwpGameList = (await GameList.FindAllAsync()).Where(x => x.Category == GameListCategory.ConfirmedBySystem);
                if (!uwpGameList.Any())
                {
                    Debug.WriteLine("No installed uwp games found to list.");
                    return;
                }

                //Add all the installed uwp games
                foreach (GameListEntry uwpGame in uwpGameList)
                {
                    try
                    {
                        //Get and check uwp application FamilyName
                        string appFamilyName = uwpGame.Properties.FirstOrDefault(x => x.Key == "PackageFamilyName").Value.ToString();
                        if (string.IsNullOrWhiteSpace(appFamilyName))
                        {
                            continue;
                        }

                        //Get uwp application package
                        Package appPackage = UwpGetAppPackageByFamilyName(appFamilyName);

                        //Get detailed application information
                        AppxDetails appxDetails = UwpGetAppxDetailsFromAppPackage(appPackage);

                        //Check if executable name is valid
                        if (string.IsNullOrWhiteSpace(appxDetails.ExecutableName))
                        {
                            continue;
                        }

                        //Check if application name is valid
                        if (string.IsNullOrWhiteSpace(appxDetails.DisplayName) || appxDetails.DisplayName.StartsWith("ms-resource"))
                        {
                            continue;
                        }

                        await UwpAddApplication(appPackage, appxDetails);
                    }
                    catch { }
                }
            }
            catch (Exception ex)
            {
                Debug.WriteLine("Failed adding uwp games library: " + ex.Message);
            }
        }