mirror of
https://github.com/doublecmd/doublecmd.git
synced 2026-06-21 09:58:13 +00:00
ADD: FileGetAttrUAC function
This commit is contained in:
parent
660e8d4c65
commit
e99bc3788b
3 changed files with 61 additions and 5 deletions
|
|
@ -11,6 +11,7 @@ procedure PushPop(var Elevate: TDuplicates);
|
|||
|
||||
function FileExistsUAC(const FileName: String): Boolean;
|
||||
function FileGetAttrUAC(const FileName: String; FollowLink: Boolean = False): TFileAttrs;
|
||||
function FileGetAttrUAC(const FileName: String; out Attr: TFileAttributeData): Boolean;
|
||||
function FileSetAttrUAC(const FileName: String; Attr: TFileAttrs): Boolean;
|
||||
function FileSetTimeUAC(const FileName: String;
|
||||
ModificationTime: DCBasicTypes.TFileTime;
|
||||
|
|
@ -142,6 +143,21 @@ begin
|
|||
end;
|
||||
end;
|
||||
|
||||
function FileGetAttrUAC(const FileName: String; out Attr: TFileAttributeData): Boolean;
|
||||
var
|
||||
LastError: Integer;
|
||||
begin
|
||||
Result:= mbFileGetAttr(FileName, Attr);
|
||||
if (not Result) and ElevationRequired then
|
||||
begin
|
||||
LastError:= GetLastOSError;
|
||||
if RequestElevation(rsElevationRequiredGetAttributes, FileName) then
|
||||
Result:= TWorkerProxy.Instance.FileGetAttr(FileName, Attr)
|
||||
else
|
||||
SetLastOSError(LastError);
|
||||
end;
|
||||
end;
|
||||
|
||||
function FileSetAttrUAC(const FileName: String; Attr: TFileAttrs): Boolean;
|
||||
var
|
||||
LastError: Integer;
|
||||
|
|
|
|||
|
|
@ -37,6 +37,7 @@ type
|
|||
function Terminate: Boolean;
|
||||
function FileExists(const FileName: String): LongBool; inline;
|
||||
function FileGetAttr(const FileName: String; FollowLink: LongBool): TFileAttrs; inline;
|
||||
function FileGetAttr(const FileName: String; out Attr: TFileAttributeData): LongBool;
|
||||
function FileSetAttr(const FileName: String; Attr: TFileAttrs): LongBool; inline;
|
||||
function FileSetTime(const FileName: String;
|
||||
ModificationTime: DCBasicTypes.TFileTime;
|
||||
|
|
@ -355,6 +356,40 @@ begin
|
|||
Result:= TFileAttrs(ProcessObject(RPC_FileGetAttr, FileName, UInt32(FollowLink)));
|
||||
end;
|
||||
|
||||
function TWorkerProxy.FileGetAttr(const FileName: String; out
|
||||
Attr: TFileAttributeData): LongBool;
|
||||
var
|
||||
LastError: Integer;
|
||||
Stream: TMemoryStream;
|
||||
begin
|
||||
Result:= False;
|
||||
try
|
||||
Stream:= TMemoryStream.Create;
|
||||
try
|
||||
// Write header
|
||||
Stream.WriteDWord(RPC_FileGetAttr);
|
||||
Stream.Seek(SizeOf(UInt32), soFromCurrent);
|
||||
// Write arguments
|
||||
Stream.WriteAnsiString(FileName);
|
||||
Stream.WriteDWord(maxSmallint);
|
||||
// Write data size
|
||||
Stream.Seek(SizeOf(UInt32), soFromBeginning);
|
||||
Stream.WriteDWord(Stream.Size - SizeOf(UInt32) * 2);
|
||||
// Send command
|
||||
FClient.WriteBuffer(Stream.Memory^, Stream.Size);
|
||||
// Receive command result
|
||||
FClient.ReadBuffer(Result, SizeOf(Result));
|
||||
FClient.ReadBuffer(LastError, SizeOf(LastError));
|
||||
FClient.ReadBuffer(Attr, SizeOf(TFileAttributeData));
|
||||
SetLastOSError(LastError);
|
||||
finally
|
||||
Stream.Free;
|
||||
end;
|
||||
except
|
||||
on E: Exception do DCDebug(E.Message);
|
||||
end;
|
||||
end;
|
||||
|
||||
function TWorkerProxy.FileSetAttr(const FileName: String; Attr: TFileAttrs): LongBool;
|
||||
begin
|
||||
Result:= ProcessObject(RPC_FileSetAttr, FileName, Attr);
|
||||
|
|
|
|||
|
|
@ -111,6 +111,7 @@ var
|
|||
CreationTime: TFileTime;
|
||||
LastAccessTime: TFileTime;
|
||||
ModificationTime: TFileTime;
|
||||
FileAttr: TFileAttributeData;
|
||||
|
||||
procedure WriteSearchRec(Data: TMemoryStream; SearchRec: PSearchRecEx);
|
||||
begin
|
||||
|
|
@ -145,16 +146,20 @@ begin
|
|||
RPC_FileGetAttr:
|
||||
begin
|
||||
FileName:= ARequest.ReadAnsiString;
|
||||
Result:= LongBool(ARequest.ReadDWord);
|
||||
Mode:= ARequest.ReadDWord;
|
||||
DCDebug('FileGetAttr ', FileName);
|
||||
if not Result then
|
||||
Result:= LongBool(mbFileGetAttr(FileName))
|
||||
else begin
|
||||
Result:= LongBool(mbFileGetAttrNoLinks(FileName));
|
||||
case Mode of
|
||||
Ord(LongBool(False)):
|
||||
Result:= LongBool(mbFileGetAttr(FileName));
|
||||
Ord(LongBool(True)):
|
||||
Result:= LongBool(mbFileGetAttrNoLinks(FileName));
|
||||
maxSmallint:
|
||||
Result:= LongBool(mbFileGetAttr(FileName, FileAttr));
|
||||
end;
|
||||
LastError:= GetLastOSError;
|
||||
ATransport.WriteBuffer(Result, SizeOf(Result));
|
||||
ATransport.WriteBuffer(LastError, SizeOf(LastError));
|
||||
if (Mode = maxSmallint) then ATransport.WriteBuffer(FileAttr, SizeOf(FileAttr));
|
||||
end;
|
||||
RPC_FileSetAttr:
|
||||
begin
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue