View Issue Details

IDProjectCategoryView StatusLast Update
0021984LazarusLazUtilspublic2012-06-27 09:07
ReporterTakeda MatsukiAssigned ToFelipe Monteiro de Carvalho 
PrioritynormalSeveritymajorReproducibilityalways
Status resolvedResolutionfixed 
Product Version1.1 (SVN)Product Build 
Target VersionFixed in Version1.1 (SVN) 
Summary0021984: [Patch] "FileUtil.FileSetDateUTF8" failed to work with Unicode FileName/Directory
Description

If we want to use FileSetDateUTF8 with normal FileName and normal Directory name (using ABC,..,Z) everything work fine, but when we work with directory or filename contain character Unicode, it would failed to work (File Date stamped using current time/date).

Regards,
takeda
Additional InformationI test using :

1. FPC 2.6.1 svn 21235 and
2. FPC 2.7.1 svn 21248,
3. Lazarus v1.1 svn 37216.
4. OS Windows 7 Ultimate 64bit.
TagsNo tags attached.
Fixed in Revision37794
LazTarget-
WidgetsetWin32/Win64
Attached Files
  • 2012-05-08 - FileSetDateUTF8 (Patch).patch (1,175 bytes)
    Index: fileutil.inc
    ===================================================================
    --- fileutil.inc	(revision 37216)
    +++ fileutil.inc	(working copy)
    @@ -95,8 +95,29 @@
     end;
     
     function FileSetDateUTF8(const FileName: String; Age: Longint): Longint;
    +{$IFDEF Windows}
    + Function ADosTimeToWinTime (DosTime:longint;Var Wintime : TFileTime):longbool;
    + var
    +  lft : TFileTime;
    + begin
    +  ADosTimeToWinTime:=DosDateTimeToFileTime(longrec(DosTime).hi,longrec(DosTime).lo,@lft) and
    +                                           LocalFileTimeToFileTime(lft,Wintime);
    + end;
    +var
    + FT:TFileTime;
    +{$ENDIF}
     begin
    + {$IFDEF WINDOWS}
    +   if (ADosTimeToWinTime(Age,FT) and
    +    SetFileTime(CreateFileW(PWideChar(UTF8Decode(FileName)),
    +                                            FILE_WRITE_ATTRIBUTES,
    +                                            0, nil, OPEN_EXISTING,
    +                                            FILE_ATTRIBUTE_NORMAL, 0),
    +                                            nil, nil, @FT)) then Exit;
    +  Result := GetLastError;
    + {$ELSE}
       Result:=SysUtils.FileSetDate(UTF8ToSys(Filename),Age);
    + {$ENDIF}
     end;
     
     function ParamStrUTF8(Param: Integer): string;
    
  • 2012-05-08 - FileSetDateUTF8 (Patch)2.patch (1,353 bytes)
    Index: fileutil.inc
    ===================================================================
    --- fileutil.inc	(revision 37234)
    +++ fileutil.inc	(working copy)
    @@ -95,9 +95,36 @@
     end;
     
     function FileSetDateUTF8(const FileName: String; Age: Longint): Longint;
    +{$IFDEF Windows}
    + {$ifdef WindowsUnicodeSupport}
    + Function ADosTimeToWinTime (DosTime:longint;Var Wintime : TFileTime):longbool;
    + var
    +  lft : TFileTime;
    + begin
    +  ADosTimeToWinTime:=DosDateTimeToFileTime(longrec(DosTime).hi,longrec(DosTime).lo,@lft) and
    +                                           LocalFileTimeToFileTime(lft,Wintime);
    + end;
    +var
    + FT:TFileTime;
    +  {$endif}
    +{$ENDIF}
     begin
    + {$IFDEF WINDOWS}
    +  {$ifdef WindowsUnicodeSupport}
    +   if (ADosTimeToWinTime(Age,FT) and
    +    SetFileTime(CreateFileW(PWideChar(UTF8ToUTF16(FileName)),
    +                                            FILE_WRITE_ATTRIBUTES,
    +                                            0, nil, OPEN_EXISTING,
    +                                            FILE_ATTRIBUTE_NORMAL, 0),
    +                                            nil, nil, @FT)) then Exit;
    +   Result := GetLastError;
    +  {$else}
    +   Result:=SysUtils.FileSetDate(UTF8ToSys(Filename),Age);
    +  {$endif}
    + {$ELSE}
       Result:=SysUtils.FileSetDate(UTF8ToSys(Filename),Age);
    -end;
    + {$ENDIF}
    +end;  
     
     function ParamStrUTF8(Param: Integer): string;
     begin
    

