Subst'ed/removable drive icon reused for new drives

The behaviour described in the bug report is either by design, or would be far too complex/time-consuming to be changed

Moderators: white, Hacker, petermad, Stefan2

User avatar
ghisler(Author)
Site Admin
Site Admin
Posts: 48021
Joined: 2003-02-04, 09:46 UTC
Location: Switzerland
Contact:

Post by *ghisler(Author) »

Not confirmed, I tried with your icon.
Author of Total Commander
https://www.ghisler.com
User avatar
MarcinW
Power Member
Power Member
Posts: 852
Joined: 2012-01-23, 15:58 UTC
Location: Poland

Post by *MarcinW »

I have much more simple problem which - I suppose - may be connected with the problem described here.

I created a pendrive containing Icon1.ico and Autorun.inf with the following contents:

Code: Select all

[autorun]
icon=Icon1.ico
Tested with Windows 7 64-bit and TC 9.20 Beta 4 64-bit:

1) Open TC
2) Open also "Computer" to see Explorer icons
3) Insert pendrive
4) Explorer shows a new drive icon, which blinks for a moment and then finally displays Icon1.ico
5) TC shows a standard drive icon
6) Restart TC - now it shows Icon1.ico

Regards
User avatar
ghisler(Author)
Site Admin
Site Admin
Posts: 48021
Joined: 2003-02-04, 09:46 UTC
Location: Switzerland
Contact:

Post by *ghisler(Author) »

Unfortunately I couldn't reproduce that on Windows 10. I tried with a USB stick and a USB harddisk, both with their own custom icons.

I will move this to "Will not be changed" for now.
Author of Total Commander
https://www.ghisler.com
User avatar
MarcinW
Power Member
Power Member
Posts: 852
Joined: 2012-01-23, 15:58 UTC
Location: Poland

Post by *MarcinW »

I found the reason.

Before going into details, one question: when are drive icons updated? In a WM_DEVICECHANGE handler?

Regards
User avatar
ghisler(Author)
Site Admin
Site Admin
Posts: 48021
Joined: 2003-02-04, 09:46 UTC
Location: Switzerland
Contact:

Post by *ghisler(Author) »

Yes, when TC receives WM_DEVICECHANGE with wparam=DBT_DEVICEARRIVAL or DBT_DEVICEREMOVECOMPLETE options.

lparam then points to a DEV_BROADCAST_VOLUME structure. TC reacts when dbcv_devicetype=DBT_DEVTYP_VOLUME.

TC updates the icon immediately, and again with a 2 second delay.
Author of Total Commander
https://www.ghisler.com
User avatar
MarcinW
Power Member
Power Member
Posts: 852
Joined: 2012-01-23, 15:58 UTC
Location: Poland

Post by *MarcinW »

Ok, thanks.

What is the reason of trying again after 2 seconds?
User avatar
ghisler(Author)
Site Admin
Site Admin
Posts: 48021
Joined: 2003-02-04, 09:46 UTC
Location: Switzerland
Contact:

Post by *ghisler(Author) »

When TC gets the icon immediately within WM_DEVICECHANGE, I ofent get just the default icon. However, some removable decides have autorun.inf defining a different icon. Apparenly Windows notices that only a bit after sending WM_DEVICECHANGE.
Author of Total Commander
https://www.ghisler.com
User avatar
DrShark
Power Member
Power Member
Posts: 1872
Joined: 2006-11-03, 22:26 UTC
Location: Kyiv, 68/262
Contact:

Post by *DrShark »

As Christian Ghisler wrote in email, requesting icons using separate .exe program can't be used as a solution because it will cause a slowdown of drive icons appearance, especially on systems with real-time antivirus scanners, so we need different solution.

