Bookstore

Recent

Author Topic: Bug in LCL unicode file names handlig (procedure FindWideToAnsi)  (Read 5857 times)

dredkin

  • New member
  • *
  • Posts: 5
HI all.

I guess i've found a bug in LCL.
file lcl\include\winfileutil.inc

procedure FindWideToAnsi(const wide: TWIN32FINDDATAW; var ansi: TWIN32FINDDATA);

This is howit looks now:
Code: [Select]
procedure FindWideToAnsi(const wide: TWIN32FINDDATAW; var ansi: TWIN32FINDDATA);
var
  ws : WideString;
  an : AnsiString;
begin
  {$ifdef WinCE}
  ansi := wide;
  {$else}
  SetLength(ws, length(wide.cAlternateFileName));
  Move(wide.cAlternateFileName[0], ws[1], length(ws)*2);
  an:=ws; // no need to utf8 for cAlternateFileName (it's always ansi encoded)
  Move(an[1], ansi.cAlternateFileName, sizeof(ansi.cAlternateFileName));

  ws:=PWideChar(@wide.cFileName[0]);
  an:=UTF8Encode(ws);
  ansi.cFileName:=an;
  if length(an)<length(ansi.cFileName) then ansi.cFileName[ length(an)]:=#0;

  with ansi do
  begin
    dwFileAttributes := wide.dwFileAttributes;
    ftCreationTime := wide.ftCreationTime;
    ftLastAccessTime := wide.ftLastAccessTime;
    ftLastWriteTime := wide.ftLastWriteTime;
    nFileSizeHigh := wide.nFileSizeHigh;
    nFileSizeLow := wide.nFileSizeLow;
    dwReserved0 := wide.dwReserved0;
    dwReserved1 := wide.dwReserved1;
  end;
  {$endif}
end;

I'm pretty sure it should be:
Code: [Select]
procedure FindWideToAnsi(const wide: TWIN32FINDDATAW; var ansi: TWIN32FINDDATA);
var
  ws : WideString;
  an : AnsiString;
begin
  {$ifndef WinCE}
  SetLength(ws, length(wide.cAlternateFileName));
  Move(wide.cAlternateFileName[0], ws[1], length(ws)*2);
  an:=ws; // no need to utf8 for cAlternateFileName (it's always ansi encoded)
  Move(an[1], ansi.cAlternateFileName, sizeof(ansi.cAlternateFileName));
  {$endif}

  ws:=PWideChar(@wide.cFileName[0]);
  an:=UTF8Encode(ws);
  ansi.cFileName:=an;
  if length(an)<length(ansi.cFileName) then ansi.cFileName[ length(an)]:=#0;

  with ansi do
  begin
    dwFileAttributes := wide.dwFileAttributes;
    ftCreationTime := wide.ftCreationTime;
    ftLastAccessTime := wide.ftLastAccessTime;
    ftLastWriteTime := wide.ftLastWriteTime;
    nFileSizeHigh := wide.nFileSizeHigh;
    nFileSizeLow := wide.nFileSizeLow;
    {$ifdef WinCE}
    dwOID:= wide.dwOID;
    {$else}
    dwReserved0 := wide.dwReserved0;
    dwReserved1 := wide.dwReserved1;
    {$endif}
  end;
end;

This change will fix the following issue:
Now on WINCE TShellTreeView and TShellListView cannot display unicode file names (question marks are seen instead of non-latin symbols). So it's impossible to select unicode file name in TOPenDialog.
I've checked it and after fix TOpenDialog works as expected.

I'm not familiar with lazarus bug tracking so I would be very glad if someone who has priviledges commit this to svn. :)
« Last Edit: June 20, 2011, 08:13:28 pm by dredkin »

Bart

  • Hero Member
  • *****
  • Posts: 3722
    • Bart en Mariska's Webstek
Re: Bug in LCL unicode file names handlig (procedure FindWideToAnsi)
« Reply #1 on: June 20, 2011, 11:56:17 pm »
You should really post it in the bugtracker.
Bugs reported here are forgotten, bugs in the bugtracker are not.

Preferaably you make a diff of your copy of winfileutil against the one that came with your Lazarus version originally and attach that diff to the bugreprot in the bugtracker.

See: http://wiki.freepascal.org/How_do_I_create_a_bug_report and http://wiki.freepascal.org/Creating_A_Patch

Bart

dredkin

  • New member
  • *
  • Posts: 5
Re: Bug in LCL unicode file names handlig (procedure FindWideToAnsi)
« Reply #2 on: June 21, 2011, 09:10:42 am »
Yeah. Want something to be done - do it yourself.
Bug http://bugs.freepascal.org/view.php?id=19602 submitted

Bart

  • Hero Member
  • *****
  • Posts: 3722
    • Bart en Mariska's Webstek
Re: Bug in LCL unicode file names handlig (procedure FindWideToAnsi)
« Reply #3 on: June 21, 2011, 11:58:58 am »
Yeah. Want something to be done - do it yourself.
Bug http://bugs.freepascal.org/view.php?id=19602 submitted

No need for sarcasme here.

I merely pointed out to you that the bugtracker is the place to report bugs.

As a matter of courtacy (from your side) I asked you to include your solution for the problem as well.
Doing so will speed up things (if your patch is correct, that is. I can't test, I do not have WinCE).

As a matter of courtesy from my side I pointed to the wiki articles. If you would want te get involved in the development of Fpc/Lazarus (solving bugs, adding functionality etc.) you really need to read them.
And from your efforts to solve the bug you reported, I gathered you might be interested in it.

Even if you do not participate in finding the solution (which you clearly did, or tried), we still are greatfull for bugs reported in Mantis.

Please, every now and then, check on the bugreport you filed: it is possible that some developer has questions for you regarding this bug.

For now,

Happy coding!

Bart