Skip to content

Commit

Permalink
[Files] Linux fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
exilon committed Mar 17, 2023
1 parent 6f729e6 commit 9254b1c
Showing 1 changed file with 30 additions and 0 deletions.
30 changes: 30 additions & 0 deletions Quick.Files.pas
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,9 @@ TDirItem = record
function FindDelimiter(const Delimiters, S: string; StartIdx: Integer = 1): Integer;
{$ENDIF}
function ConvertDateTimeToFileTime(const DateTime: TDateTime; const UseLocalTimeZone: Boolean): TFileTime;
{$IFDEF MSWINDOWS}
function ConvertFileTimeToDateTime(const FileTime : TFileTime; const UseLocalTimeZone : Boolean) : TDateTime;
{$ENDIF}
procedure SetDateTimeInfo(const Path: string; const CreationTime, LastAccessTime, LastWriteTime: PDateTime; const UseLocalTimeZone: Boolean);
function GetFiles(const Path : string; Recursive : Boolean) : TArray<TDirItem>; overload;
procedure GetFiles(const Path : string; aAddToList : TDirItemAddProc; Recursive : Boolean); overload;
Expand Down Expand Up @@ -1309,8 +1311,12 @@ function GetFiles(const Path : string; Recursive : Boolean) : TArray<TDirItem>;
diritem.Name := rec.Name;
diritem.IsDirectory := False;
diritem.Size := rec.Size;
{$IFNDEF LINUX}
diritem.CreationDate := ConvertFileTimeToDateTime(rec.FindData.ftCreationTime,True);
diritem.LastModified := ConvertFileTimeToDateTime(rec.FindData.ftLastWriteTime,True);
{$ELSE}
diritem.CreationDate := FileDateToDateTime(rec.Time);
{$ENDIF}
Result := Result + [diritem];
end
else
Expand All @@ -1336,8 +1342,12 @@ procedure GetFiles(const Path : string; aAddToList : TDirItemAddProc; Recursive
diritem.Name := rec.Name;
diritem.IsDirectory := False;
diritem.Size := rec.Size;
{$IFNDEF LINUX}
diritem.CreationDate := ConvertFileTimeToDateTime(rec.FindData.ftCreationTime,True);
diritem.LastModified := ConvertFileTimeToDateTime(rec.FindData.ftLastWriteTime,True);
{$ELSE}
diritem.CreationDate := FileDateToDateTime(rec.Time);
{$ENDIF}
aAddToList(diritem);
end
else
Expand All @@ -1363,8 +1373,12 @@ function GetDirectories(const Path : string; Recursive : Boolean) : TArray<TDirI
diritem.Name := rec.Name;
diritem.IsDirectory := True;
diritem.Size := rec.Size;
{$IFNDEF LINUX}
diritem.CreationDate := ConvertFileTimeToDateTime(rec.FindData.ftCreationTime,True);
diritem.LastModified := ConvertFileTimeToDateTime(rec.FindData.ftLastWriteTime,True);
{$ELSE}
diritem.CreationDate := FileDateToDateTime(rec.Time);
{$ENDIF}
Result := Result + [diritem];
if Recursive then Result := Result + GetFiles(IncludeTrailingPathDelimiter(Path) + diritem.Name,Recursive);
end;
Expand Down Expand Up @@ -1402,17 +1416,25 @@ function GetFilesAndDirectories(const Path : string; Recursive : Boolean) : TArr
diritem.Name := rec.Name;
diritem.IsDirectory := False;
diritem.Size := rec.Size;
{$IFNDEF LINUX}
diritem.CreationDate := ConvertFileTimeToDateTime(rec.FindData.ftCreationTime,True);
diritem.LastModified := ConvertFileTimeToDateTime(rec.FindData.ftLastWriteTime,True);
{$ELSE}
diritem.CreationDate := FileDateToDateTime(rec.Time);
{$ENDIF}
Result := Result + [diritem];
end
else if (rec.Name <> '.') and (rec.Name <> '..') then
begin
diritem.Name := rec.Name;
diritem.IsDirectory := True;
diritem.Size := rec.Size;
{$IFNDEF LINUX}
diritem.CreationDate := ConvertFileTimeToDateTime(rec.FindData.ftCreationTime,True);
diritem.LastModified := ConvertFileTimeToDateTime(rec.FindData.ftLastWriteTime,True);
{$ELSE}
diritem.CreationDate := FileDateToDateTime(rec.Time);
{$ENDIF}
Result := Result + [diritem];
if Recursive then Result := Result + GetFilesAndDirectories(dirpath + diritem.Name,Recursive);
end;
Expand Down Expand Up @@ -1452,17 +1474,25 @@ procedure GetFilesAndDirectories(const Path : string; aAddToList : TDirItemAddPr
diritem.Name := rec.Name;
diritem.IsDirectory := False;
diritem.Size := rec.Size;
{$IFNDEF LINUX}
diritem.CreationDate := ConvertFileTimeToDateTime(rec.FindData.ftCreationTime,True);
diritem.LastModified := ConvertFileTimeToDateTime(rec.FindData.ftLastWriteTime,True);
{$ELSE}
diritem.CreationDate := FileDateToDateTime(rec.Time);
{$ENDIF}
aAddToList(diritem);
end
else if (rec.Name <> '.') and (rec.Name <> '..') then
begin
diritem.Name := rec.Name;
diritem.IsDirectory := True;
diritem.Size := rec.Size;
{$IFNDEF LINUX}
diritem.CreationDate := ConvertFileTimeToDateTime(rec.FindData.ftCreationTime,True);
diritem.LastModified := ConvertFileTimeToDateTime(rec.FindData.ftLastWriteTime,True);
{$ELSE}
diritem.CreationDate := FileDateToDateTime(rec.Time);
{$ENDIF}
aAddToList(diritem);
if Recursive then GetFilesAndDirectories(dirpath + diritem.Name,aAddToList,Recursive);
end;
Expand Down

0 comments on commit 9254b1c

Please sign in to comment.