public override void Update(IEnumerable <Game> itemsToUpdate) { foreach (var item in itemsToUpdate) { var dbItem = Get(item.Id); if (!dbItem.Icon.IsNullOrEmpty() && dbItem.Icon != item.Icon) { db.RemoveFile(dbItem.Icon); } if (!dbItem.CoverImage.IsNullOrEmpty() && dbItem.CoverImage != item.CoverImage) { db.RemoveFile(dbItem.CoverImage); } if (!dbItem.BackgroundImage.IsNullOrEmpty()) { if (!dbItem.BackgroundImage.IsHttpUrl() && dbItem.BackgroundImage != item.BackgroundImage) { db.RemoveFile(dbItem.BackgroundImage); } else if (dbItem.BackgroundImage.IsHttpUrl() && dbItem.BackgroundImage != item.BackgroundImage) { HttpFileCache.ClearCache(dbItem.BackgroundImage); } } } base.Update(itemsToUpdate); }
public override void Update(Game itemToUpdate) { var dbItem = Get(itemToUpdate.Id); if (!dbItem.Icon.IsNullOrEmpty() && dbItem.Icon != itemToUpdate.Icon) { db.RemoveFile(dbItem.Icon); } if (!dbItem.CoverImage.IsNullOrEmpty() && dbItem.CoverImage != itemToUpdate.CoverImage) { db.RemoveFile(dbItem.CoverImage); } if (!dbItem.BackgroundImage.IsNullOrEmpty() && !dbItem.BackgroundImage.IsHttpUrl() && dbItem.BackgroundImage != itemToUpdate.BackgroundImage) { db.RemoveFile(dbItem.BackgroundImage); } else if (dbItem.BackgroundImage.IsHttpUrl() && dbItem.BackgroundImage != itemToUpdate.BackgroundImage) { HttpFileCache.ClearCache(dbItem.BackgroundImage); } base.Update(itemToUpdate); }
private void PART_BtAddSteamGridDb_Click(object sender, RoutedEventArgs e) { try { SteamGridDbType steamGridDbType = SteamGridDbType.heroes; if (_IsCover) { steamGridDbType = SteamGridDbType.grids; } var ViewExtension = new SteamGridDbView(_gameBackgroundImages.Name, steamGridDbType); Window windowExtension = PlayniteUiHelper.CreateExtensionWindow(PluginDatabase.PlayniteApi, "SteamGridDB", ViewExtension); windowExtension.ShowDialog(); if (ViewExtension.steamGridDbResult != null) { GlobalProgressOptions globalProgressOptions = new GlobalProgressOptions( resources.GetString("LOCCommonGettingData"), false ); globalProgressOptions.IsIndeterminate = true; var ProgressDownload = PluginDatabase.PlayniteApi.Dialogs.ActivateGlobalProgress((activateGlobalProgress) => { try { var cachedFile = HttpFileCache.GetWebFile(ViewExtension.steamGridDbResult.url); _backgroundImagesEdited.Add(new ItemImage { Name = cachedFile }); } catch (Exception ex) { Common.LogError(ex, false, true, "BackgroundChanger"); } }, globalProgressOptions); Task.Run(() => { while (!(bool)ProgressDownload.Result) { } }).ContinueWith(antecedant => { this.Dispatcher.BeginInvoke((Action) delegate { PART_LbBackgroundImages.ItemsSource = null; PART_LbBackgroundImages.ItemsSource = _backgroundImagesEdited; }); }); } } catch (Exception ex) { Common.LogError(ex, false, true, "BackgroundChanger"); } }
private void RemoveGameMedia(string mediaId) { if (string.IsNullOrEmpty(mediaId)) { return; } if (mediaId.IsHttpUrl()) { HttpFileCache.ClearCache(mediaId); } else { database.RemoveFile(mediaId); } }
public override bool Remove(Guid id) { var item = Get(id); var result = base.Remove(id); db.RemoveFile(item.Icon); db.RemoveFile(item.CoverImage); if (item.BackgroundImage.IsHttpUrl()) { HttpFileCache.ClearCache(item.BackgroundImage); } else { db.RemoveFile(item.BackgroundImage); } return(result); }
public override bool Remove(IEnumerable <Game> items) { foreach (var item in items) { // Get item from in case that passed platform doesn't have actual metadata. var dbItem = Get(item.Id); db.RemoveFile(dbItem.Icon); db.RemoveFile(dbItem.CoverImage); if (dbItem.BackgroundImage.IsHttpUrl()) { HttpFileCache.ClearCache(dbItem.BackgroundImage); } else { db.RemoveFile(dbItem.BackgroundImage); } } var result = base.Remove(items); return(result); }
public static object GetImageFromSource(string source) { if (string.IsNullOrEmpty(source)) { return(null); } var imageId = source; if (string.IsNullOrEmpty(imageId)) { return(null); } if (imageId.StartsWith("resources:")) { if (cache.TryGet(imageId, out var image)) { return(image); } else { try { var imagePath = imageId.Replace("resources:", "pack://application:,,,"); var imageData = BitmapExtensions.BitmapFromFile(imagePath); cache.TryAdd(imageId, imageData, imageData.GetSizeInMemory()); return(imageData); } catch (Exception e) when(!PlayniteEnvironment.ThrowAllErrors) { logger.Error(e, "Failed to create bitmap from resources " + imageId); return(null); } } } if (imageId.IsHttpUrl()) { try { var cachedFile = HttpFileCache.GetWebFile(imageId); if (string.IsNullOrEmpty(cachedFile)) { logger.Warn("Web file not found: " + imageId); return(null); } return(BitmapExtensions.BitmapFromFile(cachedFile)); } catch (Exception exc) when(!PlayniteEnvironment.ThrowAllErrors) { logger.Error(exc, $"Failed to create bitmap from {imageId} file."); return(null); } } if (File.Exists(imageId)) { try { return(BitmapExtensions.BitmapFromFile(imageId)); } catch (Exception e) when(!PlayniteEnvironment.ThrowAllErrors) { logger.Error(e, "Failed to create bitmap from " + imageId); return(null); } } try { if (database == null) { logger.Error("Cannot load database image, database not found."); return(null); } try { if (cache.TryGet(imageId, out var image)) { return(image); } var imageData = database.GetFileAsImage(imageId); if (imageData == null) { logger.Warn("Image not found in database: " + imageId); return(null); } else { cache.TryAdd(imageId, imageData, imageData.GetSizeInMemory()); return(imageData); } } catch (Exception exc) when(!PlayniteEnvironment.ThrowAllErrors) { logger.Error(exc, $"Failed to get bitmap from {imageId} database file."); return(null); } } catch (Exception exc) when(!PlayniteEnvironment.ThrowAllErrors) { logger.Error(exc, "Failed to load image from database."); return(null); } }