mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-12-05 09:38:50 +01:00
LazUtils: fix FileSetDateUtf8 for Windows, when file is in a folder with Unicode characters.
Fixes issue: #0023696. Patch based upon efforts of Takeda Matsuki. git-svn-id: trunk@39893 -
This commit is contained in:
parent
60db6ec323
commit
809f049924
@ -89,38 +89,6 @@ begin
|
||||
Result:=SysUtils.ExpandUNCFileName(Filename);
|
||||
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);
|
||||
{$ENDIF}
|
||||
end;
|
||||
|
||||
function ParamStrUTF8(Param: Integer): string;
|
||||
begin
|
||||
Result:=SysToUTF8(ObjPas.ParamStr(Param));
|
||||
|
||||
@ -142,6 +142,14 @@ begin
|
||||
Result:=st.st_size;
|
||||
end;
|
||||
|
||||
{------------------------------------------------------------------------------
|
||||
FileSetDateUTF8
|
||||
------------------------------------------------------------------------------}
|
||||
function FileSetDateUTF8(const FileName: String; Age: Longint): Longint;
|
||||
begin
|
||||
Result:=SysUtils.FileSetDate(UTF8ToSys(Filename),Age);
|
||||
end;
|
||||
|
||||
{------------------------------------------------------------------------------
|
||||
GetFileDescription
|
||||
------------------------------------------------------------------------------}
|
||||
|
||||
@ -263,6 +263,44 @@ begin
|
||||
Windows.FindClose(FindHandle);
|
||||
end;
|
||||
|
||||
{-------------------------------------------------------------------------------
|
||||
FileSetDateUTF8
|
||||
-------------------------------------------------------------------------------}
|
||||
function FileSetDateAnsi(const FileName: String; Age: Longint): Longint;
|
||||
begin
|
||||
Result:=SysUtils.FileSetDate(UTF8ToSys(Filename),Age);
|
||||
end;
|
||||
|
||||
{$ifndef WinCE}
|
||||
function FileSetDateWide(const FileName: String; Age: Longint): Longint;
|
||||
|
||||
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;
|
||||
fh: HANDLE;
|
||||
begin
|
||||
try
|
||||
fh := CreateFileW(PWideChar(UTF8ToUTF16(FileName)),
|
||||
FILE_WRITE_ATTRIBUTES,
|
||||
0, nil, OPEN_EXISTING,
|
||||
FILE_ATTRIBUTE_NORMAL, 0);
|
||||
if (fh <> feInvalidHandle) and (ADosTimeToWinTime(Age,FT) and SetFileTime(fh, nil, nil, @FT)) then
|
||||
Result := 0
|
||||
else
|
||||
Result := GetLastError;
|
||||
finally
|
||||
if (fh <> feInvalidHandle) then FileClose(fh);
|
||||
end;
|
||||
end;
|
||||
{$endif}
|
||||
|
||||
{------------------------------------------------------------------------------
|
||||
FindFirstUTF8
|
||||
------------------------------------------------------------------------------}
|
||||
@ -553,6 +591,7 @@ end;
|
||||
var
|
||||
FileAge_ : function (const Filename:string):Longint = @FileAgeWide;
|
||||
FileSize_ : function (const Filename: string): int64 = @FileSizeWide;
|
||||
FileSetDate_ : function (const FileName: String; Age: Longint): Longint = @FileSetDateWide;
|
||||
FindFirst_ : function (const Path: string; Attr: Longint;
|
||||
out Rslt: TSearchRec): Longint = @FindFirstWide;
|
||||
FindNext_ : function (var Rslt: TSearchRec): Longint = @FindNextWide;
|
||||
@ -581,6 +620,15 @@ begin
|
||||
Result:=FileSize_(FileName);
|
||||
end;
|
||||
|
||||
function FileSetDateUTF8(const FileName: String; Age: Longint): Longint;
|
||||
begin
|
||||
{$ifndef WinCE}
|
||||
Result:=FileSetDate_(FileName, Age);
|
||||
{$else}
|
||||
Result:=SysUtils.FileSetDate(UTF8ToSys(Filename),Age);
|
||||
{$endif}
|
||||
end;
|
||||
|
||||
function FindFirstUTF8(const Path: string; Attr: Longint; out Rslt: TSearchRec): Longint;
|
||||
begin
|
||||
Result:=FindFirst_(Path, Attr, Rslt);
|
||||
@ -733,6 +781,7 @@ begin
|
||||
begin
|
||||
FileAge_:=@FileAgeAnsi;
|
||||
FileSize_:=@FileSizeAnsi;
|
||||
FileSetDate_:=@FileSetDateAnsi;
|
||||
FileGetAttr_:=@FileGetAttrAnsi;
|
||||
FileSetAttr_:=@FileSetAttrAnsi;
|
||||
DeleteFile_:=@DeleteFileAnsi;
|
||||
|
||||
Loading…
Reference in New Issue
Block a user