public GameMetadata UpdateGameWithMetadata(Game game) { var metadata = new GameMetadata(); var program = Twitch.GetUninstallRecord(game.GameId); if (program == null) { return(metadata); } if (!string.IsNullOrEmpty(program.DisplayIcon) && File.Exists(program.DisplayIcon)) { var iconPath = program.DisplayIcon; var iconFile = Path.GetFileName(iconPath); if (iconPath.EndsWith("ico", StringComparison.OrdinalIgnoreCase)) { var data = File.ReadAllBytes(iconPath); metadata.Icon = new MetadataFile(iconFile, data); } else { var exeIcon = IconExtension.ExtractIconFromExe(iconPath, true); if (exeIcon != null) { var iconName = Guid.NewGuid() + ".png"; metadata.Icon = new MetadataFile(iconName, exeIcon.ToByteArray(System.Drawing.Imaging.ImageFormat.Png)); } } } game.Name = StringExtensions.NormalizeGameName(program.DisplayName); return(metadata); }
public OriginGameMetadata UpdateGameWithMetadata(Game game) { var metadata = DownloadGameMetadata(game.ProviderId); game.Name = StringExtensions.NormalizeGameName(metadata.StoreDetails.i18n.displayName); game.Links = new ObservableCollection <Link>() { new Link("Store", @"https://www.origin.com/store" + metadata.StoreDetails.offerPath), new Link("Wiki", @"http://pcgamingwiki.com/w/index.php?search=" + game.Name) }; if (!string.IsNullOrEmpty(metadata.StoreDetails.i18n.gameForumURL)) { game.Links.Add(new Link("Forum", metadata.StoreDetails.i18n.gameForumURL)); } game.Description = metadata.StoreDetails.i18n.longDescription; game.Developers = new ComparableList <string>() { metadata.StoreDetails.developerFacetKey }; game.Publishers = new ComparableList <string>() { metadata.StoreDetails.publisherFacetKey }; game.Genres = new ComparableList <string>(metadata.StoreDetails.genreFacetKey?.Split(',')); game.ReleaseDate = metadata.StoreDetails.platforms.First(a => a.platform == "PCWIN").releaseDate; if (!string.IsNullOrEmpty(metadata.StoreDetails.i18n.gameManualURL)) { game.OtherTasks = new ObservableCollection <GameTask>() { new GameTask() { IsBuiltIn = true, Type = GameTaskType.URL, Path = metadata.StoreDetails.i18n.gameManualURL, Name = "Manual" } }; } // There's not icon available on Origin servers so we will load one from EXE if (game.IsInstalled && string.IsNullOrEmpty(game.Icon)) { var exeIcon = IconExtension.ExtractIconFromExe(game.PlayTask.Path, true); if (exeIcon != null) { var iconName = Guid.NewGuid() + ".png"; metadata.Icon = new FileDefinition( string.Format("images/origin/{0}/{1}", game.ProviderId.Replace(":", ""), iconName), iconName, exeIcon.ToByteArray(System.Drawing.Imaging.ImageFormat.Png) ); } } return(metadata); }
private void LoadTheme_PostExecute(LoadThemeResults result) { if (result.Loaded) { ViewModel = new ThemeViewModel(result.Theme, result.Info); var path = result.Path; UpdateRecentsList(path); if (result.Info == null) { IconExtension icex = new IconExtension(@"/ThemeEditor.WPF;component/Resources/Icons/app_icn.ico", 48); var large = ((BitmapSource)icex.ProvideValue(null)).CreateResizedImage(48, 48); icex.Size = 24; var small = ((BitmapSource)icex.ProvideValue(null)).CreateResizedImage(24, 24); ViewModel.Info.LargeIcon.Bitmap = large; ViewModel.Info.SmallIcon.Bitmap = small; } ThemePath = result.Path; if (ReloadBGMCommand.CanExecute(null)) { ReloadBGMCommand.Execute(null); } } IsBusy = false; }
public override GameMetadata GetMetadata(Game game) { var gameInfo = new GameInfo { Links = new List <Link>() }; var metadata = new GameMetadata() { GameInfo = gameInfo }; gameInfo.Links.Add(new Link("PCGamingWiki", @"http://pcgamingwiki.com/w/index.php?search=" + game.Name)); var program = Twitch.GetUninstallRecord(game.GameId); if (program != null) { gameInfo.Name = StringExtensions.NormalizeGameName(program.DisplayName); if (!string.IsNullOrEmpty(program.DisplayIcon) && File.Exists(program.DisplayIcon)) { var iconPath = program.DisplayIcon; if (iconPath.EndsWith("ico", StringComparison.OrdinalIgnoreCase)) { metadata.Icon = new MetadataFile(program.DisplayIcon); } else { var exeIcon = IconExtension.ExtractIconFromExe(iconPath, true); if (exeIcon != null) { var iconName = Guid.NewGuid() + ".png"; metadata.Icon = new MetadataFile(iconName, exeIcon.ToByteArray(System.Drawing.Imaging.ImageFormat.Png)); } } } } if (entitlements?.Any() == true) { var entitlement = entitlements.FirstOrDefault(a => a.product.id == game.GameId); if (entitlement != null) { if (entitlement.product.productDetail?.iconUrl != null) { metadata.CoverImage = new MetadataFile(entitlement.product.productDetail.iconUrl); } // Ignore Getting Over It background, which is set if the publisher didn't assigned any // https://github.com/JosefNemec/Playnite/issues/1376 var backgroundUrl = entitlement.product.productDetail?.details?.backgroundUrl2; if (!backgroundUrl.IsNullOrEmpty() && backgroundUrl != "https://images-na.ssl-images-amazon.com/images/I/A1VAra5JJvL.jpg") { metadata.BackgroundImage = new MetadataFile(entitlement.product.productDetail.details.backgroundUrl2); } } } return(metadata); }
private static string AddNewFile(string path, Guid libraryId, GameDatabase database) { var fileName = Guid.NewGuid().ToString() + Path.GetExtension(path); var fileId = $"{libraryId.ToString()}/{fileName}"; MetadataFile metaFile = null; try { if (path.StartsWith("http", StringComparison.OrdinalIgnoreCase)) { metaFile = new MetadataFile(fileId, fileName, HttpDownloader.DownloadData(path)); } else { if (File.Exists(path)) { if (path.EndsWith(".exe", StringComparison.OrdinalIgnoreCase)) { var icon = IconExtension.ExtractIconFromExe(path, true); if (icon == null) { return(null); } fileName = Path.ChangeExtension(fileName, ".png"); fileId = Path.ChangeExtension(fileId, ".png"); metaFile = new MetadataFile(fileId, fileName, icon.ToByteArray(System.Drawing.Imaging.ImageFormat.Png)); } else { metaFile = new MetadataFile(fileId, fileName, File.ReadAllBytes(path)); } } else { logger.Error($"Can't add game file during game import, file doesn't exists: {path}"); } } } catch (Exception e) when(!PlayniteEnvironment.ThrowAllErrors) { logger.Error(e, $"Failed to import game file during game import from {path}"); } if (metaFile != null) { if (metaFile.FileName.EndsWith(".tga", StringComparison.OrdinalIgnoreCase)) { metaFile.FileName = Path.ChangeExtension(metaFile.FileName, ".png"); metaFile.FileId = Path.ChangeExtension(metaFile.FileId, ".png"); metaFile.Content = BitmapExtensions.TgaToBitmap(metaFile.Content).ToPngArray(); } database.AddFile(metaFile); return(metaFile.FileId); } return(null); }
public override GameMetadata GetMetadata(Game game) { var gameInfo = new GameInfo { Links = new List <Link>() }; var metadata = new GameMetadata() { GameInfo = gameInfo }; gameInfo.Links.Add(new Link("PCGamingWiki", @"http://pcgamingwiki.com/w/index.php?search=" + game.Name)); var program = Twitch.GetUninstallRecord(game.GameId); if (program != null) { gameInfo.Name = StringExtensions.NormalizeGameName(program.DisplayName); if (!string.IsNullOrEmpty(program.DisplayIcon) && File.Exists(program.DisplayIcon)) { var iconPath = program.DisplayIcon; if (iconPath.EndsWith("ico", StringComparison.OrdinalIgnoreCase)) { metadata.Icon = new MetadataFile(program.DisplayIcon); } else { var exeIcon = IconExtension.ExtractIconFromExe(iconPath, true); if (exeIcon != null) { var iconName = Guid.NewGuid() + ".png"; metadata.Icon = new MetadataFile(iconName, exeIcon.ToByteArray(System.Drawing.Imaging.ImageFormat.Png)); } } } } if (entitlements?.Any() == true) { var entitlement = entitlements.FirstOrDefault(a => a.product.id == game.GameId); if (entitlement != null) { if (entitlement.product.productDetail?.iconUrl != null) { metadata.CoverImage = new MetadataFile(entitlement.product.productDetail.iconUrl); } if (entitlement.product.productDetail?.details?.backgroundUrl2 != null) { metadata.BackgroundImage = new MetadataFile(entitlement.product.productDetail.details.backgroundUrl2); } } } return(metadata); }
/// <summary> /// Wandelt den Extension-Enumwert in einen string um! /// </summary> /// <param name="ext">Extension des Bilds</param> /// <returns></returns> private static string GetExt(IconExtension ext) { switch (ext) { case IconExtension.jpg: return("jpg"); case IconExtension.png: return("png"); } throw new InvalidOperationException("Ungültiger Aufruf!"); }
private void RemoveImage_Execute(TargetImage args) { switch (args) { case TargetImage.Top: ViewModel.Textures.Top.ClearTexture(); break; case TargetImage.Bottom: ViewModel.Textures.Bottom.ClearTexture(); break; case TargetImage.FileLarge: ViewModel.Textures.FileLarge.ClearTexture(); break; case TargetImage.FileSmall: ViewModel.Textures.FileSmall.ClearTexture(); break; case TargetImage.FolderOpen: ViewModel.Textures.FolderOpen.ClearTexture(); break; case TargetImage.FolderClosed: ViewModel.Textures.FolderClosed.ClearTexture(); break; case TargetImage.TopAlt: ViewModel.Textures.TopAlt.ClearTexture(); break; case TargetImage.SmallIcon: { var icex = new IconExtension(@"/ThemeEditor.WPF;component/Resources/Icons/app_icn.ico", 24); var large = ((BitmapSource)icex.ProvideValue(null)).CreateResizedImage(24, 24); ViewModel.Info.SmallIcon.EncodeTexture(large, RawTexture.DataFormat.Bgr565); break; } case TargetImage.LargeIcon: { var icex = new IconExtension(@"/ThemeEditor.WPF;component/Resources/Icons/app_icn.ico", 48); var large = ((BitmapSource)icex.ProvideValue(null)).CreateResizedImage(48, 48); ViewModel.Info.LargeIcon.EncodeTexture(large, RawTexture.DataFormat.Bgr565); break; } default: throw new ArgumentOutOfRangeException(); } }
private string SaveFileIconToTemp(string exePath) { var ico = IconExtension.ExtractIconFromExe(exePath, true); if (ico == null) { return(string.Empty); } var tempPath = Path.Combine(Paths.TempPath, "tempico.png"); if (ico != null) { if (File.Exists(tempPath)) { File.Delete(tempPath); } ico.ToBitmap().Save(tempPath, System.Drawing.Imaging.ImageFormat.Png); } return(tempPath); }
public override GameMetadata GetMetadata(Game game) { var storeMetadata = DownloadGameMetadata(game.GameId); var gameInfo = new GameInfo { Name = StringExtensions.NormalizeGameName(storeMetadata.StoreDetails.i18n.displayName), Description = storeMetadata.StoreDetails.i18n.longDescription, ReleaseDate = storeMetadata.StoreDetails.platforms.First(a => a.platform == "PCWIN").releaseDate, Links = new List <Link>() { new Link("Store", @"https://www.origin.com/store" + storeMetadata.StoreDetails.offerPath), new Link("PCGamingWiki", @"http://pcgamingwiki.com/w/index.php?search=" + game.Name) } }; if (!storeMetadata.StoreDetails.publisherFacetKey.IsNullOrEmpty()) { gameInfo.Publishers = new List <string>() { storeMetadata.StoreDetails.publisherFacetKey }; } if (!storeMetadata.StoreDetails.developerFacetKey.IsNullOrEmpty()) { gameInfo.Developers = new List <string>() { storeMetadata.StoreDetails.developerFacetKey }; } if (!storeMetadata.StoreDetails.genreFacetKey.IsNullOrEmpty()) { gameInfo.Genres = new List <string>(storeMetadata.StoreDetails.genreFacetKey?.Split(',')); } var metadata = new GameMetadata() { GameInfo = gameInfo, Icon = storeMetadata.Icon, CoverImage = storeMetadata.CoverImage, BackgroundImage = storeMetadata.BackgroundImage }; if (!string.IsNullOrEmpty(storeMetadata.StoreDetails.i18n.gameForumURL)) { gameInfo.Links.Add(new Link("Forum", storeMetadata.StoreDetails.i18n.gameForumURL)); } if (!string.IsNullOrEmpty(storeMetadata.StoreDetails.i18n.gameManualURL)) { game.OtherActions = new ObservableCollection <GameAction>() { new GameAction() { IsHandledByPlugin = false, Type = GameActionType.URL, Path = storeMetadata.StoreDetails.i18n.gameManualURL, Name = "Manual" } }; } // There's not icon available on Origin servers so we will load one from EXE if (game.IsInstalled && string.IsNullOrEmpty(game.Icon)) { var playAction = api.ExpandGameVariables(game, game.PlayAction); var executable = string.Empty; if (File.Exists(playAction.Path)) { executable = playAction.Path; } else if (!string.IsNullOrEmpty(playAction.WorkingDir)) { executable = Path.Combine(playAction.WorkingDir, playAction.Path); } if (string.IsNullOrEmpty(executable)) { return(storeMetadata); } var exeIcon = IconExtension.ExtractIconFromExe(executable, true); if (exeIcon != null) { var iconName = Guid.NewGuid() + ".png"; metadata.Icon = new MetadataFile(iconName, exeIcon.ToByteArray(System.Drawing.Imaging.ImageFormat.Png)); } } return(metadata); }
public PaletteControl() { InitializeComponent(); swatchPopup.PlacementTarget = ItemsControl; swatchPopup.Child = new StackPanel { Children = { new Grid { HorizontalAlignment = HorizontalAlignment.Center, Children = { new Rectangle { Fill = (Brush)FindResource("Background"), Opacity = .5 }, new TextBlock { Text = "Shift/Ctrl+Click to edit multiple colors.", FontStyle = FontStyles.Italic, Foreground = (Brush)FindResource("Secondary") }, }, }, swatch, new DockPanel { Children = { new Button { Padding = new Thickness(0), Content = new Path{ Data = IconExtension.GetIcon("EyeDropper"), Fill = (Brush)FindResource("Primary"), Stretch = Stretch.Uniform, Width = 16, Height = 16, }, ToolTip = new ToolTip{ Content = EyeDropperToolTip.Content }, }.Fluent(button =>{ DockPanel.SetDock(button, Dock.Left); button.Click += GrabScreenColor; }), new UniformGrid { Columns = 4, Rows = 2, Children = { swatchTextBoxes[3], swatchTextBoxes[0], swatchTextBoxes[1], swatchTextBoxes[2], decompTextBoxes[3], decompTextBoxes[0], decompTextBoxes[1], decompTextBoxes[2], }, }, }, }, }, }; LoseKeyboardFocusCausesLoseMultiSelect = true; Unloaded += (sender, e) => ClosePopup(); swatchTextBoxes[0].TextChanged += UpdateSwatchColorFromTextBoxes; swatchTextBoxes[1].TextChanged += UpdateSwatchColorFromTextBoxes; swatchTextBoxes[2].TextChanged += UpdateSwatchColorFromTextBoxes; swatchTextBoxes[3].TextChanged += UpdateSwatchColorFromBytesBox; decompTextBoxes[0].TextChanged += UpdateSwatchColorFromDecompTextBoxes; decompTextBoxes[1].TextChanged += UpdateSwatchColorFromDecompTextBoxes; decompTextBoxes[2].TextChanged += UpdateSwatchColorFromDecompTextBoxes; decompTextBoxes[3].TextChanged += UpdateSwatchColorFromDecompBytesBox; }
public override GameMetadata GetMetadata(Game game) { var gameInfo = new GameInfo() { Links = new List <Link>() }; var metadata = new GameMetadata() { GameInfo = gameInfo }; using (var client = new WebStoreClient()) { var catalogs = client.QuerySearch(game.Name).GetAwaiter().GetResult(); if (catalogs.HasItems()) { var product = client.GetProductInfo(catalogs[0].productSlug).GetAwaiter().GetResult(); if (product.pages.HasItems()) { var page = product.pages[0]; gameInfo.Description = page.data.about.description; gameInfo.Developers = new List <string>() { page.data.about.developerAttribution }; metadata.BackgroundImage = new MetadataFile(page.data.hero.backgroundImageUrl); gameInfo.Links.Add(new Link( library.PlayniteApi.Resources.GetString("LOCCommonLinksStorePage"), "https://www.epicgames.com/store/en-US/product/" + catalogs[0].productSlug)); if (page.data.socialLinks.HasItems()) { var links = page.data.socialLinks. Where(a => a.Key.StartsWith("link") && !a.Value.IsNullOrEmpty()). Select(a => new Link(a.Key.Replace("link", ""), a.Value)).ToList(); if (links.HasItems()) { gameInfo.Links.AddRange(links); } } if (!gameInfo.Description.IsNullOrEmpty()) { gameInfo.Description = gameInfo.Description.Replace("\n", "\n<br>"); } } } } gameInfo.Links.Add(new Link("PCGamingWiki", @"http://pcgamingwiki.com/w/index.php?search=" + game.Name)); // There's not icon available on Epic servers so we will load one from EXE if (game.IsInstalled && string.IsNullOrEmpty(game.Icon)) { var playAction = api.ExpandGameVariables(game, game.PlayAction); var executable = string.Empty; if (File.Exists(playAction.Path)) { executable = playAction.Path; } else if (!string.IsNullOrEmpty(playAction.WorkingDir)) { executable = Path.Combine(playAction.WorkingDir, playAction.Path); } var exeIcon = IconExtension.ExtractIconFromExe(executable, true); if (exeIcon != null) { var iconName = Guid.NewGuid() + ".png"; metadata.Icon = new MetadataFile(iconName, exeIcon.ToByteArray(System.Drawing.Imaging.ImageFormat.Png)); } } return(metadata); }
/// <summary> /// Baut aus verschiedenen definierten Informationen eine Uri auf /// </summary> /// <param name="imageName">Name des Bildes (ohne Extension)</param> /// <param name="iconSource">Quelle des Bildes</param> /// <param name="iconExtension">Extension des Bildes</param> /// <returns></returns> private static Uri GetUri(string imageName, IconExtension iconExtension = IconExtension.png, IconSource iconSource = IconSource.Pokemon) { string format = GetSource(iconSource); return(new Uri(string.Format(format, imageName, GetExt(iconExtension)), UriKind.RelativeOrAbsolute)); }