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
DrShark
Power Member
Power Member
Posts: 1872
Joined: 2006-11-03, 22:26 UTC
Location: Kyiv, 68/262
Contact:

Subst'ed/removable drive icon reused for new drives

Post by *DrShark »

This has been tested on TC 9.20 beta 2 on Vista 32-bit, with TC option "Show drive icons from Explorer".

If you already have a drive with custom icon, like c:\ on Vista, it's possible to reproduce it just with subst command.

Description of expected icon behavior:
1. After TC restart, subst a root of c:\ drive as t:, for example go to c:\ in TC and use a button:

Code: Select all

TOTALCMD#BAR#DATA
subst t:
%p.
%COMSPEC%
Subst current path to temp t: drive

1
-1
You'll see in a drive bar the t: drive made by subst command has an icon of c: drive.
Now remove subst'ed drive:

Code: Select all

TOTALCMD#BAR#DATA
subst t: /D

%COMSPEC%
Remove temp t: substed drive

1
-1
2. Restart TC, do the same for a drive without icon instead of c:\, you'll see subst'ed drive won't have icon too.

To reproduce the bug:
1. Restart TC.
2. From TC, using a button shown above, subst a drive using a root of another drive as a target. For test, try a drive without a custom icon.
3. In current TC session, remove sub'sted drive.
4. In current TC session, use subst for a root of drive which has custom icon. It's expected (see above) that new drive will have the icon of drive for which subst used, but instead it won't have an icon (because TC shows an icon for drive made in step 2, which is removed now).
In step 4, instead of subst'ing a new drive, you can connect a usb drive with custom icon (which may even have another drive letter), but TC won't show an icon for it too. If subst'ed drive in step 2 had custom icon, it will be re-used for a new drive which appears in step 4.
This wrong icon is re-used probably in all places where TC uses drive icons: drive bar, drives list, breadcrumb, trees...
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) »

I have checked this now in the debugger. Unfortunately it seems to be a bug in Windows itself: Total Commander requests the icon via SHGetFileInfoW(...SHGFI_SYSICONINDEX | SHGFI_SHELLICONSIZE | SHGFI_USEFILEATTRIBUTES,...) and does NOT cache it. I'm getting the same index for the subst'ed drive even when the target changes.
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 »

It seems bug happens if some drive has been disconnected/removed during TC session before connecting/creating with subst a new drive. And it also seems after Total Commander restart it shows correct icons for new drive that had wrong icon in previous session.
Can you confirm it? If yes, maybe it is possible to detect drive remove/disconnect event and then make Windows think that TC has been closed, so when new drive will be connected in that TC session, Windows will return a correct icon for it?
Donate for Ukraine to help stop Russian invasion!
Ukraine's National Bank special bank account:
UA843000010000000047330992708
User avatar
MarcinW
Power Member
Power Member
Posts: 852
Joined: 2012-01-23, 15:58 UTC
Location: Poland

Post by *MarcinW »

ghisler(Author) wrote:I'm getting the same index
But maybe icon contents change, and TC caches previous contents somehow? (by not updating some image list(s) properly?)
User avatar
DrShark
Power Member
Power Member
Posts: 1872
Joined: 2006-11-03, 22:26 UTC
Location: Kyiv, 68/262
Contact:

Post by *DrShark »

Just in case it matters: if in step 4 to connect a real usb drive with a custom icon, for a short time (a second or so) after drive letter on a drive bar appears, correct custom icon is shown for it, then it gets replaced with an icon used for a drive from step 2.
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, unfortunately TC isn't caching the icon. Therefore there is unfortunately no solution.
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 I wrote, if after we got wrong icon in step 4 we're restarting Total Commander, restart fixes the issue (expected icon is shown for substed or connected over usb drive after TC restart).
Maybe it's possible to request the drive icons using a separate utility, which TC will also restart each time user removes the drive, and kill its process once the utility gets the correct icons (so no Windows icon caching will be applied to TC)?
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) »

I have just created a small C program to get the icon from t:, and it has the same problem.

If only I knew when to restart it - restarting it for each drive request would be very slow.
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 »

