diff --git a/components/lazutils/fileutil.inc b/components/lazutils/fileutil.inc index 1b46da3936..7318d8929b 100644 --- a/components/lazutils/fileutil.inc +++ b/components/lazutils/fileutil.inc @@ -93,6 +93,11 @@ begin Result := LazFileUtils.FileSizeUtf8(FileName); end; +function GetFileDescription(const AFilename: string): string; +begin + Result := LazFileUtils.GetFileDescription(AFilename); +end; + {$IFDEF darwin} function GetDarwinSystemFilename(Filename: string): string; var diff --git a/components/lazutils/fileutil.pas b/components/lazutils/fileutil.pas index ae4b9bc724..b4a4d5d720 100644 --- a/components/lazutils/fileutil.pas +++ b/components/lazutils/fileutil.pas @@ -81,7 +81,7 @@ function FileIsExecutable(const AFilename: string): boolean; inline; function FileIsSymlink(const AFilename: string): boolean; inline; function FileIsHardLink(const AFilename: string): boolean; inline; function FileSize(const Filename: string): int64; overload; inline; -function GetFileDescription(const AFilename: string): string; +function GetFileDescription(const AFilename: string): string; inline; function ReadAllLinks(const Filename: string; ExceptionOnError: boolean): string; // if a link is broken returns '' function TryReadAllLinks(const Filename: string): string; // if a link is broken returns Filename diff --git a/components/lazutils/lazfileutils.pas b/components/lazutils/lazfileutils.pas index 92ca882383..0975a8ece6 100644 --- a/components/lazutils/lazfileutils.pas +++ b/components/lazutils/lazfileutils.pas @@ -98,6 +98,8 @@ function FileCreateUTF8(Const FileName : string; Rights: Cardinal) : THandle; ov Function FileCreateUtf8(Const FileName : String; ShareMode : Integer; Rights : Cardinal) : THandle; overload; function FileSizeUtf8(const Filename: string): int64; +function GetFileDescription(const AFilename: string): string; + function GetAppConfigDirUTF8(Global: Boolean; Create: boolean = false): string; function GetAppConfigFileUTF8(Global: Boolean; SubDir: boolean = false; diff --git a/components/lazutils/unixfileutil.inc b/components/lazutils/unixfileutil.inc index 5b3c8c2c66..4740317cd6 100644 --- a/components/lazutils/unixfileutil.inc +++ b/components/lazutils/unixfileutil.inc @@ -1,97 +1,6 @@ {%MainUnit fileutil.pas} -{------------------------------------------------------------------------------ - GetFileDescription - ------------------------------------------------------------------------------} -function GetFileDescription(const AFilename: string): string; -var - info: Stat; - // permissions - // user - // group - // size - // date - // time - mode: mode_t; -begin - Result:=''; - if not (FpStat(AFilename,info{%H-})=0) then exit; - - // permissions - // file type - mode:= info.st_mode; - if STAT_IFLNK and mode=STAT_IFLNK then - Result:=Result+'l' - else - if STAT_IFDIR and mode=STAT_IFDIR then - Result:=Result+'d' - else - if STAT_IFBLK and mode=STAT_IFBLK then - Result:=Result+'b' - else - if STAT_IFCHR and mode=STAT_IFCHR then - Result:=Result+'c' - else - Result:=Result+'-'; - // user permissions - if STAT_IRUSR and mode=STAT_IRUsr then - Result:=Result+'r' - else - Result:=Result+'-'; - if STAT_IWUsr and mode=STAT_IWUsr then - Result:=Result+'w' - else - Result:=Result+'-'; - if STAT_IXUsr and mode=STAT_IXUsr then - Result:=Result+'x' - else - Result:=Result+'-'; - // group permissions - if STAT_IRGRP and mode=STAT_IRGRP then - Result:=Result+'r' - else - Result:=Result+'-'; - if STAT_IWGRP and mode=STAT_IWGRP then - Result:=Result+'w' - else - Result:=Result+'-'; - if STAT_IXGRP and mode=STAT_IXGRP then - Result:=Result+'x' - else - Result:=Result+'-'; - // other permissions - if STAT_IROTH and mode=STAT_IROTH then - Result:=Result+'r' - else - Result:=Result+'-'; - if STAT_IWOTH and mode=STAT_IWOTH then - Result:=Result+'w' - else - Result:=Result+'-'; - if STAT_IXOTH and mode=STAT_IXOTH then - Result:=Result+'x' - else - Result:=Result+'-'; - - - // user name - //Result:=Result+' Owner: '+IntToStr(info.uid)+'.'+IntToStr(info.gid); - - // size - Result:=Result+lrsSize+IntToStr(info.st_size); - - // date + time - Result:=Result+lrsModified; - try - Result:=Result+FormatDateTime('DD/MM/YYYY hh:mm', - FileDateToDateTime(FileAgeUTF8(AFilename))); - except - Result:=Result+'?'; - end; -end; - - {------------------------------------------------------------------------------ function ReadAllLinks(const Filename: string; ExceptionOnError: boolean): string; diff --git a/components/lazutils/unixlazfileutils.inc b/components/lazutils/unixlazfileutils.inc index 067127c17d..0b13e7d9a4 100644 --- a/components/lazutils/unixlazfileutils.inc +++ b/components/lazutils/unixlazfileutils.inc @@ -275,6 +275,92 @@ begin Result := ''; end; +function GetFileDescription(const AFilename: string): string; +var + info: Stat; + // permissions + // user + // group + // size + // date + // time + mode: mode_t; +begin + Result:=''; + if not (FpStat(AFilename,info{%H-})=0) then exit; + + // permissions + // file type + mode:= info.st_mode; + if STAT_IFLNK and mode=STAT_IFLNK then + Result:=Result+'l' + else + if STAT_IFDIR and mode=STAT_IFDIR then + Result:=Result+'d' + else + if STAT_IFBLK and mode=STAT_IFBLK then + Result:=Result+'b' + else + if STAT_IFCHR and mode=STAT_IFCHR then + Result:=Result+'c' + else + Result:=Result+'-'; + // user permissions + if STAT_IRUSR and mode=STAT_IRUsr then + Result:=Result+'r' + else + Result:=Result+'-'; + if STAT_IWUsr and mode=STAT_IWUsr then + Result:=Result+'w' + else + Result:=Result+'-'; + if STAT_IXUsr and mode=STAT_IXUsr then + Result:=Result+'x' + else + Result:=Result+'-'; + // group permissions + if STAT_IRGRP and mode=STAT_IRGRP then + Result:=Result+'r' + else + Result:=Result+'-'; + if STAT_IWGRP and mode=STAT_IWGRP then + Result:=Result+'w' + else + Result:=Result+'-'; + if STAT_IXGRP and mode=STAT_IXGRP then + Result:=Result+'x' + else + Result:=Result+'-'; + // other permissions + if STAT_IROTH and mode=STAT_IROTH then + Result:=Result+'r' + else + Result:=Result+'-'; + if STAT_IWOTH and mode=STAT_IWOTH then + Result:=Result+'w' + else + Result:=Result+'-'; + if STAT_IXOTH and mode=STAT_IXOTH then + Result:=Result+'x' + else + Result:=Result+'-'; + + + // user name + //Result:=Result+' Owner: '+IntToStr(info.uid)+'.'+IntToStr(info.gid); + + // size + Result:=Result+lrsSize+IntToStr(info.st_size); + + // date + time + Result:=Result+lrsModified; + try + Result:=Result+FormatDateTime('DD/MM/YYYY hh:mm', + FileDateToDateTime(FileAgeUTF8(AFilename))); + except + Result:=Result+'?'; + end; +end; procedure InitLazFileUtils; diff --git a/components/lazutils/winfileutil.inc b/components/lazutils/winfileutil.inc index 191dbc7bba..ffc09fddab 100644 --- a/components/lazutils/winfileutil.inc +++ b/components/lazutils/winfileutil.inc @@ -1,20 +1,7 @@ {%MainUnit fileutil.pas} -{------------------------------------------------------------------------------ - GetFileDescription - ------------------------------------------------------------------------------} -function GetFileDescription(const AFilename: string): string; -begin - // date + time - Result:=lrsModified; - try - Result:=Result+FormatDateTime('DD/MM/YYYY hh:mm', - FileDateToDateTime(FileAgeUTF8(AFilename))); - except - Result:=Result+'?'; - end; -end; + {------------------------------------------------------------------------------ function ReadAllLinks(const Filename: string; diff --git a/components/lazutils/winlazfileutils.inc b/components/lazutils/winlazfileutils.inc index 82c4a0d4d9..d4b87310e6 100644 --- a/components/lazutils/winlazfileutils.inc +++ b/components/lazutils/winlazfileutils.inc @@ -844,6 +844,18 @@ begin Result := Copy(Path, 1, I); end; +function GetFileDescription(const AFilename: string): string; +begin + // date + time + Result:=lrsModified; + try + Result:=Result+FormatDateTime('DD/MM/YYYY hh:mm', + FileDateToDateTime(FileAgeUTF8(AFilename))); + except + Result:=Result+'?'; + end; +end; +