So it seems that sometimes Windows returns correct icon on 1st Total Commander request, and sometimes on 2nd request (2 seconds after 1st one) after WM_DEVICECHANGE event, and in some cases (mentioned in this topic) it may return correct drive icon on 1st request, but wrong icon second request? And since TC is using an icon it gets from second request, it uses wrong icon? Or Windows may return wrong icons for both requests? Maybe at least for a case with correct icon on first request and wrong one on second request, TC may somehow detect which icon is correct one?
Donate for Ukraine to help stop Russian invasion!
Ukraine's National Bank special bank account:
UA843000010000000047330992708
User avatar
ghisler(Author)
Site Admin
Site Admin
Posts: 48021
Joined: 2003-02-04, 09:46 UTC
Location: Switzerland
Contact:

Post by *ghisler(Author) »

TC uses icons from both first and second request. For example, when a USB stick has its own icon, TC will show standard icon received from first request, and it will change to the specific stick icon after the second request.
Author of Total Commander
https://www.ghisler.com
User avatar
DrShark
Power Member
Power Member
Posts: 1872
Joined: 2006-11-03, 22:26 UTC
Location: Kyiv, 68/262
Contact:

Post by *DrShark »

ghisler(Author) wrote:TC uses icons from both first and second request. For example, when a USB stick has its own icon, TC will show standard icon received from first request, and it will change to the specific stick icon after the second request.
Yes, but I meant the case where TC shows correct icon after first request, but wrong icon after second request. Can TC somehow detect it and then show only an icon from first request?
Donate for Ukraine to help stop Russian invasion!
Ukraine's National Bank special bank account:
UA843000010000000047330992708
User avatar
ghisler(Author)
Site Admin
Site Admin
Posts: 48021
Joined: 2003-02-04, 09:46 UTC
Location: Switzerland
Contact:

Post by *ghisler(Author) »

No, TC just shows what Windows returns. It has no chance to know whether a returned icon is right or wrong.
Author of Total Commander
https://www.ghisler.com
User avatar
MarcinW
Power Member
Power Member
Posts: 852
Joined: 2012-01-23, 15:58 UTC
Location: Poland

Post by *MarcinW »

According to my tests, for a pendrive with custom icon defined in Autorun.inf, the following messages are received:

- WM_DEVICECHANGE with wParam = DBT_DEVICEARRIVAL is reveived - a standard drive icon is available in the image list,
- then one or more WM_DEVICECHANGE with wParam = DBT_DEVNODES_CHANGED is/are received - a custom (defined in Autorun.inf) drive icon is available in the image list.

This means, that TC should also handle WM_DEVICECHANGE messages with wParam = DBT_DEVNODES_CHANGED - and since DBT_DEVNODES_CHANGED passes no additional info, all removable drive icons should be refreshed on DBT_DEVNODES_CHANGED.

Regards
User avatar
ghisler(Author)
Site Admin
Site Admin
Posts: 48021
Joined: 2003-02-04, 09:46 UTC
Location: Switzerland
Contact:

Post by *ghisler(Author) »

But does the icon really change to the correct one? Currently I'm simply re-reading the icons 2 seconds later, and it works fine here.

Could you test with my test tool whether it loads the correct icon when you click on the window?

All you need to do is change the drive letter of the drive to T:
https://totalcommander.ch/win/testiconproblems.zip

Or get the source code here:
https://totalcommander.ch/win/testiconproblems_src.zip
Author of Total Commander
https://www.ghisler.com
User avatar
MarcinW
Power Member
Power Member
Posts: 852
Joined: 2012-01-23, 15:58 UTC
Location: Poland

Post by *MarcinW »

I performed tests with the tool and it works properly - but only because I'm not, as a human, fast enough to reproduce the problem. But I can easily reproduce the problem with my own, simple test tool. I will describe cause and all the possible solutions in the next post here.
User avatar
ghisler(Author)
Site Admin
Site Admin
Posts: 48021
Joined: 2003-02-04, 09:46 UTC
Location: Switzerland
Contact:

Post by *ghisler(Author) »

OK, I will add reacting to DBT_DEVNODES_CHANGED in RC2 tomorrow, let's see whether it helps or not.
Author of Total Commander
https://www.ghisler.com
Post Reply