microsoft / PowerToys

Windows system utilities to maximize productivity
MIT License
110.64k stars 6.52k forks source link

[File Explorer] Disabling/uninstalling thumbnail providers may require cleaning up the thumbnail cache #7213

Open arjunbalgovind opened 4 years ago

arjunbalgovind commented 4 years ago

While testing the fix for enabling/disabling the File Explorer add-ons (https://github.com/microsoft/PowerToys/pull/6883), i.e. preview handlers and thumbnail providers it was found that for thumbnail providers, if you enable/disable the setting may require restarting explorer and cleaning up the thumbnail cache. This also applies for uninstalling.

I'm not exactly sure under what circumstances does Windows normally update the thumbnail cache, but clearing the thumbnail cache using the steps in this article: https://neosmart.net/wiki/clear-thumbnails-cache/#Method_2-4, i.e. Disk Cleanup ->Thumbnails can be used consistently to enable/disable the handler once the setting has been applied from PowerToys. (more context at this comment https://github.com/microsoft/PowerToys/pull/6883#discussion_r501415314)

We should find if this step can be avoided, or if there is a way to trigger it from code.

arjunbalgovind commented 4 years ago

@crutkas FYI. @chrdavis might have some insights on this.

chrdavis commented 4 years ago

To my knowledge you can

1. Delete the thumbnail and icon cache databases under:

%localappdata%\Microsoft\Windows\Explorer

iconcache.db thumbcache.db

2. Programmatically invoking the thumbnail cleanup component of the desktop cleanup wizard - which I wouldn't recommend as it is not publicly supported but people seem to be doing it.

htcfreek commented 4 years ago

@arjunbalgovind We have to send the message SHChangeNotify with the SHCNE_ASSOCCHANGED flag.

Quote from docs.microsoft.com: "Remarks Applications that register new handlers of any type must call SHChangeNotify with the _SHCNEASSOCCHANGED flag to instruct the Shell to invalidate the icon and thumbnail cache. This will also load new icon and thumbnail handlers that have been registered. Note, however, that icon overlay handlers are not reloaded." (https://docs.microsoft.com/en-us/windows/win32/api/shlobj_core/nf-shlobj_core-shchangenotify)

crutkas commented 2 years ago

@Aaron-Junker / @davidegiacometti is this in progress?

davidegiacometti commented 2 years ago

@Aaron-Junker / @davidegiacometti is this in progress?

Not really, https://github.com/microsoft/PowerToys/pull/12996 was a partial work. Since there seems to be no way to clean thumbnails for a file extension maybe closing this for https://github.com/microsoft/PowerToys/issues/13618 could be a good choice.

sredna commented 2 years ago

Programmatically invoking the thumbnail cleanup component of the desktop cleanup wizard - which I wouldn't recommend as it is not publicly supported but people seem to be doing it

The Disk Cleanup handlers API is documented and anyone can write a custom handler.