mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-11-01 13:39:29 +01: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;
|
||||||
------------------------------------------------------------------------------}
|
------------------------------------------------------------------------------}
|
||||||
function ForceDirectory(DirectoryName: string): boolean;
|
function ForceDirectory(DirectoryName: string): boolean;
|
||||||
var i: integer;
|
|
||||||
Dir: string;
|
|
||||||
begin
|
begin
|
||||||
DoDirSeparators(DirectoryName);
|
Result := LazFileUtils.ForceDirectory(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;
|
|
||||||
end;
|
end;
|
||||||
|
|
||||||
{------------------------------------------------------------------------------
|
{------------------------------------------------------------------------------
|
||||||
@ -508,22 +493,8 @@ begin
|
|||||||
end;
|
end;
|
||||||
|
|
||||||
function DirectoryIsWritable(const DirectoryName: string): boolean;
|
function DirectoryIsWritable(const DirectoryName: string): boolean;
|
||||||
var
|
|
||||||
TempFilename: String;
|
|
||||||
fs: TFileStream;
|
|
||||||
s: String;
|
|
||||||
begin
|
begin
|
||||||
TempFilename:=GetTempFilename(DirectoryName,'tstperm');
|
Result := LazFileUtils.DirectoryIsWritable(DirectoryName);
|
||||||
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;
|
|
||||||
end;
|
end;
|
||||||
|
|
||||||
{------------------------------------------------------------------------------
|
{------------------------------------------------------------------------------
|
||||||
|
|||||||
@ -94,10 +94,10 @@ function TryReadAllLinks(const Filename: string): string; // if a link is broken
|
|||||||
|
|
||||||
// directories
|
// directories
|
||||||
function DirPathExists(const FileName: String): Boolean; inline;
|
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 DeleteDirectory(const DirectoryName: string; OnlyChildren: boolean): boolean;
|
||||||
function ProgramDirectory: string;
|
function ProgramDirectory: string;
|
||||||
function DirectoryIsWritable(const DirectoryName: string): boolean;
|
function DirectoryIsWritable(const DirectoryName: string): boolean; inline;
|
||||||
|
|
||||||
// filename parts
|
// filename parts
|
||||||
const
|
const
|
||||||
|
|||||||
@ -430,13 +430,13 @@ end;
|
|||||||
function DirectoryIsWritable(const DirectoryName: string): boolean;
|
function DirectoryIsWritable(const DirectoryName: string): boolean;
|
||||||
var
|
var
|
||||||
TempFilename: String;
|
TempFilename: String;
|
||||||
fs: TFileStream;
|
fs: TFileStreamUtf8;
|
||||||
s: String;
|
s: String;
|
||||||
begin
|
begin
|
||||||
TempFilename:=SysUtils.GetTempFilename(AppendPathDelim(DirectoryName),'tstperm');
|
TempFilename:=SysUtils.GetTempFilename(AppendPathDelim(DirectoryName),'tstperm');
|
||||||
Result:=false;
|
Result:=false;
|
||||||
try
|
try
|
||||||
fs:=TFileStream.Create(UTF8ToSys(TempFilename),fmCreate);
|
fs:=TFileStreamUtf8.Create(TempFilename, fmCreate);
|
||||||
s:='WriteTest';
|
s:='WriteTest';
|
||||||
fs.Write(s[1],length(s));
|
fs.Write(s[1],length(s));
|
||||||
fs.Free;
|
fs.Free;
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user