mirror of
https://github.com/doublecmd/doublecmd.git
synced 2026-06-21 09:58:13 +00:00
ADD: Retry deletion operation as administrator
This commit is contained in:
parent
47d80867b2
commit
2001781374
6 changed files with 72 additions and 29 deletions
|
|
@ -34,7 +34,7 @@ type
|
|||
procedure DeleteSubDirectory(const aFile: TFile);
|
||||
|
||||
protected
|
||||
procedure ProcessFile(aFile: TFile);
|
||||
function ProcessFile(aFile: TFile): Boolean;
|
||||
procedure ProcessList(aFiles: TFiles);
|
||||
function ShowError(sMessage: String): TFileSourceOperationUIResponse;
|
||||
procedure LogMessage(sMessage: String; logOptions: TLogOptions; logMsgType: TLogMsgType);
|
||||
|
|
@ -59,7 +59,7 @@ type
|
|||
implementation
|
||||
|
||||
uses
|
||||
DCOSUtils, uLng, uFileSystemUtil, uTrash;
|
||||
DCOSUtils, uLng, uFileSystemUtil, uTrash, uAdministrator, uOSUtils;
|
||||
|
||||
constructor TFileSystemDeleteOperation.Create(aTargetFileSource: IFileSource;
|
||||
var theFilesToDelete: TFiles);
|
||||
|
|
@ -155,7 +155,12 @@ begin
|
|||
end;
|
||||
end;
|
||||
|
||||
procedure TFileSystemDeleteOperation.ProcessFile(aFile: TFile);
|
||||
function TFileSystemDeleteOperation.ProcessFile(aFile: TFile): Boolean;
|
||||
const
|
||||
ResponsesTrash: array[0..4] of TFileSourceOperationUIResponse
|
||||
= (fsourYes, fsourAll, fsourSkip, fsourSkipAll, fsourAbort);
|
||||
ResponsesError: array[0..3] of TFileSourceOperationUIResponse
|
||||
= (fsourRetry, fsourSkip, fsourSkipAll, fsourAbort);
|
||||
var
|
||||
FileName: String;
|
||||
bRetry: Boolean;
|
||||
|
|
@ -163,7 +168,9 @@ var
|
|||
sMessage, sQuestion: String;
|
||||
logOptions: TLogOptions;
|
||||
DeleteResult: Boolean;
|
||||
PossibleResponses: array of TFileSourceOperationUIResponse;
|
||||
begin
|
||||
Result := True;
|
||||
FileName := aFile.FullPath;
|
||||
|
||||
if FileIsReadOnly(aFile.Attributes) then
|
||||
|
|
@ -216,25 +223,36 @@ begin
|
|||
begin
|
||||
case FDeleteDirectly of
|
||||
fsoogNone:
|
||||
case AskQuestion(Format(rsMsgDelToTrashForce, [FileName]), '',
|
||||
[fsourYes, fsourAll, fsourSkip, fsourSkipAll, fsourAbort],
|
||||
fsourYes, fsourAbort) of
|
||||
fsourYes:
|
||||
RemoveDirectly:= fsoogYes;
|
||||
fsourAll:
|
||||
begin
|
||||
FDeleteDirectly := fsoogYes;
|
||||
begin
|
||||
if AdministratorPrivileges then
|
||||
PossibleResponses:= ResponsesTrash
|
||||
else begin
|
||||
SetLength(PossibleResponses, Length(ResponsesTrash) + 1);
|
||||
Move(ResponsesTrash[0], PossibleResponses[0], SizeOf(ResponsesTrash));
|
||||
PossibleResponses[High(PossibleResponses)]:= fsourRetryAdmin;
|
||||
end;
|
||||
case AskQuestion(Format(rsMsgDelToTrashForce, [FileName]), '',
|
||||
PossibleResponses,
|
||||
fsourYes, fsourAbort) of
|
||||
fsourYes:
|
||||
RemoveDirectly:= fsoogYes;
|
||||
end;
|
||||
fsourSkip:
|
||||
RemoveDirectly:= fsoogNo;
|
||||
fsourSkipAll:
|
||||
begin
|
||||
FDeleteDirectly := fsoogNo;
|
||||
fsourAll:
|
||||
begin
|
||||
FDeleteDirectly := fsoogYes;
|
||||
RemoveDirectly:= fsoogYes;
|
||||
end;
|
||||
fsourSkip:
|
||||
RemoveDirectly:= fsoogNo;
|
||||
end;
|
||||
fsourAbort:
|
||||
RaiseAbortOperation;
|
||||
fsourSkipAll:
|
||||
begin
|
||||
FDeleteDirectly := fsoogNo;
|
||||
RemoveDirectly:= fsoogNo;
|
||||
end;
|
||||
fsourAbort:
|
||||
RaiseAbortOperation;
|
||||
fsourRetryAdmin:
|
||||
Exit(False);
|
||||
end;
|
||||
end;
|
||||
fsoogYes:
|
||||
RemoveDirectly:= fsoogYes;
|
||||
|
|
@ -295,8 +313,15 @@ begin
|
|||
LogMessage(sMessage, logOptions, lmtError)
|
||||
else
|
||||
begin
|
||||
if AdministratorPrivileges then
|
||||
PossibleResponses:= ResponsesError
|
||||
else begin
|
||||
SetLength(PossibleResponses, Length(ResponsesError) + 1);
|
||||
Move(ResponsesError[0], PossibleResponses[0], SizeOf(ResponsesError));
|
||||
PossibleResponses[High(PossibleResponses)]:= fsourRetryAdmin;
|
||||
end;
|
||||
case AskQuestion(sQuestion, '',
|
||||
[fsourRetry, fsourSkip, fsourSkipAll, fsourAbort],
|
||||
PossibleResponses,
|
||||
fsourRetry, fsourAbort) of
|
||||
fsourRetry:
|
||||
bRetry := True;
|
||||
|
|
@ -304,6 +329,8 @@ begin
|
|||
FSkipErrors := True;
|
||||
fsourAbort:
|
||||
RaiseAbortOperation;
|
||||
fsourRetryAdmin:
|
||||
Exit(False);
|
||||
end;
|
||||
end;
|
||||
end;
|
||||
|
|
@ -322,7 +349,11 @@ begin
|
|||
FStatistics.CurrentFile := aFile.FullPath;
|
||||
UpdateStatistics(FStatistics);
|
||||
|
||||
ProcessFile(aFile);
|
||||
if not ProcessFile(aFile) then
|
||||
begin
|
||||
Delete(Self, aFiles, CurrentFileIndex);
|
||||
Exit;
|
||||
end;
|
||||
|
||||
with FStatistics do
|
||||
begin
|
||||
|
|
|
|||
|
|
@ -35,13 +35,13 @@ const
|
|||
(msmbOK, msmbOK, msmbNo, msmbYes, msmbCancel, msmbNone, msmbAppend, msmbResume,
|
||||
msmbCopyInto, msmbCopyIntoAll, msmbOverwrite, msmbOverwriteAll, msmbOverwriteOlder,
|
||||
msmbOverwriteSmaller, msmbOverwriteLarger, msmbAutoRenameSource, msmbRenameSource,
|
||||
msmbSkip, msmbSkipAll, msmbIgnore, msmbIgnoreAll, msmbAll, msmbRetry, msmbAbort);
|
||||
msmbSkip, msmbSkipAll, msmbIgnore, msmbIgnoreAll, msmbAll, msmbRetry, msmbAbort, msmbRetryAdmin);
|
||||
|
||||
ResultToResponse: array[TMyMsgResult] of TFileSourceOperationUIResponse =
|
||||
(fsourOk, fsourNo, fsourYes, fsourCancel, fsourNone, fsourAppend, fsourResume,
|
||||
fsourCopyInto, fsourCopyIntoAll, fsourOverwrite, fsourOverwriteAll, fsourOverwriteOlder,
|
||||
fsourOverwriteSmaller, fsourOverwriteLarger, fsourAutoRenameSource, fsourRenameSource,
|
||||
fsourSkip, fsourSkipAll, fsourIgnore, fsourIgnoreAll, fsourAll, fsourRetry, fsourAbort);
|
||||
fsourSkip, fsourSkipAll, fsourIgnore, fsourIgnoreAll, fsourAll, fsourRetry, fsourAbort, fsourRetryAdmin);
|
||||
|
||||
constructor TFileSourceOperationMessageBoxesUI.Create;
|
||||
begin
|
||||
|
|
|
|||
|
|
@ -33,7 +33,8 @@ type
|
|||
fsourIgnoreAll,
|
||||
fsourAll,
|
||||
fsourRetry,
|
||||
fsourAbort);
|
||||
fsourAbort,
|
||||
fsourRetryAdmin);
|
||||
|
||||
{en
|
||||
General interface for communication: operation <-> user.
|
||||
|
|
|
|||
|
|
@ -48,13 +48,13 @@ type
|
|||
mmrAppend, mmrResume, mmrCopyInto, mmrCopyIntoAll,
|
||||
mmrOverwrite, mmrOverwriteAll, mmrOverwriteOlder,
|
||||
mmrOverwriteSmaller, mmrOverwriteLarger, mmrAutoRenameSource, mmrRenameSource,
|
||||
mmrSkip, mmrSkipAll, mmrIgnore, mmrIgnoreAll, mmrAll, mmrRetry, mmrAbort);
|
||||
mmrSkip, mmrSkipAll, mmrIgnore, mmrIgnoreAll, mmrAll, mmrRetry, mmrAbort, mmrRetryAdmin);
|
||||
|
||||
TMyMsgButton=(msmbOK, msmbNo, msmbYes, msmbCancel, msmbNone,
|
||||
msmbAppend, msmbResume, msmbCopyInto, msmbCopyIntoAll,
|
||||
msmbOverwrite, msmbOverwriteAll, msmbOverwriteOlder,
|
||||
msmbOverwriteSmaller, msmbOverwriteLarger, msmbAutoRenameSource, msmbRenameSource,
|
||||
msmbSkip, msmbSkipAll, msmbIgnore, msmbIgnoreAll, msmbAll, msmbRetry, msmbAbort);
|
||||
msmbSkip, msmbSkipAll, msmbIgnore, msmbIgnoreAll, msmbAll, msmbRetry, msmbAbort, msmbRetryAdmin);
|
||||
|
||||
|
||||
{ TDialogMainThread }
|
||||
|
|
@ -768,6 +768,7 @@ begin
|
|||
cLngButton[msmbAll] := rsDlgButtonAll;
|
||||
cLngButton[msmbRetry] := rsDlgButtonRetry;
|
||||
cLngButton[msmbAbort] := rsDlgButtonAbort;
|
||||
cLngButton[msmbRetryAdmin] := rsDlgButtonRetryAdmin;
|
||||
|
||||
for I:= Low(TMyMsgButton) to High(TMyMsgButton) do
|
||||
begin
|
||||
|
|
|
|||
|
|
@ -26,7 +26,7 @@ implementation
|
|||
|
||||
uses
|
||||
Forms, Dialogs, SysUtils, uOSUtils, uDCUtils, uGlobsPaths, getopts, uDebug,
|
||||
uLng, uClipboard;
|
||||
uLng, uClipboard, uAdministrator;
|
||||
|
||||
function DecodePath(const Path: String): String;
|
||||
begin
|
||||
|
|
@ -41,7 +41,7 @@ procedure ProcessCommandLineParams;
|
|||
var
|
||||
Option: AnsiChar = #0;
|
||||
OptionIndex: LongInt = 0;
|
||||
Options: array[1..5] of TOption;
|
||||
Options: array[1..6] of TOption;
|
||||
OptionUnknown: String;
|
||||
begin
|
||||
FillChar(Options, SizeOf(Options), #0);
|
||||
|
|
@ -67,6 +67,11 @@ begin
|
|||
begin
|
||||
Name:= 'no-splash';
|
||||
end;
|
||||
with Options[6] do
|
||||
begin
|
||||
Name:= 'operation';
|
||||
Has_arg:= 1;
|
||||
end;
|
||||
FillChar(CommandLineParams, SizeOf(TCommandLineParams), #0);
|
||||
repeat
|
||||
try
|
||||
|
|
@ -102,6 +107,10 @@ begin
|
|||
begin
|
||||
CommandLineParams.NoSplash:= True;
|
||||
end;
|
||||
6:
|
||||
begin
|
||||
ExecuteOperation(ParamStrU(TrimQuotes(OptArg)));
|
||||
end;
|
||||
end;
|
||||
end;
|
||||
'L', 'l': CommandLineParams.LeftPath:= DecodePath(ParamStrU(OptArg));
|
||||
|
|
|
|||
|
|
@ -320,6 +320,7 @@ resourcestring
|
|||
rsDlgButtonRetry = 'Re&try';
|
||||
rsDlgButtonAbort = 'Ab&ort';
|
||||
rsDlgButtonOther = 'Ot&her';
|
||||
rsDlgButtonRetryAdmin = 'As Ad&ministrator';
|
||||
|
||||
rsDlgButtonContinue = '&Continue';
|
||||
rsDlgButtonExitProgram = 'E&xit program';
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue