Quellcode durchsuchen

FIX: Show error when cannot move file

Alexander Koblov vor 4 Jahren
Ursprung
Commit
9cf8a4ddd3
2 geänderte Dateien mit 20 neuen und 4 gelöschten Zeilen
  1. 19 4
      src/filesources/filesystem/ufilesystemutil.pas
  2. 1 0
      src/ulng.pas

+ 19 - 4
src/filesources/filesystem/ufilesystemutil.pas

@@ -74,6 +74,7 @@ type
 {$IF DEFINED(UNIX)}
     FSkipAllSpecialFiles: Boolean;
 {$ENDIF}
+    FSkipRenameError: Boolean;
     FSkipOpenForReadingError: Boolean;
     FSkipOpenForWritingError: Boolean;
     FSkipReadError: Boolean;
@@ -847,14 +848,28 @@ function TFileSystemOperationHelper.MoveFile(SourceFile: TFile; TargetFileName:
   Mode: TFileSystemOperationHelperCopyMode): Boolean;
 var
   Message: String;
+  RetryRename: Boolean;
   RetryDelete: Boolean;
 begin
   if not (Mode in [fsohcmAppend, fsohcmResume]) then
   begin
-    if RenameFileUAC(SourceFile.FullPath, TargetFileName) then
-      Exit(True);
-    if (GetLastOSError <> ERROR_NOT_SAME_DEVICE) then
-      Exit(False);
+    repeat
+      RetryRename := True;
+      if RenameFileUAC(SourceFile.FullPath, TargetFileName) then
+        Exit(True);
+      if (GetLastOSError <> ERROR_NOT_SAME_DEVICE) then
+      begin
+        if FSkipRenameError then Exit(False);
+        Message := Format(rsMsgErrCannotMoveFile, [WrapTextSimple(SourceFile.FullPath, 100)]) +
+                   LineEnding + LineEnding + mbSysErrorMessage;
+        case AskQuestion('', Message, [fsourSkip, fsourRetry, fsourAbort, fsourSkipAll], fsourSkip, fsourAbort) of
+          fsourSkip: Exit(False);
+          fsourAbort: AbortOperation;
+          fsourRetry: RetryRename := False;
+          fsourSkipAll: FSkipRenameError := True;
+        end;
+      end;
+    until RetryRename;
   end;
 
   if FVerify then FStatistics.TotalBytes += SourceFile.Size;

+ 1 - 0
src/ulng.pas

@@ -34,6 +34,7 @@ resourcestring
   rsMsgCannotCopySpecialFile = 'Cannot copy special file %s';
   rsMsgErrDirExists = 'Directory %s exists!';
   rsMsgErrRename = 'Cannot rename file %s to %s';
+  rsMsgErrCannotMoveFile = 'Cannot move file %s';
   rsMsgErrCannotCopyFile = 'Cannot copy file %s to %s';
   rsMsgFileExistsOverwrite = 'Overwrite:';
   rsMsgFileExistsWithFile = 'With file:';