mirror of
https://github.com/doublecmd/doublecmd.git
synced 2026-06-21 09:58:13 +00:00
FIX: Compiling under Windows 64 bit
This commit is contained in:
parent
50ced3fc6d
commit
ac12dbabc4
7 changed files with 2248 additions and 2246 deletions
|
|
@ -128,7 +128,7 @@ procedure Register;
|
|||
|
||||
implementation
|
||||
uses
|
||||
Clipbrd{$IFNDEF WIN32}, Libc, unix{$ELSE}, Windows{$ENDIF};
|
||||
Clipbrd{$IFDEF UNIX}, Libc, unix{$ELSE}, Windows{$ENDIF};
|
||||
|
||||
const
|
||||
cTextWidth=80; // wrap on 80 chars
|
||||
|
|
@ -401,7 +401,7 @@ end;
|
|||
|
||||
|
||||
Function TViewerControl.MapFile(const sFileName:String):Boolean;
|
||||
{$IFDEF WIN32}
|
||||
{$IFDEF MSWINDOWS}
|
||||
var
|
||||
wFileName: WideString;
|
||||
begin
|
||||
|
|
@ -469,7 +469,7 @@ end;
|
|||
{$ENDIF}
|
||||
|
||||
procedure TViewerControl.UnMapFile;
|
||||
{$IFDEF WIN32}
|
||||
{$IFDEF MSWINDOWS}
|
||||
begin
|
||||
if Assigned(FMappedFile) then
|
||||
UnmapViewOfFile(FMappedFile);
|
||||
|
|
@ -670,7 +670,7 @@ begin
|
|||
end;
|
||||
|
||||
Function TViewerControl.LoadFromStdin(const sCmd:String):Boolean;
|
||||
{$IFDEF WIN32}
|
||||
{$IFDEF MSWINDOWS}
|
||||
begin
|
||||
|
||||
end;
|
||||
|
|
|
|||
|
|
@ -59,7 +59,7 @@ uses
|
|||
dmDialogs, fViewer, fOptions, fCopyDlg, fMoveDlg, fFindDlg,
|
||||
fSymLink, fMultiRename, fSplitter, fPackDlg, fExtractDlg;
|
||||
|
||||
{$IFDEF MSWINDOWS}
|
||||
{$IFDEF WIN32}
|
||||
{$R XP.res}
|
||||
{$ENDIF}
|
||||
|
||||
|
|
|
|||
574
ufileop.pas
574
ufileop.pas
|
|
@ -1,287 +1,287 @@
|
|||
{
|
||||
Seksi Commander
|
||||
----------------------------
|
||||
Licence : GNU GPL v 2.0
|
||||
Author : radek.cervinka@centrum.cz
|
||||
|
||||
contributors:
|
||||
|
||||
Peter Cernoch 2002, pcernoch@volny.cz
|
||||
|
||||
Martin Matusu, xmat@volny.cz
|
||||
|
||||
Alexander Koblov (Alexx2000@mail.ru)
|
||||
|
||||
}
|
||||
|
||||
unit uFileOp;
|
||||
{$mode objfpc}{$H+}
|
||||
interface
|
||||
uses
|
||||
uFileList, uTypes,lclproc;
|
||||
|
||||
Function LoadFilebyName(const sFileName:String):TFileRecItem;
|
||||
Function LoadFilesbyDir(const sDir:String; fl:TFileList):Boolean;
|
||||
Function AttrToStr(iAttr:Cardinal):String;
|
||||
|
||||
//Function IsDirByName(const sName:String):Boolean;
|
||||
|
||||
const
|
||||
__S_IFMT = $F000;
|
||||
__S_IFDIR = $4000;
|
||||
__S_IFCHR = $2000;
|
||||
__S_IFBLK = $6000;
|
||||
__S_IFREG = $8000;
|
||||
__S_IFIFO = $1000;
|
||||
__S_IFLNK = $A000;
|
||||
__S_IFSOCK = $C000;
|
||||
|
||||
__S_ISUID = $800;
|
||||
__S_ISGID = $400;
|
||||
__S_ISVTX = $200;
|
||||
__S_IREAD = $100;
|
||||
__S_IWRITE = $80;
|
||||
__S_IEXEC = $40;
|
||||
|
||||
S_ISUID = __S_ISUID;
|
||||
S_ISGID = __S_ISGID;
|
||||
S_ISVTX = __S_ISVTX;
|
||||
|
||||
implementation
|
||||
uses
|
||||
SysUtils, uFileProcs, uFindEx, uGlobs, uOSUtils {$IFNDEF WIN32}, uUsersGroups, Unix, BaseUnix{$ENDIF};
|
||||
|
||||
{$IFNDEF WIN32} // *nix
|
||||
Function IsDirByName(const sName:String):Boolean;
|
||||
var
|
||||
stat:stat64;
|
||||
begin
|
||||
fpStat64(PChar(sName),stat);
|
||||
Result:=FPS_ISDIR(stat.st_mode);
|
||||
end;
|
||||
{$ENDIF}
|
||||
|
||||
Function LoadFilebyName(const sFileName:String):TFileRecItem;
|
||||
var
|
||||
fr:TFileRecItem;
|
||||
sr:TSearchRec;
|
||||
sb: stat64; //buffer for stat64
|
||||
|
||||
begin
|
||||
// writeln('Enter LoadFilesbyDir');
|
||||
DebugLn('LoadFileByName SFileName = '+sFileName);
|
||||
if FindFirstEx(sFileName,faAnyFile,sr)<>0 then
|
||||
begin DebugLn('FindFirst <> 0');
|
||||
with fr do // append "blank dir"
|
||||
begin
|
||||
fr.sName:='';
|
||||
fr.sNameNoExt:='';
|
||||
fr.sExt:='';
|
||||
fr.iDirSize:=0;
|
||||
fr.iMode:=0;
|
||||
fr.bExecutable:=False;
|
||||
fr.bSysFile := False;
|
||||
fr.bIsLink:=False;
|
||||
fr.sLinkTo:='';
|
||||
fr.bLinkIsDir:=False;
|
||||
fr.bSelected:=False;
|
||||
fr.sModeStr:='';
|
||||
fr.iSize:=0;
|
||||
Result:=fr
|
||||
end;
|
||||
FindClose(sr);
|
||||
Exit;
|
||||
end;
|
||||
// repeat
|
||||
|
||||
{$IFNDEF WIN32} // *nix
|
||||
Fplstat64(sr.Name,sb);
|
||||
fr.iSize:=sb.st_size;
|
||||
|
||||
fr.iOwner:=sb.st_uid; //UID
|
||||
fr.iGroup:=sb.st_gid; //GID
|
||||
fr.sOwner:=UIDToStr(fr.iOwner);
|
||||
fr.sGroup:=GIDToStr(fr.iGroup);
|
||||
{/mate}
|
||||
fr.iMode:=sb.st_mode;
|
||||
fr.bSysFile := (sr.Name[1] = '.') and (sr.Name <> '..');
|
||||
fr.fTimeI:= FileDateToDateTime(sb.st_mtime); // EncodeDate (1970, 1, 1) + (sr.Time / 86400.0);
|
||||
{$ELSE} // Windows
|
||||
fr.iSize:= sr.Size;
|
||||
fr.iMode:= sr.Attr;
|
||||
fr.bSysFile := Boolean(sr.Attr and faSysFile) or Boolean(sr.Attr and faHidden);
|
||||
fr.fTimeI:= FileDateToDateTime(sr.Time);
|
||||
{$ENDIF}
|
||||
|
||||
if FPS_ISDIR(fr.iMode) or (sr.Name[1]='.') then //!!!!!
|
||||
fr.sExt:=''
|
||||
else
|
||||
fr.sExt:=ExtractFileExt(sr.Name);
|
||||
fr.sNameNoExt:=Copy(sr.Name,1,length(sr.Name)-length(fr.sExt));
|
||||
fr.sName:=sr.Name;
|
||||
|
||||
fr.sTime := FormatDateTime(gDateTimeFormat, fr.fTimeI);
|
||||
fr.bIsLink:=FPS_ISLNK(fr.iMode);
|
||||
fr.sLinkTo:='';
|
||||
fr.iDirSize:=0;
|
||||
|
||||
if fr.bIsLink then
|
||||
begin
|
||||
fr.sLinkTo:=ReadSymLink(sr.Name);
|
||||
end;
|
||||
{$IFDEF UNIX} // *nix
|
||||
if fr.bIsLink then
|
||||
fr.bLinkIsDir:=IsDirByName(fr.sLinkTo)
|
||||
else
|
||||
fr.bLinkIsDir:=False;
|
||||
fr.bExecutable:=(not FPS_ISDIR(fr.iMode)) and (fr.iMode AND (S_IXUSR OR S_IXGRP OR S_IXOTH)>0);
|
||||
{$ELSE} // Windows for ShellExecute
|
||||
fr.bExecutable:= not FPS_ISDIR(fr.iMode);
|
||||
if fr.bIsLink then
|
||||
fr.bLinkIsDir:=True //Because symbolic link works on Windows 2k/XP for directories only
|
||||
else
|
||||
fr.bLinkIsDir:=False;
|
||||
{$ENDIF}
|
||||
fr.bSelected:=False;
|
||||
fr.sModeStr:=AttrToStr(fr.iMode);
|
||||
fr.sPath := ExtractFilePath(fr.sName);
|
||||
Result:=fr;
|
||||
// until FindNext(sr)<>0;
|
||||
FindClose(sr);
|
||||
end;
|
||||
|
||||
|
||||
Function LoadFilesbyDir(const sDir:String; fl:TFileList):Boolean;
|
||||
var
|
||||
fr:TFileRecItem;
|
||||
sr:TSearchRec;
|
||||
sb: stat64; //buffer for stat64
|
||||
|
||||
begin
|
||||
// writeln('Enter LoadFilesbyDir');
|
||||
Result:=True;
|
||||
fl.Clear;
|
||||
fl.CurrentDirectory := IncludeTrailingPathDelimiter(sDir);
|
||||
if FindFirstEx('*',faAnyFile,sr)<>0 then
|
||||
begin
|
||||
with fr do // append "blank dir"
|
||||
begin
|
||||
fr.sName:='..';
|
||||
fr.sNameNoExt:='..';
|
||||
fr.sExt:='';
|
||||
fr.iDirSize:=0;
|
||||
fr.iMode:=0;
|
||||
fr.bExecutable:=False;
|
||||
fr.bSysFile := False;
|
||||
fr.bIsLink:=False;
|
||||
fr.sLinkTo:='';
|
||||
fr.bLinkIsDir:=False;
|
||||
fr.bSelected:=False;
|
||||
fr.sModeStr:='';
|
||||
fr.iSize:=0;
|
||||
fl.AddItem(@fr);
|
||||
end;
|
||||
FindClose(sr);
|
||||
Exit;
|
||||
end;
|
||||
repeat
|
||||
if sr.Name='.' then Continue;
|
||||
if ((sDir=DirectorySeparator) or (sDir=(ExtractFileDrive(sDir)+PathDelim))) and (sr.Name='..') then Continue;
|
||||
if sr.Name='' then Continue;
|
||||
|
||||
{$IFNDEF WIN32} // *nix
|
||||
Fplstat64(sr.Name,sb);
|
||||
fr.iSize:=sb.st_size;
|
||||
|
||||
fr.iOwner:=sb.st_uid; //UID
|
||||
fr.iGroup:=sb.st_gid; //GID
|
||||
fr.sOwner:=UIDToStr(fr.iOwner);
|
||||
fr.sGroup:=GIDToStr(fr.iGroup);
|
||||
{/mate}
|
||||
fr.iMode:=sb.st_mode;
|
||||
fr.bSysFile := (sr.Name[1] = '.') and (sr.Name <> '..');
|
||||
fr.fTimeI:= FileDateToDateTime(sb.st_mtime); // EncodeDate (1970, 1, 1) + (sr.Time / 86400.0);
|
||||
{$ELSE} // Windows
|
||||
fr.iSize:= sr.Size;
|
||||
fr.iMode:= sr.Attr;
|
||||
fr.bSysFile := Boolean(sr.Attr and faSysFile) or Boolean(sr.Attr and faHidden);
|
||||
fr.fTimeI:= FileDateToDateTime(sr.Time);
|
||||
{$ENDIF}
|
||||
|
||||
if FPS_ISDIR(fr.iMode) or (sr.Name[1]='.') then //!!!!!
|
||||
fr.sExt:=''
|
||||
else
|
||||
fr.sExt:=ExtractFileExt(sr.Name);
|
||||
fr.sNameNoExt:=Copy(sr.Name,1,length(sr.Name)-length(fr.sExt));
|
||||
fr.sName:=sr.Name;
|
||||
|
||||
fr.sTime := FormatDateTime(gDateTimeFormat, fr.fTimeI);
|
||||
fr.bIsLink:=FPS_ISLNK(fr.iMode);
|
||||
fr.sLinkTo:='';
|
||||
fr.iDirSize:=0;
|
||||
|
||||
if fr.bIsLink then
|
||||
begin
|
||||
fr.sLinkTo:=ReadSymLink(sr.Name);
|
||||
end;
|
||||
{$IFDEF UNIX} // *nix
|
||||
if fr.bIsLink then
|
||||
fr.bLinkIsDir:=IsDirByName(fr.sLinkTo)
|
||||
else
|
||||
fr.bLinkIsDir:=False;
|
||||
fr.bExecutable:=(not FPS_ISDIR(fr.iMode)) and (fr.iMode AND (S_IXUSR OR S_IXGRP OR S_IXOTH)>0);
|
||||
{$ELSE} // Windows for ShellExecute
|
||||
fr.bExecutable:= not FPS_ISDIR(fr.iMode);
|
||||
if fr.bIsLink then
|
||||
fr.bLinkIsDir:=True //Because symbolic link works on Windows 2k/XP for directories only
|
||||
else
|
||||
fr.bLinkIsDir:=False;
|
||||
{$ENDIF}
|
||||
fr.bSelected:=False;
|
||||
fr.sModeStr:=AttrToStr(fr.iMode);
|
||||
fr.sPath := sDir;
|
||||
fl.AddItem(@fr);
|
||||
until FindNextEx(sr)<>0;
|
||||
FindClose(sr);
|
||||
Result:=True;
|
||||
end;
|
||||
|
||||
Function AttrToStr(iAttr:Cardinal):String;
|
||||
begin
|
||||
Result := '----------';
|
||||
|
||||
{$IFDEF WIN32}
|
||||
|
||||
if FPS_ISDIR(iAttr) then Result[1]:='d';
|
||||
if FPS_ISLNK(iAttr) then Result[1]:='l';
|
||||
|
||||
if Boolean(iAttr and $01) then Result[2] := 'r';
|
||||
if Boolean(iAttr and $20) then Result[3] := 'a';
|
||||
if Boolean(iAttr and $02) then Result[4] := 'h';
|
||||
if Boolean(iAttr and $04) then Result[5] := 's';
|
||||
if Boolean(iAttr and $08) then Result[6] := 'v';
|
||||
|
||||
{$ELSE}
|
||||
if FPS_ISDIR(iAttr) then Result[1]:='d';
|
||||
if FPS_ISLNK(iAttr) then Result[1]:='l';
|
||||
if FPS_ISSOCK(iAttr) then Result[1]:='s';
|
||||
if FPS_ISFIFO(iAttr) then Result[1]:='f';
|
||||
if FPS_ISBLK(iAttr) then Result[1]:='b';
|
||||
if FPS_ISCHR(iAttr) then Result[1]:='c';
|
||||
|
||||
if ((iAttr AND S_IRUSR) = S_IRUSR) then Result[2] := 'r';
|
||||
if ((iAttr AND S_IWUSR) = S_IWUSR) then Result[3] := 'w';
|
||||
if ((iAttr AND S_IXUSR) = S_IXUSR) then Result[4] := 'x';
|
||||
if ((iAttr AND S_IRGRP) = S_IRGRP) then Result[5] := 'r';
|
||||
if ((iAttr AND S_IWGRP) = S_IWGRP) then Result[6] := 'w';
|
||||
if ((iAttr AND S_IXGRP) = S_IXGRP) then Result[7] := 'x';
|
||||
if ((iAttr AND S_IROTH) = S_IROTH) then Result[8] := 'r';
|
||||
if ((iAttr AND S_IWOTH) = S_IWOTH) then Result[9] := 'w';
|
||||
if ((iAttr AND S_IXOTH) = S_IXOTH) then Result[10] := 'x';
|
||||
|
||||
if ((iAttr AND S_ISUID) = S_ISUID) then Result[4] := 's';
|
||||
if ((iAttr AND S_ISGID) = S_ISGID) then Result[7] := 's';
|
||||
{$ENDIF}
|
||||
end;
|
||||
|
||||
end.
|
||||
{
|
||||
Seksi Commander
|
||||
----------------------------
|
||||
Licence : GNU GPL v 2.0
|
||||
Author : radek.cervinka@centrum.cz
|
||||
|
||||
contributors:
|
||||
|
||||
Peter Cernoch 2002, pcernoch@volny.cz
|
||||
|
||||
Martin Matusu, xmat@volny.cz
|
||||
|
||||
Alexander Koblov (Alexx2000@mail.ru)
|
||||
|
||||
}
|
||||
|
||||
unit uFileOp;
|
||||
{$mode objfpc}{$H+}
|
||||
interface
|
||||
uses
|
||||
uFileList, uTypes,lclproc;
|
||||
|
||||
Function LoadFilebyName(const sFileName:String):TFileRecItem;
|
||||
Function LoadFilesbyDir(const sDir:String; fl:TFileList):Boolean;
|
||||
Function AttrToStr(iAttr:Cardinal):String;
|
||||
|
||||
//Function IsDirByName(const sName:String):Boolean;
|
||||
|
||||
const
|
||||
__S_IFMT = $F000;
|
||||
__S_IFDIR = $4000;
|
||||
__S_IFCHR = $2000;
|
||||
__S_IFBLK = $6000;
|
||||
__S_IFREG = $8000;
|
||||
__S_IFIFO = $1000;
|
||||
__S_IFLNK = $A000;
|
||||
__S_IFSOCK = $C000;
|
||||
|
||||
__S_ISUID = $800;
|
||||
__S_ISGID = $400;
|
||||
__S_ISVTX = $200;
|
||||
__S_IREAD = $100;
|
||||
__S_IWRITE = $80;
|
||||
__S_IEXEC = $40;
|
||||
|
||||
S_ISUID = __S_ISUID;
|
||||
S_ISGID = __S_ISGID;
|
||||
S_ISVTX = __S_ISVTX;
|
||||
|
||||
implementation
|
||||
uses
|
||||
SysUtils, uFileProcs, uFindEx, uGlobs, uOSUtils {$IFDEF UNIX}, uUsersGroups, Unix, BaseUnix{$ENDIF};
|
||||
|
||||
{$IFDEF UNIX} // *nix
|
||||
Function IsDirByName(const sName:String):Boolean;
|
||||
var
|
||||
stat:stat64;
|
||||
begin
|
||||
fpStat64(PChar(sName),stat);
|
||||
Result:=FPS_ISDIR(stat.st_mode);
|
||||
end;
|
||||
{$ENDIF}
|
||||
|
||||
Function LoadFilebyName(const sFileName:String):TFileRecItem;
|
||||
var
|
||||
fr:TFileRecItem;
|
||||
sr:TSearchRec;
|
||||
sb: stat64; //buffer for stat64
|
||||
|
||||
begin
|
||||
// writeln('Enter LoadFilesbyDir');
|
||||
DebugLn('LoadFileByName SFileName = '+sFileName);
|
||||
if FindFirstEx(sFileName,faAnyFile,sr)<>0 then
|
||||
begin DebugLn('FindFirst <> 0');
|
||||
with fr do // append "blank dir"
|
||||
begin
|
||||
fr.sName:='';
|
||||
fr.sNameNoExt:='';
|
||||
fr.sExt:='';
|
||||
fr.iDirSize:=0;
|
||||
fr.iMode:=0;
|
||||
fr.bExecutable:=False;
|
||||
fr.bSysFile := False;
|
||||
fr.bIsLink:=False;
|
||||
fr.sLinkTo:='';
|
||||
fr.bLinkIsDir:=False;
|
||||
fr.bSelected:=False;
|
||||
fr.sModeStr:='';
|
||||
fr.iSize:=0;
|
||||
Result:=fr
|
||||
end;
|
||||
FindClose(sr);
|
||||
Exit;
|
||||
end;
|
||||
// repeat
|
||||
|
||||
{$IFDEF UNIX} // *nix
|
||||
Fplstat64(sr.Name,sb);
|
||||
fr.iSize:=sb.st_size;
|
||||
|
||||
fr.iOwner:=sb.st_uid; //UID
|
||||
fr.iGroup:=sb.st_gid; //GID
|
||||
fr.sOwner:=UIDToStr(fr.iOwner);
|
||||
fr.sGroup:=GIDToStr(fr.iGroup);
|
||||
{/mate}
|
||||
fr.iMode:=sb.st_mode;
|
||||
fr.bSysFile := (sr.Name[1] = '.') and (sr.Name <> '..');
|
||||
fr.fTimeI:= FileDateToDateTime(sb.st_mtime); // EncodeDate (1970, 1, 1) + (sr.Time / 86400.0);
|
||||
{$ELSE} // Windows
|
||||
fr.iSize:= sr.Size;
|
||||
fr.iMode:= sr.Attr;
|
||||
fr.bSysFile := Boolean(sr.Attr and faSysFile) or Boolean(sr.Attr and faHidden);
|
||||
fr.fTimeI:= FileDateToDateTime(sr.Time);
|
||||
{$ENDIF}
|
||||
|
||||
if FPS_ISDIR(fr.iMode) or (sr.Name[1]='.') then //!!!!!
|
||||
fr.sExt:=''
|
||||
else
|
||||
fr.sExt:=ExtractFileExt(sr.Name);
|
||||
fr.sNameNoExt:=Copy(sr.Name,1,length(sr.Name)-length(fr.sExt));
|
||||
fr.sName:=sr.Name;
|
||||
|
||||
fr.sTime := FormatDateTime(gDateTimeFormat, fr.fTimeI);
|
||||
fr.bIsLink:=FPS_ISLNK(fr.iMode);
|
||||
fr.sLinkTo:='';
|
||||
fr.iDirSize:=0;
|
||||
|
||||
if fr.bIsLink then
|
||||
begin
|
||||
fr.sLinkTo:=ReadSymLink(sr.Name);
|
||||
end;
|
||||
{$IFDEF UNIX} // *nix
|
||||
if fr.bIsLink then
|
||||
fr.bLinkIsDir:=IsDirByName(fr.sLinkTo)
|
||||
else
|
||||
fr.bLinkIsDir:=False;
|
||||
fr.bExecutable:=(not FPS_ISDIR(fr.iMode)) and (fr.iMode AND (S_IXUSR OR S_IXGRP OR S_IXOTH)>0);
|
||||
{$ELSE} // Windows for ShellExecute
|
||||
fr.bExecutable:= not FPS_ISDIR(fr.iMode);
|
||||
if fr.bIsLink then
|
||||
fr.bLinkIsDir:=True //Because symbolic link works on Windows 2k/XP for directories only
|
||||
else
|
||||
fr.bLinkIsDir:=False;
|
||||
{$ENDIF}
|
||||
fr.bSelected:=False;
|
||||
fr.sModeStr:=AttrToStr(fr.iMode);
|
||||
fr.sPath := ExtractFilePath(fr.sName);
|
||||
Result:=fr;
|
||||
// until FindNext(sr)<>0;
|
||||
FindClose(sr);
|
||||
end;
|
||||
|
||||
|
||||
Function LoadFilesbyDir(const sDir:String; fl:TFileList):Boolean;
|
||||
var
|
||||
fr:TFileRecItem;
|
||||
sr:TSearchRec;
|
||||
sb: stat64; //buffer for stat64
|
||||
|
||||
begin
|
||||
// writeln('Enter LoadFilesbyDir');
|
||||
Result:=True;
|
||||
fl.Clear;
|
||||
fl.CurrentDirectory := IncludeTrailingPathDelimiter(sDir);
|
||||
if FindFirstEx('*',faAnyFile,sr)<>0 then
|
||||
begin
|
||||
with fr do // append "blank dir"
|
||||
begin
|
||||
fr.sName:='..';
|
||||
fr.sNameNoExt:='..';
|
||||
fr.sExt:='';
|
||||
fr.iDirSize:=0;
|
||||
fr.iMode:=0;
|
||||
fr.bExecutable:=False;
|
||||
fr.bSysFile := False;
|
||||
fr.bIsLink:=False;
|
||||
fr.sLinkTo:='';
|
||||
fr.bLinkIsDir:=False;
|
||||
fr.bSelected:=False;
|
||||
fr.sModeStr:='';
|
||||
fr.iSize:=0;
|
||||
fl.AddItem(@fr);
|
||||
end;
|
||||
FindClose(sr);
|
||||
Exit;
|
||||
end;
|
||||
repeat
|
||||
if sr.Name='.' then Continue;
|
||||
if ((sDir=DirectorySeparator) or (sDir=(ExtractFileDrive(sDir)+PathDelim))) and (sr.Name='..') then Continue;
|
||||
if sr.Name='' then Continue;
|
||||
|
||||
{$IFDEF UNIX} // *nix
|
||||
Fplstat64(sr.Name,sb);
|
||||
fr.iSize:=sb.st_size;
|
||||
|
||||
fr.iOwner:=sb.st_uid; //UID
|
||||
fr.iGroup:=sb.st_gid; //GID
|
||||
fr.sOwner:=UIDToStr(fr.iOwner);
|
||||
fr.sGroup:=GIDToStr(fr.iGroup);
|
||||
{/mate}
|
||||
fr.iMode:=sb.st_mode;
|
||||
fr.bSysFile := (sr.Name[1] = '.') and (sr.Name <> '..');
|
||||
fr.fTimeI:= FileDateToDateTime(sb.st_mtime); // EncodeDate (1970, 1, 1) + (sr.Time / 86400.0);
|
||||
{$ELSE} // Windows
|
||||
fr.iSize:= sr.Size;
|
||||
fr.iMode:= sr.Attr;
|
||||
fr.bSysFile := Boolean(sr.Attr and faSysFile) or Boolean(sr.Attr and faHidden);
|
||||
fr.fTimeI:= FileDateToDateTime(sr.Time);
|
||||
{$ENDIF}
|
||||
|
||||
if FPS_ISDIR(fr.iMode) or (sr.Name[1]='.') then //!!!!!
|
||||
fr.sExt:=''
|
||||
else
|
||||
fr.sExt:=ExtractFileExt(sr.Name);
|
||||
fr.sNameNoExt:=Copy(sr.Name,1,length(sr.Name)-length(fr.sExt));
|
||||
fr.sName:=sr.Name;
|
||||
|
||||
fr.sTime := FormatDateTime(gDateTimeFormat, fr.fTimeI);
|
||||
fr.bIsLink:=FPS_ISLNK(fr.iMode);
|
||||
fr.sLinkTo:='';
|
||||
fr.iDirSize:=0;
|
||||
|
||||
if fr.bIsLink then
|
||||
begin
|
||||
fr.sLinkTo:=ReadSymLink(sr.Name);
|
||||
end;
|
||||
{$IFDEF UNIX} // *nix
|
||||
if fr.bIsLink then
|
||||
fr.bLinkIsDir:=IsDirByName(fr.sLinkTo)
|
||||
else
|
||||
fr.bLinkIsDir:=False;
|
||||
fr.bExecutable:=(not FPS_ISDIR(fr.iMode)) and (fr.iMode AND (S_IXUSR OR S_IXGRP OR S_IXOTH)>0);
|
||||
{$ELSE} // Windows for ShellExecute
|
||||
fr.bExecutable:= not FPS_ISDIR(fr.iMode);
|
||||
if fr.bIsLink then
|
||||
fr.bLinkIsDir:=True //Because symbolic link works on Windows 2k/XP for directories only
|
||||
else
|
||||
fr.bLinkIsDir:=False;
|
||||
{$ENDIF}
|
||||
fr.bSelected:=False;
|
||||
fr.sModeStr:=AttrToStr(fr.iMode);
|
||||
fr.sPath := sDir;
|
||||
fl.AddItem(@fr);
|
||||
until FindNextEx(sr)<>0;
|
||||
FindClose(sr);
|
||||
Result:=True;
|
||||
end;
|
||||
|
||||
Function AttrToStr(iAttr:Cardinal):String;
|
||||
begin
|
||||
Result := '----------';
|
||||
|
||||
{$IFDEF MSWINDOWS}
|
||||
|
||||
if FPS_ISDIR(iAttr) then Result[1]:='d';
|
||||
if FPS_ISLNK(iAttr) then Result[1]:='l';
|
||||
|
||||
if Boolean(iAttr and $01) then Result[2] := 'r';
|
||||
if Boolean(iAttr and $20) then Result[3] := 'a';
|
||||
if Boolean(iAttr and $02) then Result[4] := 'h';
|
||||
if Boolean(iAttr and $04) then Result[5] := 's';
|
||||
if Boolean(iAttr and $08) then Result[6] := 'v';
|
||||
|
||||
{$ELSE}
|
||||
if FPS_ISDIR(iAttr) then Result[1]:='d';
|
||||
if FPS_ISLNK(iAttr) then Result[1]:='l';
|
||||
if FPS_ISSOCK(iAttr) then Result[1]:='s';
|
||||
if FPS_ISFIFO(iAttr) then Result[1]:='f';
|
||||
if FPS_ISBLK(iAttr) then Result[1]:='b';
|
||||
if FPS_ISCHR(iAttr) then Result[1]:='c';
|
||||
|
||||
if ((iAttr AND S_IRUSR) = S_IRUSR) then Result[2] := 'r';
|
||||
if ((iAttr AND S_IWUSR) = S_IWUSR) then Result[3] := 'w';
|
||||
if ((iAttr AND S_IXUSR) = S_IXUSR) then Result[4] := 'x';
|
||||
if ((iAttr AND S_IRGRP) = S_IRGRP) then Result[5] := 'r';
|
||||
if ((iAttr AND S_IWGRP) = S_IWGRP) then Result[6] := 'w';
|
||||
if ((iAttr AND S_IXGRP) = S_IXGRP) then Result[7] := 'x';
|
||||
if ((iAttr AND S_IROTH) = S_IROTH) then Result[8] := 'r';
|
||||
if ((iAttr AND S_IWOTH) = S_IWOTH) then Result[9] := 'w';
|
||||
if ((iAttr AND S_IXOTH) = S_IXOTH) then Result[10] := 'x';
|
||||
|
||||
if ((iAttr AND S_ISUID) = S_ISUID) then Result[4] := 's';
|
||||
if ((iAttr AND S_ISGID) = S_ISGID) then Result[7] := 's';
|
||||
{$ENDIF}
|
||||
end;
|
||||
|
||||
end.
|
||||
|
|
|
|||
754
ufindex.pas
754
ufindex.pas
|
|
@ -1,376 +1,378 @@
|
|||
{
|
||||
File name: FindEx.pas
|
||||
Date: 2004/05/xx
|
||||
Author: Radek Cervinka <radek.cervinka@centrum.cz>
|
||||
|
||||
very fast file utils for 64 bit access
|
||||
|
||||
fpStat64, fplStat64, Find*64
|
||||
|
||||
|
||||
Copyright (C) 2004
|
||||
|
||||
Licence: GNU LGPL or later
|
||||
|
||||
Warning Libc version is not much tested
|
||||
|
||||
contributors:
|
||||
|
||||
Copyright (C) 2006-2008 Koblov Alexander (Alexx2000@mail.ru)
|
||||
}
|
||||
|
||||
|
||||
unit uFindEx;
|
||||
|
||||
{$mode objfpc}{$H+}
|
||||
|
||||
interface
|
||||
|
||||
{$DEFINE FAKE_FIND}
|
||||
{$DEFINE USE_STAT64}
|
||||
{$IFDEF CPU64}
|
||||
{$DEFINE USE_STAT64LIBC} // libc version
|
||||
{$ENDIF}
|
||||
|
||||
uses
|
||||
SysUtils {$IFNDEF WIN32},BaseUnix, Unix{$IFDEF USE_STAT64LIBC}, Libc {$ELSE}, SysCall{$ENDIF}{$ELSE}, Windows{$ENDIF};
|
||||
|
||||
Type
|
||||
TFindStatus = (fsOK, fsStatFailed, fsBadAttr);
|
||||
|
||||
{$IFDEF USE_STAT64}
|
||||
{$IFDEF USE_STAT64LIBC}
|
||||
Stat64 = Libc._stat64;
|
||||
{$ELSE}
|
||||
// for kernel syscall check structure
|
||||
{$I stat64.inc}
|
||||
|
||||
{$ENDIF}
|
||||
{$ENDIF}
|
||||
|
||||
|
||||
function FindFirstEx (const Path : UTF8String; Attr : Longint; out Rslt : TSearchRec) : Longint;
|
||||
function FindNextEx (var Rslt : TSearchRec) : Longint;
|
||||
function CheckAttrMask(DefaultAttr : Cardinal; sAttr : String; Attr : Cardinal) : Boolean;
|
||||
{$IFDEF UNIX} //*nix systems
|
||||
|
||||
{$IFNDEF FAKE_FIND}
|
||||
function FindStat (Var Rslt : TSearchRec) :TFindStatus;
|
||||
{$ENDIF}
|
||||
|
||||
{$IFDEF USE_STAT64}
|
||||
function Fpstat64(path:String; var buf:stat64):cint;
|
||||
function Fplstat64(path:String; var buf:stat64):cint;
|
||||
{$IFNDEF FAKE_FIND}
|
||||
function FindStat64 (Var Rslt : TSearchRec) :TFindStatus;
|
||||
{$ENDIF}
|
||||
{$ENDIF}
|
||||
|
||||
{$ENDIF} //*nix systems
|
||||
|
||||
implementation
|
||||
uses LCLProc, uFileOp;
|
||||
|
||||
{$IFDEF UNIX} //*nix systems
|
||||
|
||||
{$IFNDEF FAKE_FIND}
|
||||
Function GlobToTSearchRec (Var Info : TSearchRec) : Boolean;
|
||||
|
||||
Var
|
||||
p : Pglob;
|
||||
GlobSearchRec : PGlobSearchRecEx;
|
||||
|
||||
begin
|
||||
GlobSearchRec:=PGlobSearchRecEx(Info.FindHandle);
|
||||
P:=GlobSearchRec^.GlobHandle;
|
||||
Result:=P<>Nil;
|
||||
If Result then
|
||||
begin
|
||||
GlobSearchRec^.GlobHandle:=P^.Next;
|
||||
With Info do
|
||||
begin
|
||||
If P^.Name<>Nil then
|
||||
Name:=strpas(p^.name)
|
||||
else
|
||||
Name:='';
|
||||
GlobSearchRec^.LastName:=Name;
|
||||
end;
|
||||
P^.Next:=Nil;
|
||||
Unix.GlobFree(P);
|
||||
end;
|
||||
end;
|
||||
|
||||
|
||||
Function DoFind(Var Rslt : TSearchRec) : Longint;
|
||||
|
||||
Var
|
||||
GlobSearchRec : PGlobSearchRecEx;
|
||||
|
||||
begin
|
||||
Result:=-1;
|
||||
GlobSearchRec:=PGlobSearchRecEx(Rslt.FindHandle);
|
||||
If (GlobSearchRec^.GlobHandle<>Nil) then
|
||||
While (GlobSearchRec^.GlobHandle<>Nil) and not (Result=0) do
|
||||
If GlobToTSearchRec(Rslt) Then Result:=0;
|
||||
end;
|
||||
{$ENDIF}
|
||||
|
||||
{$IFNDEF FAKE_FIND}
|
||||
Function LinuxToWinAttr (FN : Pchar; Const Info : BaseUnix.Stat) : Longint;
|
||||
|
||||
begin
|
||||
Result:=faArchive;
|
||||
If fpS_ISDIR(Info.st_mode) then
|
||||
Result:=Result or faDirectory;
|
||||
If (FN[0]='.') and (not (FN[1] in [#0,'.'])) then
|
||||
Result:=Result or faHidden;
|
||||
If (Info.st_Mode and S_IWUSR)=0 Then
|
||||
Result:=Result or faReadOnly;
|
||||
If fpS_ISSOCK(Info.st_mode) or fpS_ISBLK(Info.st_mode) or fpS_ISCHR(Info.st_mode) or fpS_ISFIFO(Info.st_mode) Then
|
||||
Result:=Result or faSysFile;
|
||||
end;
|
||||
{$ENDIF}
|
||||
|
||||
{$IFNDEF FAKE_FIND}
|
||||
function FindStat (Var Rslt : TSearchRec) :TFindStatus;
|
||||
Var
|
||||
SInfo : BaseUnix.Stat;
|
||||
GlobSearchRec : PGlobSearchRecEx;
|
||||
|
||||
begin
|
||||
Result:=fsOK;
|
||||
GlobSearchRec:=PGlobSearchrecEx(Rslt.FindHandle);
|
||||
|
||||
if Fpstat(GlobSearchRec^.Path+GlobSearchRec^.LastName,SInfo)<0 then
|
||||
Result:=fsStatFailed;
|
||||
If Result = fsOK then
|
||||
begin
|
||||
Rslt.Attr:=LinuxToWinAttr(PChar(GlobSearchRec^.LastName),SInfo);
|
||||
// hmm, attr support is not good
|
||||
if (Rslt.ExcludeAttr and Rslt.Attr)<>0 then
|
||||
Result:=fsBadAttr;
|
||||
If Result = fsOK Then
|
||||
With Rslt do
|
||||
begin
|
||||
Attr:=Rslt.Attr;
|
||||
Time:=Sinfo.st_mtime;
|
||||
Size:=Sinfo.st_Size;
|
||||
end;
|
||||
end;
|
||||
end;
|
||||
{$ENDIF}
|
||||
|
||||
{$IFDEF USE_STAT64}
|
||||
|
||||
Function LinuxToWinAttr64 (FN : Pchar; Const Info : Stat64) : Longint;
|
||||
|
||||
begin
|
||||
Result:=faArchive;
|
||||
If fpS_ISDIR(Info.st_mode) then
|
||||
Result:=Result or faDirectory;
|
||||
If (FN[0]='.') and (not (FN[1] in [#0,'.'])) then
|
||||
Result:=Result or faHidden;
|
||||
If (Info.st_Mode and S_IWUSR)=0 Then
|
||||
Result:=Result or faReadOnly;
|
||||
If fpS_ISSOCK(Info.st_mode) or fpS_ISBLK(Info.st_mode) or fpS_ISCHR(Info.st_mode) or fpS_ISFIFO(Info.st_mode) Then
|
||||
Result:=Result or faSysFile;
|
||||
end;
|
||||
|
||||
{$IFDEF USE_STAT64LIBC}
|
||||
function Fpstat64(path:String; var buf:stat64):cint;
|
||||
begin
|
||||
Result:=Libc.stat64(Pchar(path),buf);
|
||||
end;
|
||||
|
||||
function Fplstat64(path: String; var buf: stat64): cint;
|
||||
begin
|
||||
Result:=Libc.lstat64(Pchar(path),buf);
|
||||
end;
|
||||
|
||||
{$ELSE}
|
||||
function Fpstat64(path:String; var buf:stat64):cint;
|
||||
begin
|
||||
Result:=do_syscall(syscall_nr_stat64,TSysParam(PChar(path)),TSysParam(@buf));
|
||||
end;
|
||||
|
||||
function Fplstat64(path: String; var buf: stat64): cint;
|
||||
begin
|
||||
Result:=do_syscall(syscall_nr_lstat64,TSysParam(PChar(path)),TSysParam(@buf));
|
||||
end;
|
||||
|
||||
{$ENDIF}
|
||||
|
||||
{$IFNDEF FAKE_FIND}
|
||||
function FindStat64 (Var Rslt : TSearchRec) :TFindStatus;
|
||||
Var
|
||||
SInfo : Stat64;
|
||||
GlobSearchRec : PGlobSearchRecEx;
|
||||
|
||||
begin
|
||||
Result:=fsOK;
|
||||
GlobSearchRec:=PGlobSearchrecEx(Rslt.FindHandle);
|
||||
if Fpstat64(GlobSearchRec^.Path+GlobSearchRec^.LastName,SInfo)<0 then
|
||||
Result:=fsStatFailed;
|
||||
If Result = fsOK then
|
||||
begin
|
||||
Rslt.Attr:=LinuxToWinAttr64(PChar(GlobSearchRec^.LastName),SInfo);
|
||||
// hmm, attr support is not good
|
||||
if (Rslt.ExcludeAttr and Rslt.Attr)<>0 then
|
||||
Result:=fsBadAttr;
|
||||
If Result = fsOK Then
|
||||
With Rslt do
|
||||
begin
|
||||
Attr:=Rslt.Attr;
|
||||
Time:=Sinfo.st_mtime;
|
||||
Size:=Sinfo.st_Size;
|
||||
end;
|
||||
end;
|
||||
end;
|
||||
|
||||
{$ENDIF}
|
||||
{$ENDIF}
|
||||
|
||||
{$ENDIF} //*nix systems
|
||||
|
||||
{$IFDEF MSWINDOWS}
|
||||
function mbFindMatchingFile(var Rslt: TSearchRec): Integer;
|
||||
var
|
||||
LocalFileTime: TFileTime;
|
||||
wFindData: TWin32FindDataW;
|
||||
pwFindData: PWIN32FINDDATAW absolute Rslt.FindData; // for use PWin32FindDataW instead TWin32FindData
|
||||
begin
|
||||
with Rslt do
|
||||
begin
|
||||
wFindData:= pwFindData^;
|
||||
while (wFindData.dwFileAttributes and ExcludeAttr) <> 0 do
|
||||
if not FindNextFileW(FindHandle, wFindData) then Exit(GetLastError);
|
||||
|
||||
pwFindData:= @wFindData;
|
||||
FileTimeToLocalFileTime(wFindData.ftLastWriteTime, LocalFileTime);
|
||||
FileTimeToDosDateTime(LocalFileTime, LongRec(Time).Hi, LongRec(Time).Lo);
|
||||
Size:= (Int64(wFindData.nFileSizeHigh) shl 32) + wFindData.nFileSizeLow;
|
||||
Attr:= wFindData.dwFileAttributes;
|
||||
Name:= UTF8Encode(wFindData.cFileName);
|
||||
end;
|
||||
Result:= 0;
|
||||
end;
|
||||
{$ENDIF}
|
||||
|
||||
function FindFirstEx (const Path : UTF8String; Attr : Longint; out Rslt : TSearchRec) : Longint;
|
||||
{$IFDEF MSWINDOWS}
|
||||
const
|
||||
faSpecial = faHidden or faSysFile or faVolumeID or faDirectory;
|
||||
var
|
||||
wPath: WideString;
|
||||
wFindData: TWin32FindDataW;
|
||||
pwFindData: PWIN32FINDDATAW absolute Rslt.FindData; // for use PWin32FindDataW instead TWin32FindData
|
||||
begin
|
||||
wPath:= UTF8Decode(Path);
|
||||
Rslt.ExcludeAttr:= not Attr and faSpecial;
|
||||
Rslt.FindHandle:= FindFirstFileW(PWideChar(wPath), wFindData);
|
||||
// if error then exit
|
||||
if Rslt.FindHandle = INVALID_HANDLE_VALUE then Exit(GetLastError);
|
||||
|
||||
pwFindData:= @wFindData;
|
||||
|
||||
Result:= mbFindMatchingFile(Rslt);
|
||||
end;
|
||||
{$ELSE}
|
||||
begin
|
||||
if (Attr and faSymLink) = faSymLink then
|
||||
Attr:= Attr or not faSymLink;
|
||||
// call standart FindFirst function
|
||||
Result:= FindFirst(Path, Attr, Rslt);
|
||||
// and replace Attr by Mode
|
||||
if Result = 0 then
|
||||
Rslt.Attr:= Rslt.Mode;
|
||||
end;
|
||||
{$ENDIF}
|
||||
|
||||
function FindNextEx (var Rslt : TSearchRec) : Longint;
|
||||
{$IFDEF MSWINDOWS}
|
||||
var
|
||||
wFindData: TWin32FindDataW;
|
||||
pwFindData: PWIN32FINDDATAW absolute Rslt.FindData; // for use PWin32FindDataW instead TWin32FindData
|
||||
begin
|
||||
wFindData:= pwFindData^;
|
||||
if FindNextFileW(Rslt.FindHandle, wFindData) then
|
||||
begin
|
||||
pwFindData:= @wFindData;
|
||||
Result:= mbFindMatchingFile(Rslt);
|
||||
end
|
||||
else
|
||||
Result:= GetLastError;
|
||||
end;
|
||||
{$ELSE}
|
||||
begin
|
||||
// call standart FindNext function
|
||||
Result:= FindNext(Rslt);
|
||||
// and replace Attr by Mode
|
||||
if Result = 0 then
|
||||
Rslt.Attr:= Rslt.Mode;
|
||||
end;
|
||||
{$ENDIF}
|
||||
|
||||
function CheckAttrMask(DefaultAttr : Cardinal; sAttr : String; Attr : Cardinal) : Boolean;
|
||||
{$IFDEF WINDOWS}
|
||||
begin
|
||||
Result := True;
|
||||
if (DefaultAttr <> 0) and (DefaultAttr <> faAnyFile) then
|
||||
Result := (Attr and DefaultAttr) = DefaultAttr;
|
||||
if Length(sAttr) < 4 then Exit;
|
||||
if Result then
|
||||
begin
|
||||
if sAttr[1] = 'r' then Result := Result and ((Attr and faReadOnly) = faReadOnly)
|
||||
else if sAttr[1] = '-' then Result := Result and ((Attr and faReadOnly) <> faReadOnly);
|
||||
//WriteLN('After r == ', BoolToStr(Result));
|
||||
if sAttr[2] = 'a' then Result := Result and ((Attr and faArchive) = faArchive)
|
||||
else if sAttr[2] = '-' then Result := Result and ((Attr and faArchive) <> faArchive);
|
||||
//WriteLN('After a == ', BoolToStr(Result));
|
||||
if sAttr[3] = 'h' then Result := Result and ((Attr and faHidden) = faHidden)
|
||||
else if sAttr[3] = '-' then Result := Result and ((Attr and faHidden) <> faHidden);
|
||||
//WriteLN('After h == ', BoolToStr(Result));
|
||||
if sAttr[4] = 's' then Result := Result and ((Attr and faSysFile) = faSysFile)
|
||||
else if sAttr[4] = '-' then Result := Result and ((Attr and faSysFile) <> faSysFile);
|
||||
end;
|
||||
end;
|
||||
{$ELSE}
|
||||
begin
|
||||
Result := True;
|
||||
if (DefaultAttr <> 0) and (DefaultAttr <> faAnyFile) then
|
||||
begin
|
||||
if Boolean(DefaultAttr and faDirectory) then
|
||||
Result := Result and fpS_ISDIR(Attr);
|
||||
DebugLn('Result do == ', BoolToStr(Result));
|
||||
if Boolean(DefaultAttr and faSymLink) then
|
||||
Result := Result and ((Attr and S_IFLNK) = S_IFLNK);
|
||||
DebugLn('Result after == ', BoolToStr(Result));
|
||||
end;
|
||||
if Length(sAttr) < 9 then Exit;
|
||||
|
||||
if sAttr[1]='r' then Result:=Result and ((Attr AND S_IRUSR) = S_IRUSR)
|
||||
else if sAttr[1]='-' then Result:=Result and ((Attr AND S_IRUSR) <> S_IRUSR);
|
||||
if sAttr[2]='w' then Result:=Result and ((Attr AND S_IWUSR) = S_IWUSR)
|
||||
else if sAttr[2]='-' then Result:=Result and ((Attr AND S_IWUSR) <> S_IWUSR);
|
||||
if sAttr[3]='x' then Result:=Result and ((Attr AND S_IXUSR) = S_IXUSR)
|
||||
else if sAttr[3]='-' then Result:=Result and ((Attr AND S_IXUSR) <> S_IXUSR);
|
||||
if sAttr[4]='r' then Result:=Result and ((Attr AND S_IRGRP) = S_IRGRP)
|
||||
else if sAttr[4]='-' then Result:=Result and ((Attr AND S_IRGRP) <> S_IRGRP);
|
||||
if sAttr[5]='w' then Result:=Result and ((Attr AND S_IWGRP) = S_IWGRP)
|
||||
else if sAttr[5]='-' then Result:=Result and ((Attr AND S_IWGRP) <> S_IWGRP);
|
||||
if sAttr[6]='x' then Result:=Result and ((Attr AND S_IXGRP) = S_IXGRP)
|
||||
else if sAttr[6]='-' then Result:=Result and ((Attr AND S_IXGRP) <> S_IXGRP);
|
||||
if sAttr[7]='r' then Result:=Result and ((Attr AND S_IROTH) = S_IROTH)
|
||||
else if sAttr[7]='-' then Result:=Result and ((Attr AND S_IROTH) <> S_IROTH);
|
||||
if sAttr[8]='w' then Result:=Result and ((Attr AND S_IWOTH) = S_IWOTH)
|
||||
else if sAttr[8]='-' then Result:=Result and ((Attr AND S_IWOTH) <> S_IWOTH);
|
||||
if sAttr[9]='x' then Result:=Result and ((Attr AND S_IXOTH) = S_IXOTH)
|
||||
else if sAttr[9]='-' then Result:=Result and ((Attr AND S_IXOTH) <> S_IXOTH);
|
||||
|
||||
if sAttr[3]='s' then Result:=Result and ((Attr AND S_ISUID) = S_ISUID);
|
||||
if sAttr[6]='s' then Result:=Result and ((Attr AND S_ISGID) = S_ISGID);
|
||||
end;
|
||||
{$ENDIF}
|
||||
|
||||
end.
|
||||
|
||||
{
|
||||
File name: FindEx.pas
|
||||
Date: 2004/05/xx
|
||||
Author: Radek Cervinka <radek.cervinka@centrum.cz>
|
||||
|
||||
very fast file utils for 64 bit access
|
||||
|
||||
fpStat64, fplStat64, Find*64
|
||||
|
||||
|
||||
Copyright (C) 2004
|
||||
|
||||
Licence: GNU LGPL or later
|
||||
|
||||
Warning Libc version is not much tested
|
||||
|
||||
contributors:
|
||||
|
||||
Copyright (C) 2006-2008 Koblov Alexander (Alexx2000@mail.ru)
|
||||
}
|
||||
|
||||
|
||||
unit uFindEx;
|
||||
|
||||
{$mode objfpc}{$H+}
|
||||
|
||||
interface
|
||||
|
||||
{$DEFINE FAKE_FIND}
|
||||
{$DEFINE USE_STAT64}
|
||||
{$IFDEF UNIX}
|
||||
{$IFDEF CPU64}
|
||||
{$DEFINE USE_STAT64LIBC} // libc version
|
||||
{$ENDIF}
|
||||
{$ENDIF}
|
||||
|
||||
uses
|
||||
SysUtils {$IFDEF UNIX},BaseUnix, Unix{$IFDEF USE_STAT64LIBC}, Libc {$ELSE}, SysCall{$ENDIF}{$ELSE}, Windows{$ENDIF};
|
||||
|
||||
Type
|
||||
TFindStatus = (fsOK, fsStatFailed, fsBadAttr);
|
||||
|
||||
{$IFDEF USE_STAT64}
|
||||
{$IFDEF USE_STAT64LIBC}
|
||||
Stat64 = Libc._stat64;
|
||||
{$ELSE}
|
||||
// for kernel syscall check structure
|
||||
{$I stat64.inc}
|
||||
|
||||
{$ENDIF}
|
||||
{$ENDIF}
|
||||
|
||||
|
||||
function FindFirstEx (const Path : UTF8String; Attr : Longint; out Rslt : TSearchRec) : Longint;
|
||||
function FindNextEx (var Rslt : TSearchRec) : Longint;
|
||||
function CheckAttrMask(DefaultAttr : Cardinal; sAttr : String; Attr : Cardinal) : Boolean;
|
||||
{$IFDEF UNIX} //*nix systems
|
||||
|
||||
{$IFNDEF FAKE_FIND}
|
||||
function FindStat (Var Rslt : TSearchRec) :TFindStatus;
|
||||
{$ENDIF}
|
||||
|
||||
{$IFDEF USE_STAT64}
|
||||
function Fpstat64(path:String; var buf:stat64):cint;
|
||||
function Fplstat64(path:String; var buf:stat64):cint;
|
||||
{$IFNDEF FAKE_FIND}
|
||||
function FindStat64 (Var Rslt : TSearchRec) :TFindStatus;
|
||||
{$ENDIF}
|
||||
{$ENDIF}
|
||||
|
||||
{$ENDIF} //*nix systems
|
||||
|
||||
implementation
|
||||
uses LCLProc, uFileOp;
|
||||
|
||||
{$IFDEF UNIX} //*nix systems
|
||||
|
||||
{$IFNDEF FAKE_FIND}
|
||||
Function GlobToTSearchRec (Var Info : TSearchRec) : Boolean;
|
||||
|
||||
Var
|
||||
p : Pglob;
|
||||
GlobSearchRec : PGlobSearchRecEx;
|
||||
|
||||
begin
|
||||
GlobSearchRec:=PGlobSearchRecEx(Info.FindHandle);
|
||||
P:=GlobSearchRec^.GlobHandle;
|
||||
Result:=P<>Nil;
|
||||
If Result then
|
||||
begin
|
||||
GlobSearchRec^.GlobHandle:=P^.Next;
|
||||
With Info do
|
||||
begin
|
||||
If P^.Name<>Nil then
|
||||
Name:=strpas(p^.name)
|
||||
else
|
||||
Name:='';
|
||||
GlobSearchRec^.LastName:=Name;
|
||||
end;
|
||||
P^.Next:=Nil;
|
||||
Unix.GlobFree(P);
|
||||
end;
|
||||
end;
|
||||
|
||||
|
||||
Function DoFind(Var Rslt : TSearchRec) : Longint;
|
||||
|
||||
Var
|
||||
GlobSearchRec : PGlobSearchRecEx;
|
||||
|
||||
begin
|
||||
Result:=-1;
|
||||
GlobSearchRec:=PGlobSearchRecEx(Rslt.FindHandle);
|
||||
If (GlobSearchRec^.GlobHandle<>Nil) then
|
||||
While (GlobSearchRec^.GlobHandle<>Nil) and not (Result=0) do
|
||||
If GlobToTSearchRec(Rslt) Then Result:=0;
|
||||
end;
|
||||
{$ENDIF}
|
||||
|
||||
{$IFNDEF FAKE_FIND}
|
||||
Function LinuxToWinAttr (FN : Pchar; Const Info : BaseUnix.Stat) : Longint;
|
||||
|
||||
begin
|
||||
Result:=faArchive;
|
||||
If fpS_ISDIR(Info.st_mode) then
|
||||
Result:=Result or faDirectory;
|
||||
If (FN[0]='.') and (not (FN[1] in [#0,'.'])) then
|
||||
Result:=Result or faHidden;
|
||||
If (Info.st_Mode and S_IWUSR)=0 Then
|
||||
Result:=Result or faReadOnly;
|
||||
If fpS_ISSOCK(Info.st_mode) or fpS_ISBLK(Info.st_mode) or fpS_ISCHR(Info.st_mode) or fpS_ISFIFO(Info.st_mode) Then
|
||||
Result:=Result or faSysFile;
|
||||
end;
|
||||
{$ENDIF}
|
||||
|
||||
{$IFNDEF FAKE_FIND}
|
||||
function FindStat (Var Rslt : TSearchRec) :TFindStatus;
|
||||
Var
|
||||
SInfo : BaseUnix.Stat;
|
||||
GlobSearchRec : PGlobSearchRecEx;
|
||||
|
||||
begin
|
||||
Result:=fsOK;
|
||||
GlobSearchRec:=PGlobSearchrecEx(Rslt.FindHandle);
|
||||
|
||||
if Fpstat(GlobSearchRec^.Path+GlobSearchRec^.LastName,SInfo)<0 then
|
||||
Result:=fsStatFailed;
|
||||
If Result = fsOK then
|
||||
begin
|
||||
Rslt.Attr:=LinuxToWinAttr(PChar(GlobSearchRec^.LastName),SInfo);
|
||||
// hmm, attr support is not good
|
||||
if (Rslt.ExcludeAttr and Rslt.Attr)<>0 then
|
||||
Result:=fsBadAttr;
|
||||
If Result = fsOK Then
|
||||
With Rslt do
|
||||
begin
|
||||
Attr:=Rslt.Attr;
|
||||
Time:=Sinfo.st_mtime;
|
||||
Size:=Sinfo.st_Size;
|
||||
end;
|
||||
end;
|
||||
end;
|
||||
{$ENDIF}
|
||||
|
||||
{$IFDEF USE_STAT64}
|
||||
|
||||
Function LinuxToWinAttr64 (FN : Pchar; Const Info : Stat64) : Longint;
|
||||
|
||||
begin
|
||||
Result:=faArchive;
|
||||
If fpS_ISDIR(Info.st_mode) then
|
||||
Result:=Result or faDirectory;
|
||||
If (FN[0]='.') and (not (FN[1] in [#0,'.'])) then
|
||||
Result:=Result or faHidden;
|
||||
If (Info.st_Mode and S_IWUSR)=0 Then
|
||||
Result:=Result or faReadOnly;
|
||||
If fpS_ISSOCK(Info.st_mode) or fpS_ISBLK(Info.st_mode) or fpS_ISCHR(Info.st_mode) or fpS_ISFIFO(Info.st_mode) Then
|
||||
Result:=Result or faSysFile;
|
||||
end;
|
||||
|
||||
{$IFDEF USE_STAT64LIBC}
|
||||
function Fpstat64(path:String; var buf:stat64):cint;
|
||||
begin
|
||||
Result:=Libc.stat64(Pchar(path),buf);
|
||||
end;
|
||||
|
||||
function Fplstat64(path: String; var buf: stat64): cint;
|
||||
begin
|
||||
Result:=Libc.lstat64(Pchar(path),buf);
|
||||
end;
|
||||
|
||||
{$ELSE}
|
||||
function Fpstat64(path:String; var buf:stat64):cint;
|
||||
begin
|
||||
Result:=do_syscall(syscall_nr_stat64,TSysParam(PChar(path)),TSysParam(@buf));
|
||||
end;
|
||||
|
||||
function Fplstat64(path: String; var buf: stat64): cint;
|
||||
begin
|
||||
Result:=do_syscall(syscall_nr_lstat64,TSysParam(PChar(path)),TSysParam(@buf));
|
||||
end;
|
||||
|
||||
{$ENDIF}
|
||||
|
||||
{$IFNDEF FAKE_FIND}
|
||||
function FindStat64 (Var Rslt : TSearchRec) :TFindStatus;
|
||||
Var
|
||||
SInfo : Stat64;
|
||||
GlobSearchRec : PGlobSearchRecEx;
|
||||
|
||||
begin
|
||||
Result:=fsOK;
|
||||
GlobSearchRec:=PGlobSearchrecEx(Rslt.FindHandle);
|
||||
if Fpstat64(GlobSearchRec^.Path+GlobSearchRec^.LastName,SInfo)<0 then
|
||||
Result:=fsStatFailed;
|
||||
If Result = fsOK then
|
||||
begin
|
||||
Rslt.Attr:=LinuxToWinAttr64(PChar(GlobSearchRec^.LastName),SInfo);
|
||||
// hmm, attr support is not good
|
||||
if (Rslt.ExcludeAttr and Rslt.Attr)<>0 then
|
||||
Result:=fsBadAttr;
|
||||
If Result = fsOK Then
|
||||
With Rslt do
|
||||
begin
|
||||
Attr:=Rslt.Attr;
|
||||
Time:=Sinfo.st_mtime;
|
||||
Size:=Sinfo.st_Size;
|
||||
end;
|
||||
end;
|
||||
end;
|
||||
|
||||
{$ENDIF}
|
||||
{$ENDIF}
|
||||
|
||||
{$ENDIF} //*nix systems
|
||||
|
||||
{$IFDEF MSWINDOWS}
|
||||
function mbFindMatchingFile(var Rslt: TSearchRec): Integer;
|
||||
var
|
||||
LocalFileTime: TFileTime;
|
||||
wFindData: TWin32FindDataW;
|
||||
pwFindData: PWIN32FINDDATAW absolute Rslt.FindData; // for use PWin32FindDataW instead TWin32FindData
|
||||
begin
|
||||
with Rslt do
|
||||
begin
|
||||
wFindData:= pwFindData^;
|
||||
while (wFindData.dwFileAttributes and ExcludeAttr) <> 0 do
|
||||
if not FindNextFileW(FindHandle, wFindData) then Exit(GetLastError);
|
||||
|
||||
pwFindData:= @wFindData;
|
||||
FileTimeToLocalFileTime(wFindData.ftLastWriteTime, LocalFileTime);
|
||||
FileTimeToDosDateTime(LocalFileTime, LongRec(Time).Hi, LongRec(Time).Lo);
|
||||
Size:= (Int64(wFindData.nFileSizeHigh) shl 32) + wFindData.nFileSizeLow;
|
||||
Attr:= wFindData.dwFileAttributes;
|
||||
Name:= UTF8Encode(wFindData.cFileName);
|
||||
end;
|
||||
Result:= 0;
|
||||
end;
|
||||
{$ENDIF}
|
||||
|
||||
function FindFirstEx (const Path : UTF8String; Attr : Longint; out Rslt : TSearchRec) : Longint;
|
||||
{$IFDEF MSWINDOWS}
|
||||
const
|
||||
faSpecial = faHidden or faSysFile or faVolumeID or faDirectory;
|
||||
var
|
||||
wPath: WideString;
|
||||
wFindData: TWin32FindDataW;
|
||||
pwFindData: PWIN32FINDDATAW absolute Rslt.FindData; // for use PWin32FindDataW instead TWin32FindData
|
||||
begin
|
||||
wPath:= UTF8Decode(Path);
|
||||
Rslt.ExcludeAttr:= not Attr and faSpecial;
|
||||
Rslt.FindHandle:= FindFirstFileW(PWideChar(wPath), wFindData);
|
||||
// if error then exit
|
||||
if Rslt.FindHandle = INVALID_HANDLE_VALUE then Exit(GetLastError);
|
||||
|
||||
pwFindData:= @wFindData;
|
||||
|
||||
Result:= mbFindMatchingFile(Rslt);
|
||||
end;
|
||||
{$ELSE}
|
||||
begin
|
||||
if (Attr and faSymLink) = faSymLink then
|
||||
Attr:= Attr or not faSymLink;
|
||||
// call standart FindFirst function
|
||||
Result:= FindFirst(Path, Attr, Rslt);
|
||||
// and replace Attr by Mode
|
||||
if Result = 0 then
|
||||
Rslt.Attr:= Rslt.Mode;
|
||||
end;
|
||||
{$ENDIF}
|
||||
|
||||
function FindNextEx (var Rslt : TSearchRec) : Longint;
|
||||
{$IFDEF MSWINDOWS}
|
||||
var
|
||||
wFindData: TWin32FindDataW;
|
||||
pwFindData: PWIN32FINDDATAW absolute Rslt.FindData; // for use PWin32FindDataW instead TWin32FindData
|
||||
begin
|
||||
wFindData:= pwFindData^;
|
||||
if FindNextFileW(Rslt.FindHandle, wFindData) then
|
||||
begin
|
||||
pwFindData:= @wFindData;
|
||||
Result:= mbFindMatchingFile(Rslt);
|
||||
end
|
||||
else
|
||||
Result:= GetLastError;
|
||||
end;
|
||||
{$ELSE}
|
||||
begin
|
||||
// call standart FindNext function
|
||||
Result:= FindNext(Rslt);
|
||||
// and replace Attr by Mode
|
||||
if Result = 0 then
|
||||
Rslt.Attr:= Rslt.Mode;
|
||||
end;
|
||||
{$ENDIF}
|
||||
|
||||
function CheckAttrMask(DefaultAttr : Cardinal; sAttr : String; Attr : Cardinal) : Boolean;
|
||||
{$IFDEF WINDOWS}
|
||||
begin
|
||||
Result := True;
|
||||
if (DefaultAttr <> 0) and (DefaultAttr <> faAnyFile) then
|
||||
Result := (Attr and DefaultAttr) = DefaultAttr;
|
||||
if Length(sAttr) < 4 then Exit;
|
||||
if Result then
|
||||
begin
|
||||
if sAttr[1] = 'r' then Result := Result and ((Attr and faReadOnly) = faReadOnly)
|
||||
else if sAttr[1] = '-' then Result := Result and ((Attr and faReadOnly) <> faReadOnly);
|
||||
//WriteLN('After r == ', BoolToStr(Result));
|
||||
if sAttr[2] = 'a' then Result := Result and ((Attr and faArchive) = faArchive)
|
||||
else if sAttr[2] = '-' then Result := Result and ((Attr and faArchive) <> faArchive);
|
||||
//WriteLN('After a == ', BoolToStr(Result));
|
||||
if sAttr[3] = 'h' then Result := Result and ((Attr and faHidden) = faHidden)
|
||||
else if sAttr[3] = '-' then Result := Result and ((Attr and faHidden) <> faHidden);
|
||||
//WriteLN('After h == ', BoolToStr(Result));
|
||||
if sAttr[4] = 's' then Result := Result and ((Attr and faSysFile) = faSysFile)
|
||||
else if sAttr[4] = '-' then Result := Result and ((Attr and faSysFile) <> faSysFile);
|
||||
end;
|
||||
end;
|
||||
{$ELSE}
|
||||
begin
|
||||
Result := True;
|
||||
if (DefaultAttr <> 0) and (DefaultAttr <> faAnyFile) then
|
||||
begin
|
||||
if Boolean(DefaultAttr and faDirectory) then
|
||||
Result := Result and fpS_ISDIR(Attr);
|
||||
DebugLn('Result do == ', BoolToStr(Result));
|
||||
if Boolean(DefaultAttr and faSymLink) then
|
||||
Result := Result and ((Attr and S_IFLNK) = S_IFLNK);
|
||||
DebugLn('Result after == ', BoolToStr(Result));
|
||||
end;
|
||||
if Length(sAttr) < 9 then Exit;
|
||||
|
||||
if sAttr[1]='r' then Result:=Result and ((Attr AND S_IRUSR) = S_IRUSR)
|
||||
else if sAttr[1]='-' then Result:=Result and ((Attr AND S_IRUSR) <> S_IRUSR);
|
||||
if sAttr[2]='w' then Result:=Result and ((Attr AND S_IWUSR) = S_IWUSR)
|
||||
else if sAttr[2]='-' then Result:=Result and ((Attr AND S_IWUSR) <> S_IWUSR);
|
||||
if sAttr[3]='x' then Result:=Result and ((Attr AND S_IXUSR) = S_IXUSR)
|
||||
else if sAttr[3]='-' then Result:=Result and ((Attr AND S_IXUSR) <> S_IXUSR);
|
||||
if sAttr[4]='r' then Result:=Result and ((Attr AND S_IRGRP) = S_IRGRP)
|
||||
else if sAttr[4]='-' then Result:=Result and ((Attr AND S_IRGRP) <> S_IRGRP);
|
||||
if sAttr[5]='w' then Result:=Result and ((Attr AND S_IWGRP) = S_IWGRP)
|
||||
else if sAttr[5]='-' then Result:=Result and ((Attr AND S_IWGRP) <> S_IWGRP);
|
||||
if sAttr[6]='x' then Result:=Result and ((Attr AND S_IXGRP) = S_IXGRP)
|
||||
else if sAttr[6]='-' then Result:=Result and ((Attr AND S_IXGRP) <> S_IXGRP);
|
||||
if sAttr[7]='r' then Result:=Result and ((Attr AND S_IROTH) = S_IROTH)
|
||||
else if sAttr[7]='-' then Result:=Result and ((Attr AND S_IROTH) <> S_IROTH);
|
||||
if sAttr[8]='w' then Result:=Result and ((Attr AND S_IWOTH) = S_IWOTH)
|
||||
else if sAttr[8]='-' then Result:=Result and ((Attr AND S_IWOTH) <> S_IWOTH);
|
||||
if sAttr[9]='x' then Result:=Result and ((Attr AND S_IXOTH) = S_IXOTH)
|
||||
else if sAttr[9]='-' then Result:=Result and ((Attr AND S_IXOTH) <> S_IXOTH);
|
||||
|
||||
if sAttr[3]='s' then Result:=Result and ((Attr AND S_ISUID) = S_ISUID);
|
||||
if sAttr[6]='s' then Result:=Result and ((Attr AND S_ISGID) = S_ISGID);
|
||||
end;
|
||||
{$ENDIF}
|
||||
|
||||
end.
|
||||
|
||||
|
|
|
|||
|
|
@ -61,7 +61,7 @@ type
|
|||
FSecondIconSize,
|
||||
FThirdIconSize : TDriveIcons;
|
||||
FPixmapSize : String;
|
||||
{$IFDEF WIN32}
|
||||
{$IFDEF MSWINDOWS}
|
||||
SysImgList : Cardinal;
|
||||
{$ENDIF}
|
||||
protected
|
||||
|
|
@ -327,7 +327,7 @@ begin
|
|||
end;
|
||||
|
||||
constructor TPixMapManager.Create;
|
||||
{$IFDEF WIN32}
|
||||
{$IFDEF MSWINDOWS}
|
||||
var
|
||||
FileInfo : TSHFileInfo;
|
||||
iIconSize : Integer;
|
||||
|
|
@ -335,7 +335,7 @@ var
|
|||
begin
|
||||
FExtList:=TStringList.Create;
|
||||
FPixmapList:=TStringList.Create;
|
||||
{$IFDEF WIN32}
|
||||
{$IFDEF MSWINDOWS}
|
||||
if gIconsSize < 32 then
|
||||
iIconSize := SHGFI_SMALLICON
|
||||
else
|
||||
|
|
@ -376,7 +376,7 @@ begin
|
|||
if Assigned(bmMediaFlash) then FreeAndNil(bmMediaFlash);
|
||||
if Assigned(bmMediaOptical) then FreeAndNil(bmMediaOptical);
|
||||
end;
|
||||
{$IFDEF WIN32}
|
||||
{$IFDEF MSWINDOWS}
|
||||
ImageList_Destroy(SysImgList);
|
||||
{$ENDIF}
|
||||
inherited Destroy;
|
||||
|
|
|
|||
|
|
@ -33,7 +33,7 @@ function ModeStr2Mode(const sMode:String):Integer;
|
|||
implementation
|
||||
|
||||
uses
|
||||
SysUtils, uFileOp, uOSUtils, uFindEx, LCLProc {$IFNDEF WIN32}, BaseUnix{$ENDIF};
|
||||
SysUtils, uFileOp, uOSUtils, uFindEx, LCLProc {$IFDEF UNIX}, BaseUnix{$ENDIF};
|
||||
|
||||
{ TFileList }
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue