Bug in Rename function

English support forum

Moderators: white, Hacker, petermad, Stefan2

cheming
Member
Member
Posts: 153
Joined: 2004-05-07, 14:38 UTC
Location: China

Bug in Rename function

Post by *cheming »

1. press Shift-F6 to change a filename that contains unicode charactor (just like Chinese, Japanese, etc).
2. the selection by default is wrong!

Here is a picture to show this bug: :arrow:

http://tinypic.com/kmb0w
User avatar
ghisler(Author)
Site Admin
Site Admin
Posts: 48097
Joined: 2003-02-04, 09:46 UTC
Location: Switzerland
Contact:

Post by *ghisler(Author) »

I have tried this both with Windows 9x (Chinese version) and Windows 2000 (German with Chinese language installed) without problems.

Please let me know which Windows version you use, and what you have set in Control Panel - Regional settings as a language for non-Unicode programs.
Author of Total Commander
https://www.ghisler.com
cheming
Member
Member
Posts: 153
Joined: 2004-05-07, 14:38 UTC
Location: China

Post by *cheming »

Windows XP Chinese Version with SP2
TotalCmd 6.03a

The filename in Hex:
0000 0000 D2 B5 CE F1 D6 A7 B3 C5 B2 BF 20 2D 20 C8 CB D4
0000 0010 B1 BC A8 D0 A7 BF BC BA CB B1 ED 2D 31 30 D4 C2
0000 0020 2E 78 6C 73

Regional settings in my machine for language for non-Unicode program are Chinese of couse :-) My XP is a localized version not multi-language version. But I tried in that version too, the same filename, the same problem.

In my .ini file, there is such a line:

RenameSelOnlyName=1


I found the problem has such rules:

1. filename's length is 2n+1 (Chinese char's number, not Ansi-string's length)
2. selection's legnth always n+1

I give you seven examples:

http://tinypic.com/kohf9
Last edited by cheming on 2004-11-11, 10:43 UTC, edited 1 time in total.
User avatar
Hacker
Moderator
Moderator
Posts: 13071
Joined: 2003-02-06, 14:56 UTC
Location: Bratislava, Slovakia

Post by *Hacker »

[IMG] tag doesn't work here, please use the [URL] tag instead.
(I changed it in your first post.)

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

Post by *ghisler(Author) »

Thanks for all the details, I will try to reproduce it.
Author of Total Commander
https://www.ghisler.com
User avatar
follo
Junior Member
Junior Member
Posts: 15
Joined: 2003-10-08, 05:20 UTC

Post by *follo »

I had reported this problem before,see:

http://ghisler.ch/board/viewtopic.php?t=3531&highlight=chinese

This problem was resolved in version 6.0X. But now it occured again in v6.03a.
My os is chinese version of Window XP with sp1.
User avatar
follo
Junior Member
Junior Member
Posts: 15
Joined: 2003-10-08, 05:20 UTC

Post by *follo »

Now it's clear that the rename bug is in v6.03a.
This functionality in v6.03 is ok.
User avatar
ghisler(Author)
Site Admin
Site Admin
Posts: 48097
Joined: 2003-02-04, 09:46 UTC
Location: Switzerland
Contact:

Post by *ghisler(Author) »

I have just tried it with an English Windows 2000: Both with English and simplified Chinese as default language the selection is 100% correct! There must be something different to localized Chinese versions...
Now it's clear that the rename bug is in v6.03a.
This functionality in v6.03 is ok.
This can't be, the two are 100% code-identical except for the fix in the parallel port connection...
Author of Total Commander
https://www.ghisler.com
cheming
Member
Member
Posts: 153
Joined: 2004-05-07, 14:38 UTC
Location: China

Post by *cheming »

ghisler(Author) wrote:I have just tried it with an English Windows 2000: Both with English and simplified Chinese as default language the selection is 100% correct! There must be something different to localized Chinese versions...
Now it's clear that the rename bug is in v6.03a.
This functionality in v6.03 is ok.
This can't be, the two are 100% code-identical except for the fix in the parallel port connection...
Ghisler is right. I tested in Windows 2000 localized Chinese version and no problem too. So I suggest you should test it in Windows XP and you can represent the issue.
User avatar
follo
Junior Member
Junior Member
Posts: 15
Joined: 2003-10-08, 05:20 UTC

Post by *follo »

Yes, this problem occurs in windows XP.
I tested v6.03 in Chinese version of windows 2003 server. And it was ok.
When I executed v6.03 in windows XP(Chinese version) the problem reoccured.

So ghisler is right:"There must be something different to localized Chinese versions... "
cheming
Member
Member
Posts: 153
Joined: 2004-05-07, 14:38 UTC
Location: China

Post by *cheming »

Here is the code I disassambled. I think this is like TMyListBox.SetSelLength.

Code: Select all

