mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-08-20 14:19:17 +02:00
Cleanup for utility functions.
git-svn-id: trunk@58786 -
This commit is contained in:
parent
cc3dd4cfbf
commit
0bb1729bdc
@ -344,10 +344,10 @@ type
|
|||||||
FSourceDir: string;
|
FSourceDir: string;
|
||||||
FTargetDir: string;
|
FTargetDir: string;
|
||||||
FFlags: TCopyFileFlags;
|
FFlags: TCopyFileFlags;
|
||||||
FCopyFailedCount:Integer;
|
FCopyFailedCount: Integer;
|
||||||
protected
|
protected
|
||||||
procedure DoFileFound; override;
|
procedure DoFileFound; override;
|
||||||
procedure DoDirectoryFound; override;
|
//procedure DoDirectoryFound; override;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
procedure TCopyDirTree.DoFileFound;
|
procedure TCopyDirTree.DoFileFound;
|
||||||
@ -359,18 +359,12 @@ begin
|
|||||||
if not CopyFile(FileName, NewLoc, FFlags) then
|
if not CopyFile(FileName, NewLoc, FFlags) then
|
||||||
Inc(FCopyFailedCount);
|
Inc(FCopyFailedCount);
|
||||||
end;
|
end;
|
||||||
|
{
|
||||||
procedure TCopyDirTree.DoDirectoryFound;
|
procedure TCopyDirTree.DoDirectoryFound;
|
||||||
var
|
|
||||||
NewPath:String;
|
|
||||||
begin
|
begin
|
||||||
NewPath:=StringReplace(FileName, FSourceDir, FTargetDir, []);
|
// Directory is already created by the cffCreateDestDirectory flag.
|
||||||
// ToDo: make directories also respect cffPreserveTime flag.
|
|
||||||
if not DirectoryExistsUTF8(NewPath) then
|
|
||||||
if not ForceDirectoriesUTF8(NewPath) then
|
|
||||||
Inc(FCopyFailedCount);
|
|
||||||
end;
|
end;
|
||||||
|
}
|
||||||
function CopyDirTree(const SourceDir, TargetDir: string; Flags: TCopyFileFlags=[]): Boolean;
|
function CopyDirTree(const SourceDir, TargetDir: string; Flags: TCopyFileFlags=[]): Boolean;
|
||||||
var
|
var
|
||||||
Searcher: TCopyDirTree;
|
Searcher: TCopyDirTree;
|
||||||
@ -387,11 +381,7 @@ begin
|
|||||||
|
|
||||||
// Don't even try to copy to a subdirectory of SourceDir.
|
// Don't even try to copy to a subdirectory of SourceDir.
|
||||||
{$ifdef CaseInsensitiveFilenames}
|
{$ifdef CaseInsensitiveFilenames}
|
||||||
{$ifdef ACP_RTL}
|
|
||||||
if AnsiStartsText(Searcher.FSourceDir, Searcher.FTargetDir) then Exit;
|
if AnsiStartsText(Searcher.FSourceDir, Searcher.FTargetDir) then Exit;
|
||||||
{$else ACP_RTL}
|
|
||||||
if Utf8StartsText(Searcher.FSourceDir, Searcher.FTargetDir) then Exit;
|
|
||||||
{$endif}
|
|
||||||
{$ELSE}
|
{$ELSE}
|
||||||
if AnsiStartsStr(Searcher.FSourceDir, Searcher.FTargetDir) then Exit;
|
if AnsiStartsStr(Searcher.FSourceDir, Searcher.FTargetDir) then Exit;
|
||||||
{$ENDIF}
|
{$ENDIF}
|
||||||
|
@ -27,8 +27,9 @@ unit FileUtil;
|
|||||||
interface
|
interface
|
||||||
|
|
||||||
uses
|
uses
|
||||||
Classes, SysUtils,
|
Classes, SysUtils, StrUtils,
|
||||||
Masks, LazUTF8, LazFileUtils, StrUtils;
|
// LazUtils
|
||||||
|
Masks, LazUTF8, LazFileUtils;
|
||||||
|
|
||||||
{$IF defined(Windows) or defined(darwin) or defined(HASAMIGA)}
|
{$IF defined(Windows) or defined(darwin) or defined(HASAMIGA)}
|
||||||
{$define CaseInsensitiveFilenames}
|
{$define CaseInsensitiveFilenames}
|
||||||
@ -100,14 +101,12 @@ type
|
|||||||
function GetFileName: String;
|
function GetFileName: String;
|
||||||
public
|
public
|
||||||
procedure Stop;
|
procedure Stop;
|
||||||
|
|
||||||
function IsDirectory: Boolean;
|
function IsDirectory: Boolean;
|
||||||
public
|
public
|
||||||
property FileName: String read GetFileName;
|
property FileName: String read GetFileName;
|
||||||
property FileInfo: TSearchRec read FFileInfo;
|
property FileInfo: TSearchRec read FFileInfo;
|
||||||
property Level: Integer read FLevel;
|
property Level: Integer read FLevel;
|
||||||
property Path: String read FPath;
|
property Path: String read FPath;
|
||||||
|
|
||||||
property Searching: Boolean read FSearching;
|
property Searching: Boolean read FSearching;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
@ -91,8 +91,6 @@ function LoadXMLConfigFromCodeBuffer(const Filename: string; Config: TXMLConfig;
|
|||||||
function SaveXMLConfigToCodeBuffer(const Filename: string; Config: TXMLConfig;
|
function SaveXMLConfigToCodeBuffer(const Filename: string; Config: TXMLConfig;
|
||||||
var ACodeBuffer: TCodeBuffer;
|
var ACodeBuffer: TCodeBuffer;
|
||||||
KeepFileAttributes: boolean): TModalResult;
|
KeepFileAttributes: boolean): TModalResult;
|
||||||
function CreateEmptyFile(const Filename: string;
|
|
||||||
ErrorButtons: TMsgDlgButtons): TModalResult;
|
|
||||||
function CheckCreatingFile(const AFilename: string;
|
function CheckCreatingFile(const AFilename: string;
|
||||||
CheckReadable: boolean;
|
CheckReadable: boolean;
|
||||||
WarnOverwrite: boolean = false;
|
WarnOverwrite: boolean = false;
|
||||||
@ -105,8 +103,7 @@ function CheckDirectoryIsWritable(const Filename: string;
|
|||||||
function CheckExecutable(const OldFilename,
|
function CheckExecutable(const OldFilename,
|
||||||
NewFilename: string; const ErrorCaption, ErrorMsg: string;
|
NewFilename: string; const ErrorCaption, ErrorMsg: string;
|
||||||
SearchInPath: boolean = true): boolean;
|
SearchInPath: boolean = true): boolean;
|
||||||
function CheckDirPathExists(const Dir,
|
function CheckDirPathExists(const Dir, ErrorCaption, ErrorMsg: string): TModalResult;
|
||||||
ErrorCaption, ErrorMsg: string): TModalResult;
|
|
||||||
function ChooseSymlink(var Filename: string; const TargetFilename: string): TModalResult;
|
function ChooseSymlink(var Filename: string; const TargetFilename: string): TModalResult;
|
||||||
function CreateSymlinkInteractive(const {%H-}LinkFilename, {%H-}TargetFilename: string;
|
function CreateSymlinkInteractive(const {%H-}LinkFilename, {%H-}TargetFilename: string;
|
||||||
{%H-}ErrorButtons: TMsgDlgButtons = []): TModalResult;
|
{%H-}ErrorButtons: TMsgDlgButtons = []): TModalResult;
|
||||||
@ -400,35 +397,6 @@ begin
|
|||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
function CreateEmptyFile(const Filename: string; ErrorButtons: TMsgDlgButtons
|
|
||||||
): TModalResult;
|
|
||||||
var
|
|
||||||
Buffer: TCodeBuffer;
|
|
||||||
begin
|
|
||||||
repeat
|
|
||||||
Buffer:=CodeToolBoss.CreateFile(Filename);
|
|
||||||
if Buffer<>nil then begin
|
|
||||||
break;
|
|
||||||
end else begin
|
|
||||||
Result:=IDEMessageDialog(lisUnableToCreateFile,
|
|
||||||
Format(lisUnableToCreateFile2, [Filename]),
|
|
||||||
mtError,ErrorButtons+[mbCancel]);
|
|
||||||
if Result<>mrRetry then exit;
|
|
||||||
end;
|
|
||||||
until false;
|
|
||||||
repeat
|
|
||||||
if Buffer.Save then begin
|
|
||||||
break;
|
|
||||||
end else begin
|
|
||||||
Result:=IDEMessageDialog(lisUnableToWriteFile,
|
|
||||||
Format(lisUnableToWriteToFile2, [Buffer.Filename]),
|
|
||||||
mtError,ErrorButtons+[mbCancel]);
|
|
||||||
if Result<>mrRetry then exit;
|
|
||||||
end;
|
|
||||||
until false;
|
|
||||||
Result:=mrOk;
|
|
||||||
end;
|
|
||||||
|
|
||||||
function CheckCreatingFile(const AFilename: string;
|
function CheckCreatingFile(const AFilename: string;
|
||||||
CheckReadable: boolean; WarnOverwrite: boolean; CreateBackup: boolean
|
CheckReadable: boolean; WarnOverwrite: boolean; CreateBackup: boolean
|
||||||
): TModalResult;
|
): TModalResult;
|
||||||
@ -613,8 +581,7 @@ begin
|
|||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
function CheckDirPathExists(const Dir,
|
function CheckDirPathExists(const Dir, ErrorCaption, ErrorMsg: string): TModalResult;
|
||||||
ErrorCaption, ErrorMsg: string): TModalResult;
|
|
||||||
begin
|
begin
|
||||||
if not DirPathExists(Dir) then begin
|
if not DirPathExists(Dir) then begin
|
||||||
Result:=IDEMessageDialog(ErrorCaption,Format(ErrorMsg,[Dir]),mtWarning,
|
Result:=IDEMessageDialog(ErrorCaption,Format(ErrorMsg,[Dir]),mtWarning,
|
||||||
|
257
ide/ideprocs.pp
257
ide/ideprocs.pp
@ -34,7 +34,7 @@ uses
|
|||||||
Classes, SysUtils, Laz_AVL_Tree,
|
Classes, SysUtils, Laz_AVL_Tree,
|
||||||
// LazUtils
|
// LazUtils
|
||||||
FileUtil, LazFileUtils, LazUtilities, LazFileCache, LazUTF8, LazUTF8Classes,
|
FileUtil, LazFileUtils, LazUtilities, LazFileCache, LazUTF8, LazUTF8Classes,
|
||||||
Laz2_XMLCfg, AvgLvlTree, LazLoggerBase, LazTracer, LazStringUtils,
|
Laz2_XMLCfg, AvgLvlTree, LazLoggerBase, LazTracer,
|
||||||
// LCL
|
// LCL
|
||||||
StdCtrls, ExtCtrls,
|
StdCtrls, ExtCtrls,
|
||||||
// CodeTools
|
// CodeTools
|
||||||
@ -42,42 +42,12 @@ uses
|
|||||||
// IDE
|
// IDE
|
||||||
LazConf;
|
LazConf;
|
||||||
|
|
||||||
type
|
|
||||||
// copy
|
|
||||||
TOnCopyFileMethod =
|
|
||||||
procedure(const Filename: string; var Copy: boolean;
|
|
||||||
Data: TObject) of object;
|
|
||||||
|
|
||||||
TCopyErrorType = (
|
|
||||||
ceSrcDirDoesNotExists,
|
|
||||||
ceCreatingDirectory,
|
|
||||||
ceCopyFileError
|
|
||||||
);
|
|
||||||
|
|
||||||
TCopyErrorData = record
|
|
||||||
Error: TCopyErrorType;
|
|
||||||
Param1: string;
|
|
||||||
Param2: string;
|
|
||||||
end;
|
|
||||||
|
|
||||||
TOnCopyErrorMethod =
|
|
||||||
procedure(const ErrorData: TCopyErrorData; var Handled: boolean;
|
|
||||||
Data: TObject) of object;
|
|
||||||
|
|
||||||
// file operations
|
// file operations
|
||||||
function BackupFileForWrite(const Filename, BackupFilename: string): boolean;
|
function BackupFileForWrite(const Filename, BackupFilename: string): boolean;
|
||||||
function ClearFile(const Filename: string; RaiseOnError: boolean): boolean;
|
|
||||||
function CreateEmptyFile(const Filename: string): boolean;
|
function CreateEmptyFile(const Filename: string): boolean;
|
||||||
function CopyFileWithMethods(const SrcFilename, DestFilename: string;
|
|
||||||
{%H-}OnCopyError: TOnCopyErrorMethod; {%H-}Data: TObject): boolean;
|
|
||||||
function CopyDirectoryWithMethods(const SrcDirectory, DestDirectory: string;
|
|
||||||
OnCopyFile: TOnCopyFileMethod; OnCopyError: TOnCopyErrorMethod;
|
|
||||||
Data: TObject): boolean;
|
|
||||||
|
|
||||||
// file names
|
// file names
|
||||||
function ConvertSpecialFileChars(const Filename: string): string;
|
|
||||||
function FilenameIsPascalSource(const Filename: string): boolean;
|
function FilenameIsPascalSource(const Filename: string): boolean;
|
||||||
function FilenameIsFormText(const Filename: string): boolean;
|
|
||||||
function ChompEndNumber(const s: string): string;
|
function ChompEndNumber(const s: string): string;
|
||||||
function ShortDisplayFilename(const aFileName: string): string;
|
function ShortDisplayFilename(const aFileName: string): string;
|
||||||
|
|
||||||
@ -85,7 +55,6 @@ function ShortDisplayFilename(const aFileName: string): string;
|
|||||||
function FindFilesCaseInsensitive(const Directory,
|
function FindFilesCaseInsensitive(const Directory,
|
||||||
CaseInsensitiveFilename: string; IgnoreExact: boolean): TStringList;
|
CaseInsensitiveFilename: string; IgnoreExact: boolean): TStringList;
|
||||||
function FindFirstFileWithExt(const Directory, Ext: string): string;
|
function FindFirstFileWithExt(const Directory, Ext: string): string;
|
||||||
function FindShortFileNameOnDisk(const Filename: string): string;
|
|
||||||
function CreateNonExistingFilename(const BaseFilename: string): string;
|
function CreateNonExistingFilename(const BaseFilename: string): string;
|
||||||
function FindFPCTool(const Executable, CompilerFilename: string): string;
|
function FindFPCTool(const Executable, CompilerFilename: string): string;
|
||||||
procedure ResolveLinksInFileList(List: TStrings; RemoveDanglingLinks: Boolean);
|
procedure ResolveLinksInFileList(List: TStrings; RemoveDanglingLinks: Boolean);
|
||||||
@ -259,40 +228,6 @@ begin
|
|||||||
exit(True);
|
exit(True);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
function FilenameIsFormText(const Filename: string): boolean;
|
|
||||||
var
|
|
||||||
Ext: string;
|
|
||||||
begin
|
|
||||||
Ext:=lowercase(ExtractFileExt(Filename));
|
|
||||||
Result:=((Ext='.lfm') or (Ext='.dfm') or (Ext='.xfm'))
|
|
||||||
and (ExtractFileNameOnly(Filename)<>'');
|
|
||||||
end;
|
|
||||||
|
|
||||||
function FindShortFileNameOnDisk(const Filename: string): string;
|
|
||||||
var
|
|
||||||
FileInfo: TSearchRec;
|
|
||||||
ADirectory: String;
|
|
||||||
ShortFilename: String;
|
|
||||||
begin
|
|
||||||
Result:='';
|
|
||||||
ADirectory:=ExtractFilePath(Filename);
|
|
||||||
if FindFirstUTF8(AppendPathDelim(ADirectory)+GetAllFilesMask,
|
|
||||||
faAnyFile,FileInfo)=0
|
|
||||||
then begin
|
|
||||||
ShortFilename:=ExtractFilename(Filename);
|
|
||||||
repeat
|
|
||||||
// check if special file
|
|
||||||
if (FileInfo.Name='.') or (FileInfo.Name='..') or (FileInfo.Name='') then
|
|
||||||
continue;
|
|
||||||
if CompareFilenames(ShortFilename,FileInfo.Name)=0 then begin
|
|
||||||
Result:=FileInfo.Name;
|
|
||||||
break;
|
|
||||||
end;
|
|
||||||
until FindNextUTF8(FileInfo)<>0;
|
|
||||||
end;
|
|
||||||
FindCloseUTF8(FileInfo);
|
|
||||||
end;
|
|
||||||
|
|
||||||
function CreateNonExistingFilename(const BaseFilename: string): string;
|
function CreateNonExistingFilename(const BaseFilename: string): string;
|
||||||
var
|
var
|
||||||
PostFix: String;
|
PostFix: String;
|
||||||
@ -1335,32 +1270,6 @@ begin
|
|||||||
Result := True;
|
Result := True;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
{-------------------------------------------------------------------------------
|
|
||||||
function ClearFile(const Filename: string; RaiseOnError: boolean): boolean;
|
|
||||||
|
|
||||||
Empty file if exists.
|
|
||||||
-------------------------------------------------------------------------------}
|
|
||||||
function ClearFile(const Filename: string; RaiseOnError: boolean): boolean;
|
|
||||||
var
|
|
||||||
fs: TFileStreamUTF8;
|
|
||||||
begin
|
|
||||||
if FileExistsUTF8(Filename) then begin
|
|
||||||
try
|
|
||||||
InvalidateFileStateCache;
|
|
||||||
fs:=TFileStreamUTF8.Create(Filename,fmOpenWrite);
|
|
||||||
fs.Size:=0;
|
|
||||||
fs.Free;
|
|
||||||
except
|
|
||||||
on E: Exception do begin
|
|
||||||
Result:=false;
|
|
||||||
if RaiseOnError then raise;
|
|
||||||
exit;
|
|
||||||
end;
|
|
||||||
end;
|
|
||||||
end;
|
|
||||||
Result:=true;
|
|
||||||
end;
|
|
||||||
|
|
||||||
function FindProgram(ProgramName, BaseDirectory: string;
|
function FindProgram(ProgramName, BaseDirectory: string;
|
||||||
WithBaseDirectory: boolean): string;
|
WithBaseDirectory: boolean): string;
|
||||||
var
|
var
|
||||||
@ -1405,31 +1314,6 @@ begin
|
|||||||
Point.Y:=StrToIntDef(copy(s,p+1,length(s)-p),DefaultPoint.Y);
|
Point.Y:=StrToIntDef(copy(s,p+1,length(s)-p),DefaultPoint.Y);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
{-------------------------------------------------------------------------------
|
|
||||||
ConvertSpecialFileChars
|
|
||||||
|
|
||||||
Params: const Filename: string
|
|
||||||
Result: string
|
|
||||||
|
|
||||||
Replaces all spaces in a filename.
|
|
||||||
-------------------------------------------------------------------------------}
|
|
||||||
function ConvertSpecialFileChars(const Filename: string): string;
|
|
||||||
const
|
|
||||||
SpecialChar = '\';
|
|
||||||
var i: integer;
|
|
||||||
begin
|
|
||||||
Result:=Filename;
|
|
||||||
i:=1;
|
|
||||||
while (i<=length(Result)) do begin
|
|
||||||
if Result[i]<>' ' then begin
|
|
||||||
inc(i);
|
|
||||||
end else begin
|
|
||||||
Result:=LeftStr(Result,i-1)+SpecialChar+RightStr(Result,length(Result)-i+1);
|
|
||||||
inc(i,2);
|
|
||||||
end;
|
|
||||||
end;
|
|
||||||
end;
|
|
||||||
|
|
||||||
function GetCurrentUserName: string;
|
function GetCurrentUserName: string;
|
||||||
begin
|
begin
|
||||||
Result:=GetEnvironmentVariableUTF8('USER');
|
Result:=GetEnvironmentVariableUTF8('USER');
|
||||||
@ -1445,96 +1329,6 @@ begin
|
|||||||
GetProgramSearchPath := GetEnvironmentVariableUTF8('PATH');
|
GetProgramSearchPath := GetEnvironmentVariableUTF8('PATH');
|
||||||
end;
|
end;
|
||||||
|
|
||||||
function CopyDirectoryWithMethods(const SrcDirectory, DestDirectory: string;
|
|
||||||
OnCopyFile: TOnCopyFileMethod; OnCopyError: TOnCopyErrorMethod;
|
|
||||||
Data: TObject): boolean;
|
|
||||||
var
|
|
||||||
SrcDir, DestDir: string;
|
|
||||||
|
|
||||||
function HandleError(ErrorNumber: TCopyErrorType;
|
|
||||||
const Param1, Param2: string): boolean;
|
|
||||||
var
|
|
||||||
ErrorData: TCopyErrorData;
|
|
||||||
begin
|
|
||||||
Result:=false;
|
|
||||||
if Assigned(OnCopyError) then begin
|
|
||||||
ErrorData.Error:=ErrorNumber;
|
|
||||||
ErrorData.Param1:=Param1;
|
|
||||||
ErrorData.Param2:=Param2;
|
|
||||||
OnCopyError(ErrorData,Result,Data);
|
|
||||||
end;
|
|
||||||
end;
|
|
||||||
|
|
||||||
function CopyDir(const CurSrcDir, CurDestDir: string): boolean;
|
|
||||||
// both dirs must end with PathDelim
|
|
||||||
var
|
|
||||||
FileInfo: TSearchRec;
|
|
||||||
CurFilename,
|
|
||||||
SubSrcDir, SubDestDir,
|
|
||||||
DestFilename: string;
|
|
||||||
DoCopy: boolean;
|
|
||||||
begin
|
|
||||||
Result:=false;
|
|
||||||
if (CompareFilenames(CurSrcDir,DestDir)=0)
|
|
||||||
or (CompareFilenames(CurDestDir,SrcDir)=0) then begin
|
|
||||||
// copying into subdirectory. For example: /home/ to /home/user/
|
|
||||||
// or copying from subdirectory. For example: /home/user/ to /home/
|
|
||||||
// -> skip
|
|
||||||
Result:=true;
|
|
||||||
exit;
|
|
||||||
end;
|
|
||||||
|
|
||||||
if not ForceDirectory(CurDestDir)
|
|
||||||
and not HandleError(ceCreatingDirectory,CurDestDir,'') then exit;
|
|
||||||
|
|
||||||
if FindFirstUTF8(CurSrcDir+GetAllFilesMask,faAnyFile,FileInfo)=0 then begin
|
|
||||||
repeat
|
|
||||||
// check if special file
|
|
||||||
if (FileInfo.Name='.') or (FileInfo.Name='..') or (FileInfo.Name='')
|
|
||||||
then continue;
|
|
||||||
CurFilename:=CurSrcDir+FileInfo.Name;
|
|
||||||
// check if src file
|
|
||||||
if FilenameIsMatching(DestDirectory,CurFilename,false) then continue;
|
|
||||||
|
|
||||||
// check user filter
|
|
||||||
if Assigned(OnCopyFile) then begin
|
|
||||||
DoCopy:=true;
|
|
||||||
OnCopyFile(CurFilename,DoCopy,Data);
|
|
||||||
if not DoCopy then continue;
|
|
||||||
end;
|
|
||||||
|
|
||||||
// copy
|
|
||||||
if (FileInfo.Attr and faDirectory)>0 then begin
|
|
||||||
// copy sub directory
|
|
||||||
SubSrcDir:=AppendPathDelim(CurFilename);
|
|
||||||
SubDestDir:=AppendPathDelim(CurDestDir+FileInfo.Name);
|
|
||||||
if not CopyDir(SubSrcDir,SubDestDir) then exit;
|
|
||||||
end else begin
|
|
||||||
// copy file
|
|
||||||
DestFilename:=CurDestDir+FileInfo.Name;
|
|
||||||
if not CopyFileWithMethods(CurFilename,DestFilename,OnCopyError,Data)
|
|
||||||
then
|
|
||||||
exit;
|
|
||||||
end;
|
|
||||||
until FindNextUTF8(FileInfo)<>0;
|
|
||||||
end;
|
|
||||||
FindCloseUTF8(FileInfo);
|
|
||||||
|
|
||||||
Result:=true;
|
|
||||||
end;
|
|
||||||
|
|
||||||
begin
|
|
||||||
Result:=true;
|
|
||||||
SrcDir:=AppendPathDelim(TrimAndExpandDirectory(SrcDirectory));
|
|
||||||
DestDir:=AppendPathDelim(TrimAndExpandDirectory(DestDirectory));
|
|
||||||
if CompareFilenames(SrcDir,DestDir)=0 then exit;
|
|
||||||
|
|
||||||
if (not DirPathExists(SrcDir))
|
|
||||||
and not HandleError(ceSrcDirDoesNotExists,SrcDir,'') then exit;
|
|
||||||
|
|
||||||
CopyDir(SrcDir,DestDirectory);
|
|
||||||
end;
|
|
||||||
|
|
||||||
function CreateEmptyFile(const Filename: string): boolean;
|
function CreateEmptyFile(const Filename: string): boolean;
|
||||||
var
|
var
|
||||||
fs: TFileStreamUTF8;
|
fs: TFileStreamUTF8;
|
||||||
@ -1549,55 +1343,6 @@ begin
|
|||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
function CopyFileWithMethods(const SrcFilename, DestFilename: string;
|
|
||||||
OnCopyError: TOnCopyErrorMethod; Data: TObject): boolean;
|
|
||||||
var
|
|
||||||
SrcFileStream, DestFileStream: TFileStreamUTF8;
|
|
||||||
{$IFdef MSWindows}
|
|
||||||
OldAttr: Longint;
|
|
||||||
{$ELSE}
|
|
||||||
OldInfo: Stat;
|
|
||||||
{$ENDIF}
|
|
||||||
begin
|
|
||||||
Result:=false;
|
|
||||||
if CompareFilenames(SrcFilename,DestFilename)=0 then exit;
|
|
||||||
|
|
||||||
// read file attributes
|
|
||||||
{$IFdef MSWindows}
|
|
||||||
OldAttr:=FileGetAttrUTF8(SrcFilename);
|
|
||||||
{$ELSE}
|
|
||||||
FpStat(SrcFilename,OldInfo{%H-});
|
|
||||||
{$ENDIF}
|
|
||||||
|
|
||||||
// copy file
|
|
||||||
try
|
|
||||||
SrcFileStream:=TFileStreamUTF8.Create(SrcFilename,fmOpenRead);
|
|
||||||
try
|
|
||||||
InvalidateFileStateCache;
|
|
||||||
DestFileStream:=TFileStreamUTF8.Create(DestFilename,fmCreate);
|
|
||||||
try
|
|
||||||
DestFileStream.CopyFrom(SrcFileStream,SrcFileStream.Size);
|
|
||||||
finally
|
|
||||||
DestFileStream.Free;
|
|
||||||
end;
|
|
||||||
finally
|
|
||||||
SrcFileStream.Free;
|
|
||||||
end;
|
|
||||||
except
|
|
||||||
exit;
|
|
||||||
end;
|
|
||||||
|
|
||||||
// copy file attributes
|
|
||||||
{$IFdef MSWindows}
|
|
||||||
FileSetAttrUTF8(DestFileName,OldAttr);
|
|
||||||
{$ELSE}
|
|
||||||
FpChmod(DestFilename, OldInfo.st_Mode and (STAT_IRWXO+STAT_IRWXG+STAT_IRWXU
|
|
||||||
+STAT_ISUID+STAT_ISGID+STAT_ISVTX));
|
|
||||||
{$ENDIF}
|
|
||||||
|
|
||||||
Result:=true;
|
|
||||||
end;
|
|
||||||
|
|
||||||
function CompareMemStreamText(s1, s2: TMemoryStream): Boolean;
|
function CompareMemStreamText(s1, s2: TMemoryStream): Boolean;
|
||||||
// compare text in s2, s2 ignoring line ends
|
// compare text in s2, s2 ignoring line ends
|
||||||
var
|
var
|
||||||
|
Loading…
Reference in New Issue
Block a user