mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-12-17 05:00:47 +01:00
LazFileUtils: fix FileAgeUTF8 on Windows when FileName contains unicode
characters outside current codepage. git-svn-id: trunk@41287 -
This commit is contained in:
parent
946e76d280
commit
486d00d68c
@ -1064,10 +1064,7 @@ end;
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
function FileAgeUTF8(const FileName: String): Longint;
|
|
||||||
begin
|
|
||||||
Result:=SysUtils.FileAge(UTF8ToSys(Filename));
|
|
||||||
end;
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -46,6 +46,11 @@ begin
|
|||||||
Result:=SysUtils.DirectoryExists(UTF8ToSys(Directory));
|
Result:=SysUtils.DirectoryExists(UTF8ToSys(Directory));
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
function FileAgeUTF8(const FileName: String): Longint;
|
||||||
|
begin
|
||||||
|
Result:=SysUtils.FileAge(UTF8ToSys(Filename));
|
||||||
|
end;
|
||||||
|
|
||||||
function ExpandFileNameUtf8(const FileName: string; {const} BaseDir: String = ''): String;
|
function ExpandFileNameUtf8(const FileName: string; {const} BaseDir: String = ''): String;
|
||||||
var
|
var
|
||||||
IsAbs: Boolean;
|
IsAbs: Boolean;
|
||||||
|
|||||||
@ -4,7 +4,7 @@
|
|||||||
var
|
var
|
||||||
//procedural variables for procedures that are implemented different on Win9x and NT or WinCE platform
|
//procedural variables for procedures that are implemented different on Win9x and NT or WinCE platform
|
||||||
//They are intialized in InitLazFileUtils
|
//They are intialized in InitLazFileUtils
|
||||||
//FileAge_ : function (const Filename:string):Longint;
|
_FileAgeUtf8 : function (const Filename:string):Longint;
|
||||||
//FileSize_ : function (const Filename: string): int64;
|
//FileSize_ : function (const Filename: string): int64;
|
||||||
//FileSetDate_ : function (const FileName: String; Age: Longint): Longint;
|
//FileSetDate_ : function (const FileName: String; Age: Longint): Longint;
|
||||||
//FindFirst_ : function (const Path: string; Attr: Longint;
|
//FindFirst_ : function (const Path: string; Attr: Longint;
|
||||||
@ -203,6 +203,11 @@ begin
|
|||||||
Result := False;
|
Result := False;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
function FileAgeUTF8(const FileName: String): Longint;
|
||||||
|
begin
|
||||||
|
Result := _FileAgeUtf8(FileName);
|
||||||
|
end;
|
||||||
|
|
||||||
|
|
||||||
{******* ANSI functions *******}
|
{******* ANSI functions *******}
|
||||||
|
|
||||||
@ -243,6 +248,13 @@ begin
|
|||||||
end;
|
end;
|
||||||
|
|
||||||
|
|
||||||
|
function FileAgeAnsi(const FileName: String): Longint;
|
||||||
|
begin
|
||||||
|
Result := SysUtils.FileAge(UTF8ToSys(Filename));
|
||||||
|
end;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
{$endif WinCE}
|
{$endif WinCE}
|
||||||
|
|
||||||
|
|
||||||
@ -262,6 +274,28 @@ const
|
|||||||
GENERIC_WRITE,
|
GENERIC_WRITE,
|
||||||
GENERIC_READ or GENERIC_WRITE);
|
GENERIC_READ or GENERIC_WRITE);
|
||||||
|
|
||||||
|
function WinToDosTime(Var Wtime : TFileTime; var DTime:longint):longbool;
|
||||||
|
var
|
||||||
|
lft : TFileTime;
|
||||||
|
begin
|
||||||
|
WinToDosTime:=FileTimeToLocalFileTime(WTime,lft)
|
||||||
|
{$ifndef WinCE}
|
||||||
|
and FileTimeToDosDateTime(lft,Longrec(Dtime).Hi,LongRec(DTIME).lo)
|
||||||
|
{$endif}
|
||||||
|
;
|
||||||
|
end;
|
||||||
|
|
||||||
|
Function DosToWinTime(DosTime:longint; Var Wintime : TFileTime):longbool;
|
||||||
|
var
|
||||||
|
lft : TFileTime;
|
||||||
|
begin
|
||||||
|
DosToWinTime:=
|
||||||
|
{$ifndef wince}
|
||||||
|
DosDateTimeToFileTime(longrec(DosTime).hi,longrec(DosTime).lo,@lft) and
|
||||||
|
{$endif}
|
||||||
|
LocalFileTimeToFileTime(lft,Wintime); ;
|
||||||
|
end;
|
||||||
|
|
||||||
function GetCurrentDirWide: String;
|
function GetCurrentDirWide: String;
|
||||||
var
|
var
|
||||||
w : WideString;
|
w : WideString;
|
||||||
@ -351,6 +385,22 @@ begin
|
|||||||
Result := Integer(Windows.GetLastError);
|
Result := Integer(Windows.GetLastError);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
function FileAgeWide(const FileName: String): Longint;
|
||||||
|
var
|
||||||
|
Hnd: THandle;
|
||||||
|
FindData: TWin32FindDataW;
|
||||||
|
begin
|
||||||
|
Hnd := FindFirstFileW(PWideChar(UTF8ToUTF16(FileName)), FindData);
|
||||||
|
if Hnd <> INVALID_HANDLE_VALUE then
|
||||||
|
begin
|
||||||
|
Windows.FindClose(Hnd);
|
||||||
|
if (FindData.dwFileAttributes and FILE_ATTRIBUTE_DIRECTORY) = 0 then
|
||||||
|
If WinToDosTime(FindData.ftLastWriteTime,Result) then
|
||||||
|
exit;
|
||||||
|
end;
|
||||||
|
Result := -1;
|
||||||
|
end;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
procedure InitLazFileUtils;
|
procedure InitLazFileUtils;
|
||||||
@ -358,7 +408,7 @@ begin
|
|||||||
{$ifndef WinCE}
|
{$ifndef WinCE}
|
||||||
if Win32MajorVersion <= 4 then
|
if Win32MajorVersion <= 4 then
|
||||||
begin
|
begin
|
||||||
//FileAge_ := @FileAgeAnsi;
|
_FileAgeUtf8 := @FileAgeAnsi;
|
||||||
//FileSize_ := @FileSizeAnsi;
|
//FileSize_ := @FileSizeAnsi;
|
||||||
//FileSetDate_ := @FileSetDateAnsi;
|
//FileSetDate_ := @FileSetDateAnsi;
|
||||||
_FileGetAttrUtf8 := @FileGetAttrAnsi;
|
_FileGetAttrUtf8 := @FileGetAttrAnsi;
|
||||||
@ -379,7 +429,7 @@ begin
|
|||||||
else
|
else
|
||||||
{$endif}
|
{$endif}
|
||||||
begin
|
begin
|
||||||
//FileAge_ := @FileAgeWide;
|
_FileAgeUtf8 := @FileAgeWide;
|
||||||
//FileSize_ := @FileSizeWide;
|
//FileSize_ := @FileSizeWide;
|
||||||
//FileSetDate_ := @FileSetDateWide;
|
//FileSetDate_ := @FileSetDateWide;
|
||||||
_FileGetAttrUtf8 := @FileGetAttrWide;
|
_FileGetAttrUtf8 := @FileGetAttrWide;
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user