0042D184  /$ 55             PUSH EBP
0042D185  |. 8BEC           MOV EBP,ESP
0042D187  |. 83C4 F8        ADD ESP,-8
0042D18A  |. 53             PUSH EBX
0042D18B  |. 56             PUSH ESI
0042D18C  |. 8BF2           MOV ESI,EDX
0042D18E  |. 8BD8           MOV EBX,EAX
0042D190  |. 8D45 FC        LEA EAX,DWORD PTR SS:[EBP-4]
0042D193  |. 50             PUSH EAX
0042D194  |. 8D45 F8        LEA EAX,DWORD PTR SS:[EBP-8]
0042D197  |. 50             PUSH EAX
0042D198  |. 68 B0000000    PUSH 0B0
0042D19D  |. 8BC3           MOV EAX,EBX
0042D19F  |. E8 A870FFFF    CALL TOTALCMD.0042424C
0042D1A4  |. 50             PUSH EAX                                 ; |hWnd
0042D1A5  |. E8 EE8BFDFF    CALL <JMP.&user32.SendMessageA>          ; \SendMessageA
0042D1AA  |. 0375 F8        ADD ESI,DWORD PTR SS:[EBP-8]
0042D1AD  |. 8975 FC        MOV DWORD PTR SS:[EBP-4],ESI
0042D1B0  |. 8B45 FC        MOV EAX,DWORD PTR SS:[EBP-4]
0042D1B3  |. 50             PUSH EAX
0042D1B4  |. 8B45 F8        MOV EAX,DWORD PTR SS:[EBP-8]
0042D1B7  |. 50             PUSH EAX
0042D1B8  |. 68 B1000000    PUSH 0B1
0042D1BD  |. 8BC3           MOV EAX,EBX
0042D1BF  |. E8 8870FFFF    CALL TOTALCMD.0042424C
0042D1C4  |. 50             PUSH EAX                                 ; |hWnd
0042D1C5  |. E8 CE8BFDFF    CALL <JMP.&user32.SendMessageA>          ; \SendMessageA
0042D1CA  |. 5E             POP ESI
0042D1CB  |. 5B             POP EBX
0042D1CC  |. 59             POP ECX
0042D1CD  |. 59             POP ECX
0042D1CE  |. 5D             POP EBP
0042D1CF  \. C3             RETN
I do some test in Delphi for testing the compatability of SetSelLength of TEdit class and Chinese character.

Code: Select all

procedure TCustomEdit.SetSelLength(Value: Integer);
var
  Selection: TSelection;
begin
  SendMessage(Handle, EM_GETSEL, Longint(@Selection.StartPos), Longint(@Selection.EndPos));
  Selection.EndPos := Selection.StartPos + Value;
  SendMessage(Handle, EM_SETSEL, Selection.StartPos, Selection.EndPos);
  SendMessage(Handle, EM_SCROLLCARET, 0,0);
end;
I found EM_GETSEL and EM_SETSEL deal Chinese as DBCS and leading-byte sensitive. So, when selecting four Chinese chars, EM_GETSEL returns 8 as the sel_length. But in the code of TC, it returns 4, this is the character size , not byte size. It seems that you called ByteToCharLen function somewhere.
User avatar
White Wind
Junior Member
Junior Member
Posts: 19
Joined: 2004-11-05, 06:21 UTC
Location: Irkutsk, Russia

Post by *White Wind »

May be it is not ByteToCharLen but just SendMessageW?
User avatar
ghisler(Author)
Site Admin
Site Admin
Posts: 48097
Joined: 2003-02-04, 09:46 UTC
Location: Switzerland
Contact:

Post by *ghisler(Author) »

2cheming
Yes, Total Commander uses EM_SETSEL to set the selection length. However, it uses CharNext() to count the number of characters in the string. Actually this seems to be a bug in Windows XP that EM_SETSEL works differently than in all other Windows versions - EM_SETSEL seems to select bytes on XP, while it selects characters on all other windows versions.

I will try to solve it like this:
1. Select entire field
2. Check how long the selection is via EM_GETSEL
3. Depending on the return value, use the one or other length for EM_SETSEL
Author of Total Commander
https://www.ghisler.com
cheming
Member
Member
Posts: 153
Joined: 2004-05-07, 14:38 UTC
Location: China

Post by *cheming »

ghisler(Author) wrote:2cheming
Yes, Total Commander uses EM_SETSEL to set the selection length. However, it uses CharNext() to count the number of characters in the string. Actually this seems to be a bug in Windows XP that EM_SETSEL works differently than in all other Windows versions - EM_SETSEL seems to select bytes on XP, while it selects characters on all other windows versions.

I will try to solve it like this:
1. Select entire field
2. Check how long the selection is via EM_GETSEL
3. Depending on the return value, use the one or other length for EM_SETSEL
As I mentioned above, EM_SETSEL is DBCS sensitive, that means even you set 3 to EM_SETSEL on 2 Chinese characters (4 bytes), it only select 1 character too (2 bytes). So I think you can just simply use Length() function to calculate the string length and pass it to EM_SETSEL will make it work fine in all versions of Windows.
User avatar
ghisler(Author)
Site Admin
Site Admin
Posts: 48097
Joined: 2003-02-04, 09:46 UTC
Location: Switzerland
Contact:

Post by *ghisler(Author) »

Unfortunately it's not that simple. :(
I have now installed the Chinese language on Windows XP English SP2, and TC 6.03a works correctly! So apparently there must be a difference between the English XP and the Chinese XP which you are using.

I will try to implement what I have suggested above.
Author of Total Commander
https://www.ghisler.com
Post Reply