Jump to content
LaunchBox Community Forums

Plugin API equivalent of Refresh Images


Recommended Posts

Hi,

In main UI you can right click and select Refresh Images for selected.

Does anyone know an equivalent in plugin API?

I have a good code flow for updating images, but once the process completes, I have to manually select Refresh Images to see the changes.

Thanks!

Link to comment
Share on other sites

Is this in BigBox, refresh the image cache or something else you’re looking to do?  Edit - oh you said Main UI so I assume LaunchBox.  Not sure but have you tried RefrshData?  This worked to make a new game show up when I added a new game so I’d think it will show updated images  

https://pluginapi.launchbox-app.com/html/da689f24-d5ec-7977-c285-e94ce60f7c94.htm

Edited by Fry
Link to comment
Share on other sites

Thanks Fry,

unfortunately, PluginHelper.LaunchBoxMainViewModel.RefreshData(); looks like it is working - the grid reloads, but the new image isn't picked up until I select 'Refresh Selected Images' myself... 

Maybe I'm just trying too quickly... I'll try a delay.

Link to comment
Share on other sites

Oh shoot, you're right.  I poked around and found that this has to do with the image cache.  I'm assuming you're modifying or adding images into the Launchbox\Images folder.  PluginHelper.LaunchBoxMainViewModel.RefreshData works BUT you first need to update the image cache and as far as I can tell there's no way to do that via the API.  So this is a pretty ugly work around which is to write your image into the image cache yourself and then call PluginHelper.LaunchBoxMainViewModel.RefreshData. This isn't ideal because going around the plug-in API to write into the image cache could easily break your plug-in with a future launchbox update if they choose to change the way images in the image cache are stored.  But, it does work as a hacky workaround.  You would want to scale your image to whatever dimensions that LaunchBox would scale and would you need to name it with the naming convention that LaunchBox would name it.  The naming convention looks to be something like: 

.{ImageType}-{Game.Id}-{MaxHeight}-{MaxWidth}.{jpg|png}

image.thumb.png.19ec00210f45f0b97bf9d1e66d0ffc01.png

I'm not 100% sure how the image scaling works.  I think it's dependent on that slider that lets you choose how many games fit in a row because when I slide that around, I see the image cache updating like crazy and new files getting generated with new file names in that dimension part of the file name.  So this is the dicey part of going around the plug-in API.  

I tested this out with a simple plug-in to test where all I do is call PluginHelper.LaunchBoxMainViewModel.RefreshData.  While LaunchBox is open, I manually replaced an image in the LaunchBox\Images\Cache-LB folder with a new image.  Then clicked my plug-in menu item to call RefreshData and the image updated on the screen.

Link to comment
Share on other sites

Cool. Be careful with the scaling logic if you’re planning to do a lot of images because if it’s not the right dimensions then I think launchbox (wpf) will have to resize the images on the fly and it will probably hurt performance. 

Edited by Fry
Link to comment
Share on other sites

Just had a thought and I am unable to test at the moment to confirm but one approach that might work would be to simply delete the image from the cache and call the refreshData method. I wonder if that would regenerate the image for you so you don’t need to worry about the file naming convention or scaling the image properly. May be worth a try.

 

EDIT - tested and this works.  Just delete the cached image and call RefreshData and it will regen itself properly

Edited by Fry
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...