public async Task LoadApps() { Windows.Management.Deployment.PackageManager packageManager = new Windows.Management.Deployment.PackageManager(); IEnumerable <Windows.ApplicationModel.Package> packages; if (LoadLegacyAppsToo) { packages = (IEnumerable <Windows.ApplicationModel.Package>)packageManager.FindPackagesForUserWithPackageTypes("", PackageTypes.Bundle | PackageTypes.Framework | PackageTypes.Main | PackageTypes.None | PackageTypes.Resource | PackageTypes.Xap); } else { packages = (IEnumerable <Windows.ApplicationModel.Package>)packageManager.FindPackagesForUser(""); } int count = packages.Count(); int progress = 0; StorageFolder localCacheFolder = ApplicationData.Current.LocalCacheFolder; if ((await localCacheFolder.TryGetItemAsync("Logos")) == null) { await localCacheFolder.CreateFolderAsync("Logos"); } StorageFolder logosFolder = await localCacheFolder.GetFolderAsync("Logos"); HashSet <string> existingAppFamilyNames = new HashSet <string>(); foreach (var item in packages) { System.Diagnostics.Debug.WriteLine(progress); AppData appD = await LoadModernAndLegacyAppData(item, logosFolder); if ((appD != null) && (appD.PackageId != "")) { appsData.AddSorted(appD, new AppDataNameComparer()); familyNameAppData.Add(appD.FamilyName, appD); existingAppFamilyNames.Add(appD.FamilyName); } else if (appD != null) { existingAppFamilyNames.Add(appD.FamilyName); } progress++; OnLoadingProgress(new LoadingEventArgs(progress, count)); } //Remove apps that are no longer installed on device from cache. List <AppData> removedApps = new List <AppData>(); foreach (var item in appsData) { if (!existingAppFamilyNames.Contains(item.FamilyName)) { removedApps.Add(item); } } foreach (var item in removedApps) { familyNameAppData.Remove(item.FamilyName); appsData.Remove(item); } SaveAppList(); OnLoadCompleted(); }
private async Task <AppData> LoadModernAndLegacyAppData(Windows.ApplicationModel.Package item, StorageFolder saveLogoLocation) { AppData data = new AppData(); try { data.FamilyName = item.Id.FamilyName; if (familyNameAppData.ContainsKey(data.FamilyName)) { familyNameAppData[data.FamilyName].PackageId = item.Id.FullName; //Refresh package id. data.PackageId = ""; return(data); } // // Сводка: // Перечисляет упакованные приложения на устройстве. Возвращаются только упакованные // приложения, зарегистрированные для текущего пользователя. // // Возврат: // Список упакованных приложений вместе с их отображаемым именем, описанием и логотипом. IReadOnlyList <Windows.ApplicationModel.Core.AppListEntry> x = await item.GetAppListEntriesAsync(); if ((x == null) || (x.Count == 0)) { return(null); } data.DisplayName = (x.First().DisplayInfo.DisplayName); data.PackageId = item.Id.FullName; data.PackageRootFolder = item.InstalledLocation.Path; data.IsLegacyApp = data.PackageRootFolder[data.PackageRootFolder.Length - 1] == '}'; data.PackageDataFolder = await GetDataFolder(data); if ((await saveLogoLocation.TryGetItemAsync(data.FamilyName + ".png")) == null) { WriteableBitmap bmp = null; try { var stream = await x.First().DisplayInfo.GetLogo(new Size(50, 50)).OpenReadAsync(); BitmapDecoder decoder = await BitmapDecoder.CreateAsync(stream); bmp = new WriteableBitmap((int)decoder.PixelWidth, (int)decoder.PixelHeight); bmp.SetSource(stream); //await bmp.SaveAsync(saveLogoLocation, data.FamilyName + ".png"); } catch { } } data.LogoPath = System.IO.Path.Combine(saveLogoLocation.Path, data.FamilyName + ".png"); try { if (data.IsLegacyApp) { data.Publisher = await TryGetPublisherName_Legacy(item); } else { data.Publisher = await TryGetPublisherName_Modern(item); } } catch { } return(data); } catch { } return(null); }