Activities

2012-05-08 07:50

 

2012-05-08 - FileSetDateUTF8 (Patch).patch (1,175 bytes)
Index: fileutil.inc
===================================================================
--- fileutil.inc	(revision 37216)
+++ fileutil.inc	(working copy)
@@ -95,8 +95,29 @@
 end;
 
 function FileSetDateUTF8(const FileName: String; Age: Longint): Longint;
+{$IFDEF Windows}
+ Function ADosTimeToWinTime (DosTime:longint;Var Wintime : TFileTime):longbool;
+ var
+  lft : TFileTime;
+ begin
+  ADosTimeToWinTime:=DosDateTimeToFileTime(longrec(DosTime).hi,longrec(DosTime).lo,@lft) and
+                                           LocalFileTimeToFileTime(lft,Wintime);
+ end;
+var
+ FT:TFileTime;
+{$ENDIF}
 begin
+ {$IFDEF WINDOWS}
+   if (ADosTimeToWinTime(Age,FT) and
+    SetFileTime(CreateFileW(PWideChar(UTF8Decode(FileName)),
+                                            FILE_WRITE_ATTRIBUTES,
+                                            0, nil, OPEN_EXISTING,
+                                            FILE_ATTRIBUTE_NORMAL, 0),
+                                            nil, nil, @FT)) then Exit;
+  Result := GetLastError;
+ {$ELSE}
   Result:=SysUtils.FileSetDate(UTF8ToSys(Filename),Age);
+ {$ENDIF}
 end;
 
 function ParamStrUTF8(Param: Integer): string;

Bart Broersma

2012-05-09 18:30

developer   ~0059443

Proposed patch will completely break FileSetDateUTF8() on win9x, since CreateFileW will return an OS error 6 (in Dutch: "De ingang is ongeldig", which probably translates into "Invalid entry") for each and every filename (wether they contain Unicode characters or not).

Takeda Matsuki

2012-05-10 03:53

reporter   ~0059453

Mr. Bart ;

I have a little question :

Is recent stable FPC still support Win9x by default?
If Yes, I would try to check it and might create patch to make it would work on Win9x. ;)

> ... CreateFileW will return an OS error 6 ...

This OS Bugs or my patch?
coz the attched patch, work fine here. I have 3 PCs with Japanese Language, Korean Language, and English.

-Takeda-

Takeda Matsuki

2012-05-10 06:40

reporter   ~0059456

Last edited: 2012-05-10 06:45

Now, I know what Mr. Bart mean and Yes Mr. Bart true -> "... which probably translates into "Invalid entry".. ".

I found UTF8Decode and UTF8Encode which come from FPC higher than 2.6.0/2.6.0a (especially which came from FPC 2.7.1) failed to work (sometime). I test 23 times, sometime UTF8Decode/Encode would give me "?????"

My Directory to test -> " C:\New folder (2)\아이\อยู่ห่างๆอย่างห่วง ๆ ", using UTF8Decode/Encode from FPC higher than 2.6.0/2.6.0a would give me " C:\New folder (2)\????\?????? ".

In my patch ( 2012-05-08 - FileSetDateUTF8 (Patch)2.patch ), I decide to use UTF8ToUTF16, and it working fine. Also, it would work with win9x. ;)

-Takeda-

2012-05-10 06:41

 

