mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-08-12 11:56:45 +02:00
LazUtils: move more Utf8 file routines to LazFileUtils (and inline them in FileUtil):
ForceDirectory, DirectoryIsWritable. git-svn-id: trunk@41356 -
This commit is contained in:
parent
58a3351361
commit
cb33ec967a
@ -430,23 +430,8 @@ end;
|
||||
function ForceDirectory(DirectoryName: string): boolean;
|
||||
------------------------------------------------------------------------------}
|
||||
function ForceDirectory(DirectoryName: string): boolean;
|
||||
var i: integer;
|
||||
Dir: string;
|
||||
begin
|
||||
DoDirSeparators(DirectoryName);
|
||||
DirectoryName := AppendPathDelim(DirectoryName);
|
||||
i:=1;
|
||||
while i<=length(DirectoryName) do begin
|
||||
if DirectoryName[i]=PathDelim then begin
|
||||
Dir:=copy(DirectoryName,1,i-1);
|
||||
if not DirPathExists(Dir) then begin
|
||||
Result:=CreateDirUTF8(Dir);
|
||||
if not Result then exit;
|
||||
end;
|
||||
end;
|
||||
inc(i);
|
||||
end;
|
||||
Result:=true;
|
||||
Result := LazFileUtils.ForceDirectory(DirectoryName);
|
||||
end;
|
||||
|
||||
{------------------------------------------------------------------------------
|
||||
@ -508,22 +493,8 @@ begin
|
||||
end;
|
||||
|
||||
function DirectoryIsWritable(const DirectoryName: string): boolean;
|
||||
var
|
||||
TempFilename: String;
|
||||
fs: TFileStream;
|
||||
s: String;
|
||||
begin
|
||||
TempFilename:=GetTempFilename(DirectoryName,'tstperm');
|
||||
Result:=false;
|
||||
try
|
||||
fs:=TFileStream.Create(UTF8ToSys(TempFilename),fmCreate);
|
||||
s:='WriteTest';
|
||||
fs.Write(s[1],length(s));
|
||||
fs.Free;
|
||||
DeleteFileUTF8(TempFilename);
|
||||
Result:=true;
|
||||
except
|
||||
end;
|
||||
Result := LazFileUtils.DirectoryIsWritable(DirectoryName);
|
||||
end;
|
||||
|
||||
{------------------------------------------------------------------------------
|
||||
|
@ -94,10 +94,10 @@ function TryReadAllLinks(const Filename: string): string; // if a link is broken
|
||||
|
||||
// directories
|
||||
function DirPathExists(const FileName: String): Boolean; inline;
|
||||
function ForceDirectory(DirectoryName: string): boolean;
|
||||
function ForceDirectory(DirectoryName: string): boolean; inline;
|
||||
function DeleteDirectory(const DirectoryName: string; OnlyChildren: boolean): boolean;
|
||||
function ProgramDirectory: string;
|
||||
function DirectoryIsWritable(const DirectoryName: string): boolean;
|
||||
function DirectoryIsWritable(const DirectoryName: string): boolean; inline;
|
||||
|
||||
// filename parts
|
||||
const
|
||||
|
@ -430,13 +430,13 @@ end;
|
||||
function DirectoryIsWritable(const DirectoryName: string): boolean;
|
||||
var
|
||||
TempFilename: String;
|
||||
fs: TFileStream;
|
||||
fs: TFileStreamUtf8;
|
||||
s: String;
|
||||
begin
|
||||
TempFilename:=SysUtils.GetTempFilename(AppendPathDelim(DirectoryName),'tstperm');
|
||||
Result:=false;
|
||||
try
|
||||
fs:=TFileStream.Create(UTF8ToSys(TempFilename),fmCreate);
|
||||
fs:=TFileStreamUtf8.Create(TempFilename, fmCreate);
|
||||
s:='WriteTest';
|
||||
fs.Write(s[1],length(s));
|
||||
fs.Free;
|
||||
|
Loading…
Reference in New Issue
Block a user