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: Hacker, Stefan2, white, sheep

User avatar
DrShark
Power Member
Power Member
Posts: 1111
Joined: 2006-11-03, 22:26 UTC
Location: Kyiv, 68/262

Subst'ed/removable drive icon reused for new drives

Post by *DrShark » 2018-05-10, 15:19 UTC

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...
Android 4.3.1 no root, kernel 08.09.2016; Vista Home Premium SP2 rus 32 bit
TC #149847 Personal licence

Cuz we're all in this together, We're here to make it right

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

Post by *ghisler(Author) » 2018-05-11, 08:35 UTC

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
http://www.ghisler.com

User avatar
DrShark
Power Member
Power Member
Posts: 1111
Joined: 2006-11-03, 22:26 UTC
Location: Kyiv, 68/262

Post by *DrShark » 2018-05-11, 10:04 UTC

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?
Android 4.3.1 no root, kernel 08.09.2016; Vista Home Premium SP2 rus 32 bit
TC #149847 Personal licence

Cuz we're all in this together, We're here to make it right

User avatar
MarcinW
Power Member
Power Member
Posts: 852
Joined: 2012-01-23, 15:58 UTC
Location: Poland

Post by *MarcinW » 2018-05-11, 11:19 UTC

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: 1111
Joined: 2006-11-03, 22:26 UTC
Location: Kyiv, 68/262

Post by *DrShark » 2018-05-11, 19:47 UTC

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.
Android 4.3.1 no root, kernel 08.09.2016; Vista Home Premium SP2 rus 32 bit
TC #149847 Personal licence

Cuz we're all in this together, We're here to make it right

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

Post by *ghisler(Author) » 2018-05-16, 16:38 UTC

No, unfortunately TC isn't caching the icon. Therefore there is unfortunately no solution.
Author of Total Commander
http://www.ghisler.com

User avatar
DrShark
Power Member
Power Member
Posts: 1111
Joined: 2006-11-03, 22:26 UTC
Location: Kyiv, 68/262

Post by *DrShark » 2018-05-17, 07:45 UTC

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)?
Android 4.3.1 no root, kernel 08.09.2016; Vista Home Premium SP2 rus 32 bit
TC #149847 Personal licence

Cuz we're all in this together, We're here to make it right

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

Post by *ghisler(Author) » 2018-05-17, 09:53 UTC

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
http://www.ghisler.com

User avatar
DrShark
Power Member
Power Member
Posts: 1111
Joined: 2006-11-03, 22:26 UTC
Location: Kyiv, 68/262

Post by *DrShark » 2018-05-17, 10:43 UTC

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).
Android 4.3.1 no root, kernel 08.09.2016; Vista Home Premium SP2 rus 32 bit
TC #149847 Personal licence

Cuz we're all in this together, We're here to make it right

User avatar
MarcinW
Power Member
Power Member
Posts: 852
Joined: 2012-01-23, 15:58 UTC
Location: Poland

Post by *MarcinW » 2018-05-17, 18:57 UTC

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: 36418
Joined: 2003-02-04, 09:46 UTC
Location: Switzerland
Contact:

Post by *ghisler(Author) » 2018-05-18, 10:28 UTC

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
http://www.ghisler.com

User avatar
DrShark
Power Member
Power Member
Posts: 1111
Joined: 2006-11-03, 22:26 UTC
Location: Kyiv, 68/262

Post by *DrShark » 2018-05-18, 11:32 UTC

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.
Android 4.3.1 no root, kernel 08.09.2016; Vista Home Premium SP2 rus 32 bit
TC #149847 Personal licence

Cuz we're all in this together, We're here to make it right

User avatar
DrShark
Power Member
Power Member
Posts: 1111
Joined: 2006-11-03, 22:26 UTC
Location: Kyiv, 68/262

Post by *DrShark » 2018-05-18, 19:47 UTC

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.
Android 4.3.1 no root, kernel 08.09.2016; Vista Home Premium SP2 rus 32 bit
TC #149847 Personal licence

Cuz we're all in this together, We're here to make it right

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

Post by *ghisler(Author) » 2018-05-21, 08:21 UTC

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
http://www.ghisler.com

User avatar
DrShark
Power Member
Power Member
Posts: 1111
Joined: 2006-11-03, 22:26 UTC
Location: Kyiv, 68/262

Post by *DrShark » 2018-05-22, 06:43 UTC

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:
https://ghisler.ch/board/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
Android 4.3.1 no root, kernel 08.09.2016; Vista Home Premium SP2 rus 32 bit
TC #149847 Personal licence

Cuz we're all in this together, We're here to make it right

Post Reply