private async void FetchInfos() { try { var pm = new PackageManager(); var packages = pm.FindPackagesForUser(""); string path = string.Empty; async Task <AppListEntry> GetAppListEntry() { foreach (var package in packages) { var result = await package.GetAppListEntriesAsync(); for (int i = 0; i < result.Count; i++) { var app = result[i]; if (app.AppUserModelId == AppId) { path = package.InstalledLocation.Path; currentAppIndex = i; return(app); } } } return(null); } sourceApp = await GetAppListEntry(); AppName = sourceApp.DisplayInfo.DisplayName; var logoPath = GetRefinedLogoPath(path); if (File.Exists(logoPath)) { MemoryStream memoryStream = new MemoryStream(); byte[] fileBytes = File.ReadAllBytes(logoPath); memoryStream.Write(fileBytes, 0, fileBytes.Length); memoryStream.Position = 0; Application.Current.Dispatcher.Invoke(() => { var image = new BitmapImage(); image.BeginInit(); image.StreamSource = memoryStream; image.EndInit(); AppImage = image; }, System.Windows.Threading.DispatcherPriority.Send); } InfoFetched?.Invoke(this, null); } catch { } }
private async void FetchInfos() { Bitmap bitmap = new Bitmap(16, 16); await Task.Run(() => { var processName = AppId.Substring(0, AppId.Length - 4); var processes = Process.GetProcessesByName(processName); if (processes?.Length > 0) { sourceProcess = processes[0]; try { AppName = sourceProcess.MainModule.FileVersionInfo.FileDescription; } catch { } try { var path = sourceProcess.MainModule.FileName; var ie = new IconExtractor(path); var icon = ie.GetIcon(0); bitmap = icon.ToBitmap(); } catch { } } }); if (bitmap != null) { Application.Current.Dispatcher.Invoke(() => { AppImage = Imaging.CreateBitmapSourceFromHBitmap(bitmap.GetHbitmap(), IntPtr.Zero, Int32Rect.Empty, BitmapSizeOptions.FromEmptyOptions()); }, System.Windows.Threading.DispatcherPriority.Send); } InfoFetched?.Invoke(this, null); }
public override async void FetchInfosAsync() { string appUserModelId = Data.AppUserModelId; string path = string.Empty; if (string.IsNullOrEmpty(Data.AppUserModelId) || string.IsNullOrWhiteSpace(Data.AppUserModelId)) { await Task.Run(() => { appUserModelId = GetAppUserModelIdForProcess(); }); } try { var pm = new PackageManager(); var packages = pm.FindPackagesForUser(string.Empty); async Task <AppListEntry> GetAppListEntry() { foreach (var package in packages) { var result = await package.GetAppListEntriesAsync(); for (int i = 0; i < result.Count; i++) { var app = result[i]; if (app.AppUserModelId == appUserModelId) { path = package.InstalledLocation.Path; currentAppIndex = i; return(app); } } } return(null); } sourceApp = await GetAppListEntry(); } catch { } if (sourceApp == null) { return; } try { DisplayName = sourceApp.DisplayInfo.DisplayName; } catch { } await Task.Run(() => { string logoPath = string.Empty; try { logoPath = GetRefinedLogoPath(path); } catch { } if (File.Exists(logoPath)) { MemoryStream memoryStream = new(); byte[] fileBytes = File.ReadAllBytes(logoPath); memoryStream.Write(fileBytes, 0, fileBytes.Length); memoryStream.Seek(0, SeekOrigin.Begin); LogoStream = memoryStream; } }); InfoFetched?.Invoke(this, null); }