2012-05-08 - FileSetDateUTF8 (Patch)2.patch (1,353 bytes)
Index: fileutil.inc
===================================================================
--- fileutil.inc	(revision 37234)
+++ fileutil.inc	(working copy)
@@ -95,9 +95,36 @@
 end;
 
 function FileSetDateUTF8(const FileName: String; Age: Longint): Longint;
+{$IFDEF Windows}
+ {$ifdef WindowsUnicodeSupport}
+ Function ADosTimeToWinTime (DosTime:longint;Var Wintime : TFileTime):longbool;
+ var
+  lft : TFileTime;
+ begin
+  ADosTimeToWinTime:=DosDateTimeToFileTime(longrec(DosTime).hi,longrec(DosTime).lo,@lft) and
+                                           LocalFileTimeToFileTime(lft,Wintime);
+ end;
+var
+ FT:TFileTime;
+  {$endif}
+{$ENDIF}
 begin
+ {$IFDEF WINDOWS}
+  {$ifdef WindowsUnicodeSupport}
+   if (ADosTimeToWinTime(Age,FT) and
+    SetFileTime(CreateFileW(PWideChar(UTF8ToUTF16(FileName)),
+                                            FILE_WRITE_ATTRIBUTES,
+                                            0, nil, OPEN_EXISTING,
+                                            FILE_ATTRIBUTE_NORMAL, 0),
+                                            nil, nil, @FT)) then Exit;
+   Result := GetLastError;
+  {$else}
+   Result:=SysUtils.FileSetDate(UTF8ToSys(Filename),Age);
+  {$endif}
+ {$ELSE}
   Result:=SysUtils.FileSetDate(UTF8ToSys(Filename),Age);
-end;
+ {$ENDIF}
+end;  
 
 function ParamStrUTF8(Param: Integer): string;
 begin

Bart Broersma

2012-05-10 19:28

developer   ~0059472

> Is recent stable FPC still support Win9x by default?
Yes, Win98 and WinMe are still supported.
Win95 is not supported out of the box, it needs patching.

Bart Broersma

2012-05-13 16:27

developer   ~0059563

Second patch at least works on WinMe.

Felipe Monteiro de Carvalho

2012-06-27 09:07

developer   ~0060691

thanks, applied

Issue History

Date Modified Username Field Change
2012-05-08 07:50 Takeda Matsuki New Issue
2012-05-08 07:50 Takeda Matsuki File Added: 2012-05-08 - FileSetDateUTF8 (Patch).patch
2012-05-08 07:50 Takeda Matsuki Widgetset => Win32/Win64
2012-05-09 17:08 Felipe Monteiro de Carvalho Status new => assigned
2012-05-09 17:08 Felipe Monteiro de Carvalho Assigned To => Felipe Monteiro de Carvalho
2012-05-09 18:30 Bart Broersma Note Added: 0059443
2012-05-10 03:53 Takeda Matsuki Note Added: 0059453
2012-05-10 06:40 Takeda Matsuki Note Added: 0059456
2012-05-10 06:41 Takeda Matsuki File Added: 2012-05-08 - FileSetDateUTF8 (Patch)2.patch
2012-05-10 06:42 Takeda Matsuki Note Edited: 0059456
2012-05-10 06:45 Takeda Matsuki Note Edited: 0059456
2012-05-10 19:28 Bart Broersma Note Added: 0059472
2012-05-13 16:27 Bart Broersma Note Added: 0059563
2012-06-27 09:07 Felipe Monteiro de Carvalho Fixed in Revision => 37794
2012-06-27 09:07 Felipe Monteiro de Carvalho LazTarget => -
2012-06-27 09:07 Felipe Monteiro de Carvalho Status assigned => resolved
2012-06-27 09:07 Felipe Monteiro de Carvalho Fixed in Version => 1.1 (SVN)
2012-06-27 09:07 Felipe Monteiro de Carvalho Resolution open => fixed
2012-06-27 09:07 Felipe Monteiro de Carvalho Note Added: 0060691