I guess it should start once when TC starts to get icons for the first time, and then it should be restarted each time some drive is removed/disconnected (it seems the all the icons are correct if new drives are only added).
Donate for Ukraine to help stop Russian invasion!
Ukraine's National Bank special bank account:
UA843000010000000047330992708
User avatar
MarcinW
Power Member
Power Member
Posts: 852
Joined: 2012-01-23, 15:58 UTC
Location: Poland

Post by *MarcinW »

Yes, if TC gets some drive plugging/unplugging notifications from the operating system, this would be a good moment to verify/rebuild the icons.
User avatar
ghisler(Author)
Site Admin
Site Admin
Posts: 48021
Joined: 2003-02-04, 09:46 UTC
Location: Switzerland
Contact:

Post by *ghisler(Author) »

I prefer not to change that for now, it would require far too many changes. It only seems to affect SUBSTed drives. And it's a constructed problem, it doesn't really occur in real life: Who would create a SUBSTed drive to another drive root? That's not useful at all.
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:It only seems to affect SUBSTed drives. And it's a constructed problem, it doesn't really occur in real life: Who would create a SUBSTed drive to another drive root? That's not useful at all.
No need to create subst'ed drive from root: subst any location, drive w/o custom icon will appear, then remove it, then connect real usb device (like usb hdd) with a custom icon: the drive of real usb device won't have a custom icon (subst'ed default drive icon re-used for it)!

Also, I think it may happen even without substing drives at all. Somewhere on my PC I have a screenshot fom Windows 7 where I connected usb FDD after connecting and removing usb flash drive, and Total Commander showed the usb flash drive icon for usb FDD drive instead of FDD icon.
Donate for Ukraine to help stop Russian invasion!
Ukraine's National Bank special bank account:
UA843000010000000047330992708
User avatar
DrShark
Power Member
Power Member
Posts: 1872
Joined: 2006-11-03, 22:26 UTC
Location: Kyiv, 68/262
Contact:

Post by *DrShark »

In addition to previous post, I reproduced it now on real devices without substing anything.

1. Start Total Commander.
2. Connet USB flash drive, which doesn't have a custom icon. For me, that was S: drive.
3. Disconnect the flash drive using a dialog called by a button:

Code: Select all

TOTALCMD#BAR#DATA
control hotplug.dll

hotplug.dll
RunDll32.exe shell32.dll,Control_RunDLL hotplug.dll


-1
.
4. Connect USB HDD with a custom icon. In my case it was a drive with autorun.inf (with r+a+h attributes), its content:

Code: Select all

[autorun]
ICON=AUTORUN\WDLOGO.ICO
Result: drive appeared (it had another letter - D:) with default icon instead of custom icon defined in autorun.inf.

However, second (additional) launched instance of Total Commander showed correct custom icon for USB HDD drive. Also, simple restart of initial TC instance allows to see the correct custom icon of USB HDD drive.
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) »

connect real usb device (like usb hdd) with a custom icon: the drive of real usb device won't have a custom icon
NOT confirmed on Windows 10! It seems like Microsoft fixed the bug there.
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:NOT confirmed on Windows 10! It seems like Microsoft fixed the bug there.
I reproduced it on 64-bit Windows 10:
Microsoft Windows [Version 10.0.16299.431]
both in TC 9.20 beta 3 x32 and x64 trying steps from that post:
viewtopic.php?p=341490#341490
(to remove drive in step 3 instead of hotplug button I had to use notification area icon because Win10 didn't recognize usb flash and usb hdd as removable drives.)
As a drive for step 2, I used 8 gb usb flash drive without custom icon.
As a drive for step 4, I used 1 tb usb hdd with custom icon.
For both drives, same H: drive letter used on Win 10.
In 1 tb HDD, it's a custom icon from USB HDD manufacturer, so in case it will help to reproduce the issue, I attached it to email with subject TC drive icons bug: wd icon
Donate for Ukraine to help stop Russian invasion!
Ukraine's National Bank special bank account:
UA843000010000000047330992708
Post Reply