diff options
| author | Tomas Bzatek <tbzatek@users.sourceforge.net> | 2009-12-16 00:11:43 +0100 |
|---|---|---|
| committer | Tomas Bzatek <tbzatek@users.sourceforge.net> | 2009-12-16 00:11:43 +0100 |
| commit | 52d72cf25a6bcff19e4a488102e3b7137bde0000 (patch) | |
| tree | 8fc2e05ddc92429ceca461b8a36b0ef16d8721b5 /UCoreWorkers.pas | |
| parent | 8f034ebc019b1c9f6133814c439cf38f91f2bb13 (diff) | |
| download | tuxcmd-52d72cf25a6bcff19e4a488102e3b7137bde0000.tar.xz | |
Worker thread arguments cleanupv0.6.75
Diffstat (limited to 'UCoreWorkers.pas')
| -rw-r--r-- | UCoreWorkers.pas | 463 |
1 files changed, 234 insertions, 229 deletions
diff --git a/UCoreWorkers.pas b/UCoreWorkers.pas index a2a4f6a..a1e65ba 100644 --- a/UCoreWorkers.pas +++ b/UCoreWorkers.pas @@ -22,21 +22,15 @@ interface uses glib2, gtk2, SyncObjs, Classes, GTKForms, GTKView, ULibc, UEngines, UCoreUtils, UVFSCore, uVFSprototypes, UCore; -type TWorkerThreadJobType = (WORKER_JOB_DUMMY, WORKER_JOB_DELETE, WORKER_JOB_COPY, WORKER_JOB_MOVE, WORKER_JOB_MERGE, WORKER_JOB_SPLIT, - WORKER_JOB_CHMOD, WORKER_JOB_CHOWN); + +type TWorkerThreadJobType = (WORKER_JOB_DUMMY, WORKER_JOB_DELETE, WORKER_JOB_COPY, WORKER_JOB_MOVE, WORKER_JOB_EXTRACT_TO_TEMP, + WORKER_JOB_MERGE, WORKER_JOB_SPLIT, WORKER_JOB_CHMOD, WORKER_JOB_CHOWN); type TVFSCallbackThread = class(TThread) private FThreadID: __pthread_t; FCopyProgressFunc: TEngineProgressFunc; - Finished: boolean; - // * TODO: move to Create() ? - procedure PrepareExecute; // Call this right after thread has been started - public - FCancelled: boolean; - - AEngine: TPanelEngine; - APlugin: TVFSPlugin; + FFinished: boolean; VFSCallbackEvent: TSimpleEvent; VFSAskQuestion_Message: PChar; @@ -57,101 +51,128 @@ type TVFSCallbackThread = class(TThread) VFSAskPassword_Display: boolean; VFSAskPassword_Result: boolean; + procedure PrepareExecute; // Call this right after thread has been started + public + FCancelled: boolean; + + AEngine: TPanelEngine; + APlugin: TVFSPlugin; + + // VFS callback dialogs have been cancelled VFSCallbackCancelled: boolean; + // Connection manager VFSConnectionManagerMode: boolean; VFSQuickConnectMode: boolean; - FCancelRequested: boolean; - + // Set this to properly handle modal dialogs DialogsParentWindow: TCustomGTKForm; constructor Create(CreateSuspended: boolean); destructor Destroy; override; end; + TWorkerThread = class(TVFSCallbackThread) private - GUIMutex: TCriticalSection; - procedure DeleteFilesWorker; - procedure CopyFilesWorker; - procedure MergeFilesWorker; - procedure SplitFilesWorker; - procedure ChmodFilesWorker; - procedure ChownFilesWorker; - procedure DummyThreadWorker; - protected - procedure Execute; override; - procedure CommitGUIUpdate; - public - JobType: TWorkerThreadJobType; + FGUIMutex: TCriticalSection; + FCallbackLockEvent: TSimpleEvent; - // Data to update - FProgress1Pos, FProgress2Pos, FProgress1Max, FProgress2Max: Int64; - FProgress1Text, FProgress2Text, FLabel1Text, FLabel2Text: string; - FGUIProgress1Pos, FGUIProgress2Pos, FGUIProgress1Max, FGUIProgress2Max: Int64; - FGUIProgress1Text, FGUIProgress2Text, FGUILabel1Text, FGUILabel2Text: string; - FGUIChanged: boolean; + // Copy worker progress values + FTotalSize, FTotalDone, FFileSize: cuLongLong; + // Dialogs FCancelMessage: string; FShowCancelMessage, FDialogShowDirDelete, FDialogShowOverwrite, FDialogShowNewDir, FDialogShowMsgBox: boolean; FDialogResultDirDelete, FDialogResultOverwrite, FDialogResultNewDir: integer; + FProgress1Pos, FProgress2Pos, FProgress1Max, FProgress2Max: Int64; + FProgress1Text, FProgress2Text, FLabel1Text, FLabel2Text: string; + FGUIProgress1Pos, FGUIProgress2Pos, FGUIProgress1Max, FGUIProgress2Max: Int64; + FGUIProgress1Text, FGUIProgress2Text, FGUILabel1Text, FGUILabel2Text: string; + FGUIChanged: boolean; + procedure UpdateProgress1(const Progress: Int64; const ProgressText: string); + procedure UpdateProgress2(const Progress: Int64; const ProgressText: string); + procedure SetProgress1Params(const ProgressMax: Int64); + procedure SetProgress2Params(const ProgressMax: Int64); + procedure UpdateCaption1(const CaptionText: string); + procedure UpdateCaption2(const CaptionText: string); + FDirDeleteButtonsType: integer; FDirDeleteLabel1Text, FDirDeleteLabel2Text, FDirDeleteLabel3Text, FDirDeleteCaption: string; FDirDeleteLabel2Visible, FDirDeleteLabel3Visible: boolean; + function ShowDirDeleteDialog(ButtonsType: integer; const Label1Text: string; const Label2Text: string = ''; + const Label3Text: string = ''; const DirDeleteCaption: string = ''): integer; FOverwriteButtonsType: integer; FOverwriteFromLabel, FOverwriteFromInfoLabel, FOverwriteToLabel, FOverwriteToInfoLabel, FOverwriteRenameStr, FOverwriteSourceFile, FOverwriteDestFile: string; + function ShowOverwriteDialog(ButtonsType: integer; const FromLabel, FromInfoLabel, ToLabel, ToInfoLabel, RenameStr, + SourceFile, DestFile: string): integer; FNewDirCaption, FNewDirLabel, FNewDirEdit: string; + function ShowNewDirDialog(Caption, LabelCaption, Edit: string): integer; + FMsgBoxText: string; FMsgBoxButtons: TMessageButtons; FMsgBoxStyle: TMessageStyle; FMsgBoxDefault, FMsgBoxEscape, FDialogResultMsgBox: TMessageButton; + function ShowMessageBox(const Text: string; Buttons: TMessageButtons; Style: TMessageStyle; + Default, Escape: TMessageButton): TMessageButton; - FCallbackLockEvent: TSimpleEvent; + procedure DeleteFilesWorker; + procedure CopyFilesWorker; + procedure MergeFilesWorker; + procedure SplitFilesWorker; + procedure ChmodFilesWorker; + procedure ChownFilesWorker; + procedure DummyThreadWorker; + protected + procedure Execute; override; + procedure CommitGUIUpdate; + public + JobType: TWorkerThreadJobType; + SrcEngine, DestEngine: TPanelEngine; + ErrorHappened: boolean; - // Parameters - Engine, SrcEngine, DestEngine: TPanelEngine; - LeftPanel: boolean; + // For getting list of selected items in the panel DataList: TList; - ParamBool1, ParamBool2, ParamBool3, ParamBool4, ParamBool5: boolean; - ParamString1, ParamString2, ParamString3: string; - ParamPointer1: Pointer; - ParamInt64: Int64; - ParamInt1, ParamInt2: integer; - ParamLongWord1: LongWord; - ParamCardinal1, ParamCardinal2: Cardinal; - ParamFloat1, ParamFloat2: Extended; - ParamDataItem1: PDataItem; SelectedItem: PDataItem; - ExtractFromVFSMode, ExtractFromVFSAll: boolean; - ErrorHappened: boolean; - constructor Create; - destructor Destroy; override; + CopyTargetPath: string; - procedure PrepareJobFilesFromPanel(AList: TList; DoNotRecurse: boolean); + FCopySkipAllErrors: boolean; - procedure UpdateProgress1(const Progress: Int64; const ProgressText: string); - procedure UpdateProgress2(const Progress: Int64; const ProgressText: string); - procedure SetProgress1Params(const ProgressMax: Int64); - procedure SetProgress2Params(const ProgressMax: Int64); - procedure UpdateCaption1(const CaptionText: string); - procedure UpdateCaption2(const CaptionText: string); + QuickRenameDataItem: PDataItem; - function ShowDirDeleteDialog(ButtonsType: integer; const Label1Text: string; const Label2Text: string = ''; - const Label3Text: string = ''; const DirDeleteCaption: string = ''): integer; - function ShowOverwriteDialog(ButtonsType: integer; const FromLabel, FromInfoLabel, ToLabel, ToInfoLabel, RenameStr, - SourceFile, DestFile: string): integer; - function ShowNewDirDialog(Caption, LabelCaption, Edit: string): integer; - function ShowMessageBox(const Text: string; Buttons: TMessageButtons; Style: TMessageStyle; - Default, Escape: TMessageButton): TMessageButton; + ExtractFromVFSAll: boolean; + ExtractFile: string; // full path to the file to extract (to a temp directory) + + ChmodMode: cuLong; + ChmodRecurseType: integer; + + ChownUID, ChownGID: cuLong; + ChownRecursive: boolean; + + MergeTargetCRC: Cardinal; + MergeHasInitialCRC: boolean; + MergeTargetFinalName: string; + MergeTargetSize: Int64; + MergeSourceFile: string; + MergeTargetPath: string; + + SplitDeleteTarget: boolean; + SplitMaxSize: Int64; + SplitSourceFile: string; + SplitTargetPath: string; + + constructor Create; + destructor Destroy; override; + procedure PrepareJobFilesFromPanel(AList: TList; DoNotRecurse: boolean); end; + TOpenDirThread = class(TVFSCallbackThread) private function ChangeDir(Engine: TPanelEngine; Path: string; var SelItem: string; const AutoFallBack: boolean): boolean; @@ -170,6 +191,7 @@ type TVFSCallbackThread = class(TThread) destructor Destroy; override; end; + TOpenConnectionThread = class(TVFSCallbackThread) private protected @@ -208,8 +230,7 @@ begin VFSConnectionManagerMode := False; VFSQuickConnectMode := False; DialogsParentWindow := FMain; - FCancelRequested := False; - Finished := False; + FFinished := False; FCancelled := False; end; @@ -234,7 +255,7 @@ begin DebugMsg(['(ERROR): vfs_ask_question_callback: user_data is not TVFSCallbackThread, exiting.']); Exit; end; - if Thread.FCancelRequested then begin + if Thread.FCancelled then begin DebugMsg(['!! (WARNING): vfs_ask_question_callback: FCancelRequested.']); if (choice <> nil) then choice^ := -1; Thread.VFSCallbackCancelled := True; @@ -274,7 +295,7 @@ begin DebugMsg(['(ERROR): vfs_ask_question_callback: user_data is not TVFSCallbackThread, exiting.']); Exit; end; - if Thread.FCancelRequested then begin + if Thread.FCancelled then begin DebugMsg(['!! (WARNING): vfs_ask_password_callback: FCancelRequested.']); Result := False; Thread.VFSCallbackCancelled := True; @@ -379,14 +400,15 @@ begin WORKER_JOB_DUMMY: DummyThreadWorker; WORKER_JOB_DELETE: DeleteFilesWorker; WORKER_JOB_COPY, - WORKER_JOB_MOVE: CopyFilesWorker; + WORKER_JOB_MOVE, + WORKER_JOB_EXTRACT_TO_TEMP: CopyFilesWorker; WORKER_JOB_MERGE: MergeFilesWorker; WORKER_JOB_SPLIT: SplitFilesWorker; WORKER_JOB_CHMOD: ChmodFilesWorker; WORKER_JOB_CHOWN: ChownFilesWorker; end; finally - Finished := True; + FFinished := True; end; end; @@ -394,31 +416,45 @@ constructor TWorkerThread.Create; begin inherited Create(True); FreeOnTerminate := False; - GUIMutex := TCriticalSection.Create; + FGUIMutex := TCriticalSection.Create; FCallbackLockEvent := TSimpleEvent.Create; - Engine := nil; DataList := nil; - ParamPointer1 := nil; SelectedItem := nil; FShowCancelMessage := False; FDialogShowDirDelete := False; FDialogShowOverwrite := False; FDialogShowNewDir := False; FDialogShowMsgBox := False; - ExtractFromVFSMode := False; ErrorHappened := False; - ParamBool1 := False; - ParamBool2 := False; - ParamBool3 := False; - ParamBool4 := False; - ParamBool5 := False; FGUIChanged := False; JobType := WORKER_JOB_DUMMY; + + // Defaults, keep in sync with class interface + CopyTargetPath := ''; + FCopySkipAllErrors := False; + QuickRenameDataItem := nil; + ExtractFromVFSAll := False; + ExtractFile := ''; + ChmodMode := 0; + ChmodRecurseType := -1; + ChownUID := 0; + ChownGID := 0; + ChownRecursive := False; + MergeTargetCRC := 0; + MergeHasInitialCRC := False; + MergeTargetFinalName := ''; + MergeTargetSize := 0; + MergeSourceFile := ''; + MergeTargetPath := ''; + SplitDeleteTarget := False; + SplitMaxSize := 0; + SplitSourceFile := ''; + SplitTargetPath := ''; end; destructor TWorkerThread.Destroy; begin - GUIMutex.Free; + FGUIMutex.Free; FCallbackLockEvent.Free; inherited Destroy; end; @@ -459,7 +495,7 @@ end; procedure TWorkerThread.CommitGUIUpdate; begin - GUIMutex.Acquire; + FGUIMutex.Acquire; // WriteLn('TWorkerThread.CommitGUIUpdate, ted mam lock ja! -- enter'); FGUIProgress1Pos := FProgress1Pos; FGUIProgress2Pos := FProgress2Pos; @@ -472,7 +508,7 @@ begin FGUIChanged := True; // Sleep(1000); // WriteLn('TWorkerThread.CommitGUIUpdate, ted mam lock ja! -- leave'); - GUIMutex.Release; + FGUIMutex.Release; end; function TWorkerThread.ShowDirDeleteDialog(ButtonsType: integer; const Label1Text: string; const Label2Text: string = ''; const Label3Text: string = ''; const DirDeleteCaption: string = ''): integer; @@ -541,18 +577,18 @@ var i: longint; InputFiles: TStringList; begin InputFiles := TStringList.Create; - CurrPath := IncludeTrailingPathDelimiter(Engine.Path); + CurrPath := IncludeTrailingPathDelimiter(AEngine.Path); // Process selected files first if DataList.Count > 0 then for i := 0 to DataList.Count - 1 do with PDataItem(DataList[i])^ do if (not UpDir) and Selected then InputFiles.Add(CurrPath + String(FName)); - // If not files are selected, take into the account current active item + // If not files are selected, take into account the current active item if (InputFiles.Count = 0) and Assigned(SelectedItem) and (not SelectedItem^.UpDir) then InputFiles.Add(CurrPath + String(SelectedItem^.FName)); - FillDirFiles(Engine, AList, InputFiles, DoNotRecurse, True); + FillDirFiles(AEngine, AList, InputFiles, DoNotRecurse, True); InputFiles.Free; end; @@ -584,6 +620,7 @@ begin WORKER_JOB_DELETE: AFProgress.Label1.Caption := LANGDelete; WORKER_JOB_COPY: AFProgress.Label1.Caption := LANGCopySC; WORKER_JOB_MOVE: AFProgress.Label1.Caption := LANGMoveRenameSC; + WORKER_JOB_EXTRACT_TO_TEMP: AFProgress.Label1.Caption := 'Extract:'; WORKER_JOB_MERGE: AFProgress.Label1.Caption := LANGMergeSC; WORKER_JOB_SPLIT: AFProgress.Label1.Caption := LANGSplitSC; WORKER_JOB_CHMOD: AFProgress.Label1.Caption := LANGChmodProgress; @@ -617,7 +654,7 @@ begin // Update progress bars if SenderThread is TWorkerThread then with SenderThread as TWorkerThread do begin - GUIMutex.Acquire; + FGUIMutex.Acquire; if FGUIChanged then begin if FGUIProgress1Max > 1 then AFProgress.ProgressBar.Fraction := FGUIProgress1Pos / FGUIProgress1Max @@ -635,7 +672,7 @@ begin AFProgress.ProgressBar2.Max := FGUIProgress2Max; FGUIChanged := False; end; - GUIMutex.Release; + FGUIMutex.Release; end; Application.ProcessMessages; @@ -683,7 +720,7 @@ begin AFDirDelete.Label2.Visible := FDirDeleteLabel2Visible; AFDirDelete.Label3.Visible := FDirDeleteLabel3Visible; FDialogResultDirDelete := Integer(AFDirDelete.Run); - if (FDirDeleteButtonsType = 3) and (FDialogResultDirDelete = 2) and (not ParamBool3) + if (FDirDeleteButtonsType = 3) and (FDialogResultDirDelete = 2) and (JobType = WORKER_JOB_MOVE) then case Application.MessageBox(LANGIgnoreError, [mbYes, mbNo{, mbCancel}], mbWarning, mbYes, mbNo) of mbNo: FDialogResultDirDelete := 1; mbCancel: FDialogResultDirDelete := 0; @@ -745,7 +782,7 @@ begin // Unlock the waiting worker thread if b then FCallbackLockEvent.SetEvent; end; - until SenderThread.Finished; + until SenderThread.FFinished; if SenderThread is TWorkerThread then with SenderThread as TWorkerThread do @@ -788,7 +825,7 @@ var SkipAll: boolean; Error := nil; // DebugMsg(['Debug: IsDir: ', AFileRec^.IsDir, ', Stage1: ', AFileRec^.Stage1, ', IsLnk: ', AFileRec^.IsLnk, '; Result = ', AFileRec^.IsDir and AFileRec^.Stage1 and (not AFileRec^.IsLnk)]); if AFileRec^.DataItem^.IsDir and AFileRec^.Stage1 and (not AFileRec^.DataItem^.IsLnk) then Exit; - Res := Engine.Remove(String(AFileRec^.DataItem^.FName), @Error); + Res := AEngine.Remove(String(AFileRec^.DataItem^.FName), @Error); // DebugMsg(['Result : ', Res]); if not Res then if SkipAll then Result := True else @@ -818,10 +855,10 @@ var i: longint; begin SkipAll := False; AList := TList.Create; - CurrPath := IncludeTrailingPathDelimiter(Engine.Path); + CurrPath := IncludeTrailingPathDelimiter(AEngine.Path); PrepareJobFilesFromPanel(AList, False); // * TODO: catch the error - if not Engine.ChangeDir(CurrPath, nil) then + if not AEngine.ChangeDir(CurrPath, nil) then DebugMsg(['*** WARNING: Cannot change to the origin location, strange behaviour might occur.']); libc_chdir('/'); @@ -871,7 +908,7 @@ begin AList.Clear; AList.Free; // * TODO: catch the error - if not Engine.ChangeDir(CurrPath, nil) then + if not AEngine.ChangeDir(CurrPath, nil) then DebugMsg(['*** WARNING: Cannot change to the origin location, strange behaviour might occur.']); end; @@ -890,8 +927,8 @@ end; if Assigned(Sender) and (TObject(Sender) is TWorkerThread) then with TWorkerThread(Sender) do begin if BytesDone = 0 then UpdateProgress1(0, '0%') - else UpdateProgress1(BytesDone, Format('%d%%', [Round(ParamFloat2 * BytesDone)])); - UpdateProgress2(ParamInt64 + BytesDone, Format('%d%%', [Round(ParamFloat1 * (ParamInt64 + BytesDone))])); + else UpdateProgress1(BytesDone, Format('%d%%', [Round(BytesDone / FFileSize * 100)])); + UpdateProgress2(FTotalDone + BytesDone, Format('%d%%', [Round((FTotalDone + BytesDone) / FTotalSize * 100)])); Result := not FCancelled; CommitGUIUpdate; end else DebugMsg(['*** CopyFilesWorker: Sender is not TWorkerThread']); @@ -906,7 +943,7 @@ end; begin Result := False; with TWorkerThread(Sender) do begin - if ParamBool2 then begin + if FCopySkipAllErrors then begin Result := True; Exit; end; @@ -923,7 +960,7 @@ end; 6 : s := LANGCannotReadFromSourceFile; 7 : s := LANGCannotWriteToDestinationFile; end; - if ParamBool1 then s2 := LANGCopyError + if (JobType in [WORKER_JOB_COPY, WORKER_JOB_EXTRACT_TO_TEMP]) then s2 := LANGCopyError else s2 := LANGMoveError; if ErrorType <> 1 then s3 := StrToUTF8(FileName) else s3 := ''; @@ -936,7 +973,7 @@ end; end; 2 : Result := True; // Ignore 3 : begin // Skip All - ParamBool2 := True; { Skip All Err } + FCopySkipAllErrors := True; { Skip All Err } Result := False; //** True? end; else {1, 124, 255 :} Result := False; // Skip @@ -946,22 +983,10 @@ end; procedure TWorkerThread.CopyFilesWorker; -// ParamFloat1 = Fr - internal -// ParamFloat2 = Fr2 - internal -// ParamInt64 = SizeDone - internal -// ParamBool1 = ModeCopy - internal -// ParamBool2 = SkipAllErr - internal -// ParamBool3 = CopyMode -// ParamBool4 = QuickRename -// ParamBool5 = OneFile -// ParamString1 = NewPath -// ParamString2 = Filepath -// ParamDataItem1 = QuickRenameDataItem var DefResponse: integer; // Global variables for this function SkipAll: boolean; - // Returns True if file was successfully copied, if not, the file will be deleted in LocalCopyFile function ManualCopyFile(SourceFile, DestFile: string; Append: boolean): boolean; var fsrc, fdst: TEngineFileDes; @@ -1124,11 +1149,11 @@ var DefResponse: integer; // Global variables for this function with AFileRec^ do begin if DataItem^.IsLnk then begin // Explicit copy the file - if ParamBool3 or (not IsOnSameFS(String(DataItem^.FName), ExtractFileDir(Dst))) then begin + if (JobType in [WORKER_JOB_COPY, WORKER_JOB_EXTRACT_TO_TEMP]) or (not IsOnSameFS(String(DataItem^.FName), ExtractFileDir(Dst))) then begin // * TODO: check error ErrorKind := Ord(DestEngine.MakeSymLink(Dst, String(DataItem^.LnkPointTo), nil)); // if ErrorKind <> 0 then Result := ERRCreateLink; - if not ParamBool3 then begin + if JobType = WORKER_JOB_MOVE then begin // * TODO: check error ErrorKind := Ord(SrcEngine.Remove(String(DataItem^.FName), nil)); // if ErrorKind <> 0 then Result := ERRRemove; @@ -1139,7 +1164,7 @@ var DefResponse: integer; // Global variables for this function // if ErrorKind <> 0 then Result := ERRCopyMove; end; end else // is not link - if ParamBool3 then begin // Copy mode + if (JobType in [WORKER_JOB_COPY, WORKER_JOB_EXTRACT_TO_TEMP]) then begin // Copy mode if LocalCopyFile(String(DataItem^.FName), Dst, Append) then begin if IsOnRO and ConfClearReadOnlyAttr and (DataItem^.Mode and S_IWUSR = 0) then DataItem^.Mode := DataItem^.Mode or S_IWUSR; // * TODO: check error @@ -1187,21 +1212,22 @@ var DefResponse: integer; // Global variables for this function try // Second stage - change permissions - if (not AFileRec^.Stage1) and (ParamBool3 or ((not ParamBool3) and (not AFileRec^.ForceMove))) then + if (not AFileRec^.Stage1) and ((JobType in [WORKER_JOB_COPY, WORKER_JOB_EXTRACT_TO_TEMP]) or (not AFileRec^.ForceMove)) then with AFileRec^ do begin if IsOnRO and ConfClearReadOnlyAttr and (DataItem^.Mode and S_IWUSR = 0) then DataItem^.Mode := DataItem^.Mode or S_IWUSR; // * TODO: check error DestEngine.Chmod(NewFilePath, DataItem^.Mode, nil); DestEngine.Chown(NewFilePath, DataItem^.UID, DataItem^.GID, nil); DestEngine.ChangeTimes(NewFilePath, DataItem^.mtime, DataItem^.atime, nil); - if not ParamBool3 then SrcEngine.Remove(String(DataItem^.FName), nil); // Remove directory + if JobType = WORKER_JOB_MOVE then + SrcEngine.Remove(String(DataItem^.FName), nil); // Remove directory Exit; end; // First stage - copy data if AFileRec^.DataItem^.IsDir then begin Res := 0; - if AFileRec^.ForceMove and (not ParamBool3) + if AFileRec^.ForceMove and (JobType = WORKER_JOB_MOVE) then begin if TwoSameFiles(ExcludeTrailingPathDelimiter(string(AFileRec^.DataItem^.FName)), ExcludeTrailingPathDelimiter(string(AFileRec^.ADestination)), True) and (not TwoSameFiles(ExcludeTrailingPathDelimiter(string(AFileRec^.DataItem^.FName)), ExcludeTrailingPathDelimiter(string(AFileRec^.ADestination)), False)) then @@ -1225,11 +1251,11 @@ var DefResponse: integer; // Global variables for this function // * TODO: check error DestEngine.MakeDir(ExtractFileDir(NewFilePath), nil); SetProgress1Params(AFileRec^.DataItem^.Size + Ord(AFileRec^.DataItem^.Size = 0)); - if AFileRec^.DataItem^.Size <= 1 then ParamFloat2 := 1 else ParamFloat2 := 100 / (AFileRec^.DataItem^.Size - 1); + FFileSize := AFileRec^.DataItem^.Size; CopyFilesWorker_ProgressFunc(Self, 0, nil); Res := 0; if DestEngine.FileExists(NewFilePath, False) and - (not (not ParamBool3 and (not TwoSameFiles(NewFilePath, AFileRec^.DataItem^.FName, False)) and TwoSameFiles(NewFilePath, AFileRec^.DataItem^.FName, True))) + (not ((JobType = WORKER_JOB_MOVE) and (not TwoSameFiles(NewFilePath, AFileRec^.DataItem^.FName, False)) and TwoSameFiles(NewFilePath, AFileRec^.DataItem^.FName, True))) then begin Response := DefResponse; // * TODO: check error @@ -1246,7 +1272,7 @@ var DefResponse: integer; // Global variables for this function end; FromInfoLabel := Format(InfoLabelFormat, [FormatSize(Item^.Size, 0), FormatDate(Item^.mtime, True, True)]); ToInfoLabel := Format(InfoLabelFormat, [FormatSize(AFileRec^.DataItem^.Size, 0), FormatDate(AFileRec^.DataItem^.mtime, True, True)]); - Response := ShowOverwriteDialog(1 + Ord(ParamBool3), Format(LANGOverwriteS, [StrToUTF8(NewFilePath)]), FromInfoLabel, + Response := ShowOverwriteDialog(1 + Ord((JobType in [WORKER_JOB_COPY, WORKER_JOB_EXTRACT_TO_TEMP])), Format(LANGOverwriteS, [StrToUTF8(NewFilePath)]), FromInfoLabel, Format(LANGWithFileS, [AFileRec^.DataItem^.FDisplayName]), ToInfoLabel, ExtractFileName(StrToUTF8(NewFilePath)), ExtractFileName(AFileRec^.DataItem^.FDisplayName), ExtractFileName(StrToUTF8(NewFilePath))); s := FOverwriteRenameStr; @@ -1297,7 +1323,7 @@ var DefResponse: integer; // Global variables for this function // Error handling if (Res <> 0) and (not SkipAll) then begin - if ParamBool3 then cap := LANGCopy + if (JobType in [WORKER_JOB_COPY, WORKER_JOB_EXTRACT_TO_TEMP]) then cap := LANGCopy else cap := LANGMove; // * TODO: port to GError { case Res of @@ -1355,9 +1381,9 @@ var DefResponse: integer; // Global variables for this function if not Ren then begin InputFiles.Add(FullPath); end else begin - s := ProcessPattern(DestEngine, ParamString1, CurrPath, ParamFileName, ParamDir); - CaseInsensitiveRename := (WideCompareStr(ParamString1, ParamFileName) <> 0) and (WideCompareText(ParamString1, ParamFileName) = 0) and - ParamDir and DestEngine.TwoSameFiles(IncludeTrailingPathDelimiter(CurrPath) + ParamString1, IncludeTrailingPathDelimiter(CurrPath) + ParamFileName, False); + s := ProcessPattern(DestEngine, CopyTargetPath, CurrPath, ParamFileName, ParamDir); + CaseInsensitiveRename := (WideCompareStr(CopyTargetPath, ParamFileName) <> 0) and (WideCompareText(CopyTargetPath, ParamFileName) = 0) and + ParamDir and DestEngine.TwoSameFiles(IncludeTrailingPathDelimiter(CurrPath) + CopyTargetPath, IncludeTrailingPathDelimiter(CurrPath) + ParamFileName, False); // DebugMsg(['HandleProcessPattern: s = ', s]); b := False; if ParamDir then begin @@ -1388,7 +1414,6 @@ var DefResponse: integer; // Global variables for this function var i: longint; List: TList; CurrPath, SaveDestPath, SaveSrcPath, s: string; - MaxSize: Int64; StartPassed: boolean; begin List := TList.Create; @@ -1397,12 +1422,12 @@ begin SaveSrcPath := ''; CurrPath := IncludeTrailingPathDelimiter(SrcEngine.Path); SaveDestPath := DestEngine.Path; - ParamString1 := ExcludeTrailingPathDelimiter(ParamString1); - if ParamString1 = '' then ParamString1 := PathDelim; + CopyTargetPath := ExcludeTrailingPathDelimiter(CopyTargetPath); + if CopyTargetPath = '' then CopyTargetPath := PathDelim; // '/' // Prepare list of files to copy - if ParamBool5 then begin // HandleVFSFromArchive - if not ExtractFromVFSAll then HandleProcessPattern(List, CurrPath, ParamString2, ExtractFileName(ParamString2), False, False) + if JobType = WORKER_JOB_EXTRACT_TO_TEMP then begin + if not ExtractFromVFSAll then HandleProcessPattern(List, CurrPath, ExtractFile, ExtractFileName(ExtractFile), False, False) else begin SaveSrcPath := IncludeTrailingPathDelimiter(SrcEngine.Path); SrcEngine.SetPath('/'); @@ -1410,23 +1435,23 @@ begin HandleProcessPattern(List, '/', '/', '', True, False); end; end else - if ParamBool4 then begin // Quick-Rename - with ParamDataItem1^ do + if QuickRenameDataItem <> nil then begin // Quick-Rename + with QuickRenameDataItem^ do HandleProcessPattern(List, CurrPath, CurrPath + String(FName), String(FName), IsDir and (not IsLnk), True); end else begin // Not Quick-Rename - if not ExtractFromVFSMode then begin + if JobType <> WORKER_JOB_EXTRACT_TO_TEMP then begin if DataList.Count > 0 then for i := 0 to DataList.Count - 1 do with PDataItem(DataList[i])^ do if (not UpDir) and Selected - then HandleProcessPattern(List, CurrPath, CurrPath + String(FName), String(FName), IsDir and (not IsLnk), not ParamBool3); + then HandleProcessPattern(List, CurrPath, CurrPath + String(FName), String(FName), IsDir and (not IsLnk), JobType = WORKER_JOB_MOVE); if (List.Count = 0) and Assigned(SelectedItem) and (not SelectedItem^.UpDir) then with SelectedItem^ do - HandleProcessPattern(List, CurrPath, CurrPath + String(FName), String(FName), IsDir and (not IsLnk), not ParamBool3); + HandleProcessPattern(List, CurrPath, CurrPath + String(FName), String(FName), IsDir and (not IsLnk), JobType = WORKER_JOB_MOVE); end else begin // Extract from VFS mode DebugMsg(['CopyFilesWorker: Should not be reached']); if (not ExtractFromVFSAll) and Assigned(SelectedItem) - then HandleProcessPattern(List, CurrPath, CurrPath + String(SelectedItem^.FName), String(SelectedItem^.FName), SelectedItem^.IsDir and (not SelectedItem^.IsLnk), not ParamBool3) + then HandleProcessPattern(List, CurrPath, CurrPath + String(SelectedItem^.FName), String(SelectedItem^.FName), SelectedItem^.IsDir and (not SelectedItem^.IsLnk), JobType = WORKER_JOB_MOVE) else begin SaveSrcPath := IncludeTrailingPathDelimiter(SrcEngine.Path); SrcEngine.SetPath('/'); @@ -1442,26 +1467,25 @@ begin __chdir('/'); // Compute total size of files to copy - MaxSize := 0; ParamInt64 := 0; + FTotalSize := 0; + FTotalDone := 0; if List.Count > 0 then for i := 0 to List.Count - 1 do if PDataItemSL(List[i])^.Stage1 and (PDataItemSL(List[i])^.DataItem^.Size > 0) and (not PDataItemSL(List[i])^.DataItem^.IsDir) and (not PDataItemSL(List[i])^.DataItem^.IsLnk) - then Inc(MaxSize, PDataItemSL(List[i])^.DataItem^.Size); - SrcEngine.BlockSize := ComputeBlockSize(MaxSize); - DestEngine.BlockSize := ComputeBlockSize(MaxSize); + then Inc(FTotalSize, PDataItemSL(List[i])^.DataItem^.Size); + SrcEngine.BlockSize := ComputeBlockSize(FTotalSize); + DestEngine.BlockSize := ComputeBlockSize(FTotalSize); // Prepare the Progress window - SetProgress2Params(MaxSize + Ord(MaxSize = 0)); + SetProgress2Params(FTotalSize + Ord(FTotalSize = 0)); UpdateProgress1(0, '0%'); UpdateProgress2(0, '0%'); CommitGUIUpdate; DefResponse := 0; - ParamBool1 := ParamBool3; SkipAll := False; - ParamBool2 := False; + FCopySkipAllErrors := False; - if MaxSize < 2 then ParamFloat1 := 1 else ParamFloat1 := 100 / (MaxSize - 1); if List.Count > 0 then begin StartPassed := True; if SrcEngine is TVFSEngine then @@ -1475,7 +1499,7 @@ begin then s := string(PDataItemSL(List[i])^.ADestination) else begin - s := ProcessPattern(DestEngine, ParamString1, CurrPath, Copy(PDataItemSL(List[i])^.DataItem^.FName, Length(CurrPath) + 1, Length(PDataItemSL(List[i])^.DataItem^.FName) - Length(CurrPath)), + s := ProcessPattern(DestEngine, CopyTargetPath, CurrPath, Copy(PDataItemSL(List[i])^.DataItem^.FName, Length(CurrPath) + 1, Length(PDataItemSL(List[i])^.DataItem^.FName) - Length(CurrPath)), PDataItemSL(List[i])^.DataItem^.IsDir and (not PDataItemSL(List[i])^.DataItem^.IsLnk)); // DebugMsg(['s2 = ', Copy(PDataItemSL(List[i])^.AName, Length(CurrPath) + 1, Length(PDataItemSL(List[i])^.AName) - Length(CurrPath)), ', s = ', s]); end; @@ -1487,7 +1511,7 @@ begin if (DestEngine as TVFSEngine).ArchiveMode then UpdateCaption2(Format(LANGToS, [Format(ConstFullPathFormatStr, [(DestEngine as TVFSEngine).ArchivePath, StrToUTF8(s)])])) else UpdateCaption2(Format(LANGToS, [GetURIPrefix((DestEngine as TVFSEngine).GetPathURI) + StrToUTF8(s)])); CommitGUIUpdate; - if TwoSameFiles(s, string(PDataItemSL(List[i])^.DataItem^.FName), ParamBool3) and (not PDataItemSL(List[i])^.DataItem^.IsDir) then begin + if TwoSameFiles(s, string(PDataItemSL(List[i])^.DataItem^.FName), (JobType in [WORKER_JOB_COPY, WORKER_JOB_EXTRACT_TO_TEMP])) and (not PDataItemSL(List[i])^.DataItem^.IsDir) then begin FCancelMessage := LANGCannotCopyFileToItself; FShowCancelMessage := True; ErrorHappened := True; @@ -1500,7 +1524,7 @@ begin Break; end; if (not PDataItemSL(List[i])^.DataItem^.IsDir) and (not PDataItemSL(List[i])^.DataItem^.IsLnk) - then Inc(ParamInt64, PDataItemSL(List[i])^.DataItem^.Size); + then Inc(FTotalDone, PDataItemSL(List[i])^.DataItem^.Size); if FCancelled then begin FCancelMessage := LANGUserCancelled; FShowCancelMessage := True; @@ -1537,13 +1561,6 @@ end; (********************************************************************************************************************************) (********************************************************************************************************************************) procedure TWorkerThread.MergeFilesWorker; -// ParamBool1 = HasInitialCRC -// ParamString1 = NewPath -// ParamString2 = FileName -// ParamString3 = TargetName -// ParamLongWord1 = TargetCRC -// ParamInt64 = TargetSize - var FD: TEngineFileDes; Count, MergeBlockSize: integer; Buffer: Pointer; @@ -1560,28 +1577,28 @@ var FD: TEngineFileDes; Stat: PDataItem; begin Result := False; - if ParamBool1 then UpdateCaption2(Format(LANGToS, [StrToUTF8(FName)])) + if MergeHasInitialCRC then UpdateCaption2(Format(LANGToS, [StrToUTF8(FName)])) else UpdateCaption1(Format(LANGFromS, [StrToUTF8(FName)])); UpdateProgress1(0, '0 %'); CommitGUIUpdate; // * TODO: check error - Stat := Engine.GetFileInfo(FName, True, True, nil); + Stat := AEngine.GetFileInfo(FName, True, True, nil); if not Assigned(Stat) then Exit; SetProgress1Params(Stat^.Size); FreeDataItem(Stat); // * TODO: check error Error := nil; - FDR := Engine.OpenFile(FName, omRead, @Error); + FDR := AEngine.OpenFile(FName, omRead, @Error); if FDR = nil then Exit; repeat // * TODO: check error - Count := Engine.ReadFile(FDR, Buffer, MergeBlockSize, @Error); + Count := AEngine.ReadFile(FDR, Buffer, MergeBlockSize, @Error); if Error <> nil then begin - Engine.CloseFile(FD, nil); + AEngine.CloseFile(FD, nil); Exit; end; // * TODO: check error - wCount := Engine.WriteFile(FD, Buffer, Count, @Error); + wCount := AEngine.WriteFile(FD, Buffer, Count, @Error); if (Error <> nil) or (Count <> wCount) then begin FCancelMessage := Format(LANGAnErrorOccuredWhileWritingFileSS, [ExtractFileName(TargetName), Error^.message]); FShowCancelMessage := True; @@ -1592,11 +1609,11 @@ var FD: TEngineFileDes; CurrentCRC := CRC32(CurrentCRC, Buffer, Count); UpdateProgress1(FProgress1Pos + Count, Format('%d %%', [Trunc((FProgress1Pos + Count) / FProgress1Max * 100)])); Inc(SizeDone, Count); - if ParamBool1 then UpdateProgress2(SizeDone, Format('%d %%', [Trunc(SizeDone / FProgress2Max * 100)])); + if MergeHasInitialCRC then UpdateProgress2(SizeDone, Format('%d %%', [Trunc(SizeDone / FProgress2Max * 100)])); CommitGUIUpdate; until (Count < MergeBlockSize) or FCancelled; // * TODO: set real error, also free it - Engine.CloseFile(FDR, nil); + AEngine.CloseFile(FDR, nil); Result := True; end; @@ -1605,15 +1622,15 @@ var CurrFile, SourcePath, TargetFinalName: string; HasFinalCRC, b: boolean; Stat: PDataItem; begin - HasFinalCRC := ParamBool1; - TargetFinalName := ParamString3; - if (Length(ParamString2) > 4) and (WideUpperCase(RightStr(ParamString2, 4)) = '.CRC') - then CurrFile := ChangeFileExt(ExtractFileName(ParamString2), '.001') - else CurrFile := ExtractFileName(ParamString2); - SourcePath := ExtractFilePath(ParamString2); - if ParamString3 = '' then ParamString3 := ChangeFileExt(ExtractFileName(ParamString2), '.out'); - TargetName := ProcessPattern(Engine, ParamString1, Engine.Path, ParamString3, False); - if Engine.FileExists(TargetName, False) then + HasFinalCRC := MergeHasInitialCRC; + TargetFinalName := MergeTargetFinalName; + if (Length(MergeSourceFile) > 4) and (WideUpperCase(RightStr(MergeSourceFile, 4)) = '.CRC') + then CurrFile := ChangeFileExt(ExtractFileName(MergeSourceFile), '.001') + else CurrFile := ExtractFileName(MergeSourceFile); + SourcePath := ExtractFilePath(MergeSourceFile); + if MergeTargetFinalName = '' then MergeTargetFinalName := ChangeFileExt(ExtractFileName(MergeSourceFile), '.out'); + TargetName := ProcessPattern(AEngine, MergeTargetPath, AEngine.Path, MergeTargetFinalName, False); + if AEngine.FileExists(TargetName, False) then if ShowMessageBox(Format(LANGTheTargetFileSAlreadyExistsDoYouWantToOverwriteIt, [StrToUTF8(TargetName)]), [mbYes, mbNo], mbQuestion, mbNone, mbNo) = mbYes then begin // * TODO: check error @@ -1626,7 +1643,7 @@ begin end else Exit; // * TODO: check error - Stat := Engine.GetFileInfo(ParamString2, True, True, nil); + Stat := AEngine.GetFileInfo(MergeSourceFile, True, True, nil); if Assigned(Stat) then MergeBlockSize := ComputeBlockSize(Stat^.Size) else MergeBlockSize := 65536*4; FreeDataItem(Stat); @@ -1639,7 +1656,7 @@ begin Exit; end; // * TODO: check error - FD := Engine.OpenFile(TargetName, omWrite, @Error); + FD := AEngine.OpenFile(TargetName, omWrite, @Error); if Error <> nil then begin FCancelMessage := Format(LANGAnErrorOccuredWhileOpeningFileSS, [StrToUTF8(TargetName), Error^.message]); FShowCancelMessage := True; @@ -1650,8 +1667,8 @@ begin CurrentCRC := 0; SizeDone := 0; PrivateCancel := False; - if ParamBool1 then begin - SetProgress2Params(ParamInt64); + if MergeHasInitialCRC then begin + SetProgress2Params(MergeTargetSize); UpdateProgress2(0, '0 %'); UpdateCaption2(Format(LANGFromS, [StrToUTF8(TargetName)])); CommitGUIUpdate; @@ -1667,7 +1684,7 @@ begin if not PrivateCancel then begin SourcePath := UTF8ToStr(FNewDirEdit); if not HasFinalCRC then - HasFinalCRC := CRCGetInfo(IncludeTrailingPathDelimiter(SourcePath) + CurrFile, Engine, TargetFinalName, ParamLongWord1, ParamInt64); + HasFinalCRC := CRCGetInfo(IncludeTrailingPathDelimiter(SourcePath) + CurrFile, AEngine, TargetFinalName, MergeTargetCRC, MergeTargetSize); Continue; end; end; @@ -1677,21 +1694,21 @@ begin except CurrFile := ''; end; - until (SizeDone = ParamInt64) or FCancelled or PrivateCancel {or ((not b) and (not HasInitialCRC))} or (CurrFile = ''); + until (SizeDone = MergeTargetSize) or FCancelled or PrivateCancel {or ((not b) and (not HasInitialCRC))} or (CurrFile = ''); // * TODO: check error - if (not ParamBool1) and HasFinalCRC then Engine.RenameFile(TargetName, IncludeTrailingPathDelimiter(ExtractFilePath(TargetName)) + TargetFinalName, nil); + if (not MergeHasInitialCRC) and HasFinalCRC then AEngine.RenameFile(TargetName, IncludeTrailingPathDelimiter(ExtractFilePath(TargetName)) + TargetFinalName, nil); if FCancelled and (not PrivateCancel) then begin FCancelMessage := LANGUserCancelled; FShowCancelMessage := True; end; if not (FCancelled or PrivateCancel) then if HasFinalCRC then begin - if CurrentCRC = ParamLongWord1 + if CurrentCRC = MergeTargetCRC then ShowMessageBox(Format(LANGMergeOfSSucceeded, [StrToUTF8(ExtractFileName(TargetFinalName))]), [mbOK], mbInfo, mbNone, mbOK) else ShowMessageBox(LANGWarningCreatedFileFailsCRCCheck, [mbOK], mbWarning, mbNone, mbOK); end else ShowMessageBox(Format(LANGMergeOfSSucceeded_NoCRCFileAvailable, [StrToUTF8(ExtractFileName(TargetFinalName))]), [mbOK], mbInfo, mbNone, mbOK); // * TODO: set real error, also free it - Engine.CloseFile(FD, nil); + AEngine.CloseFile(FD, nil); libc_free(Buffer); end; @@ -1701,11 +1718,6 @@ end; (********************************************************************************************************************************) (********************************************************************************************************************************) procedure TWorkerThread.SplitFilesWorker; -// ParamInt64 = SplitSize -// ParamString1 = FileName -// ParamString2 = NewPath -// ParamBool1 = DeleteTarget - const SplitBlockSize = 65536*4; var FD: TEngineFileDes; Error: PGError; @@ -1723,10 +1735,10 @@ var FD: TEngineFileDes; Result := False; Written := 0; // * TODO: check error - FDW := Engine.OpenFile(TargetFile, omWrite, @Error); + FDW := AEngine.OpenFile(TargetFile, omWrite, @Error); DebugMsg(['-- Opening file ', ExtractFileName(TargetFile), ', PartSize = ', PartSize]); if Error <> nil then Exit; - if ParamInt64 > 0 then begin + if SplitMaxSize > 0 then begin UpdateCaption2(Format(LANGToS, [StrToUTF8(TargetFile)])); SetProgress1Params(PartSize); UpdateProgress1(0, '0 %'); @@ -1734,36 +1746,36 @@ var FD: TEngineFileDes; CommitGUIUpdate; repeat // * TODO: check error - DebugMsg(['Seek to ', Engine.FileSeek(FD, SizeDone + Written, @Error), ', Written = ', Written]); + DebugMsg(['Seek to ', AEngine.FileSeek(FD, SizeDone + Written, @Error), ', Written = ', Written]); if Written + SplitBlockSize > PartSize then bl := PartSize - Written else bl := SplitBlockSize; // * TODO: check error - Count := Engine.ReadFile(FD, Buffer, bl, @Error); + Count := AEngine.ReadFile(FD, Buffer, bl, @Error); if (Error <> nil) or (Count <> bl) then begin // * TODO: set real error, also free it - Engine.CloseFile(FDW, nil); + AEngine.CloseFile(FDW, nil); DebugMsg(['Read Error: ', Error^.message, ', Count = ', Count, ', bl = ', bl]); // if (Count <> bl) and (Error = 0) then Error := EIO; Exit; end; // * TODO: check error - wCount := Engine.WriteFile(FDW, Buffer, Count, @Error); + wCount := AEngine.WriteFile(FDW, Buffer, Count, @Error); Inc(Written, wCount); FileCRC := CRC32(FileCRC, Buffer, wCount); if (Error <> nil) or (Count <> wCount) then begin // * TODO: set real error, also free it - Engine.CloseFile(FDW, nil); + AEngine.CloseFile(FDW, nil); // * TODO: check error DebugMsg(['Write Error: ', Error^.message, ', Count = ', Count, ', wCount = ', wCount]); // if (wCount <> Count) and (Error = 0) then Error := ENOSPC; Exit; end; UpdateProgress1(FProgress1Pos + wCount, Format('%d %%', [Trunc((FProgress1Pos + wCount) / FProgress1Max * 100)])); - if ParamInt64 > 0 then UpdateProgress2(FProgress2Pos + wCount, Format('%d %%', [Trunc((FProgress2Pos + wCount) / FProgress2Max * 100)])); + if SplitMaxSize > 0 then UpdateProgress2(FProgress2Pos + wCount, Format('%d %%', [Trunc((FProgress2Pos + wCount) / FProgress2Max * 100)])); CommitGUIUpdate; until (Written = PartSize) or FCancelled or PrivateCancel; // * TODO: set real error, also free it - Engine.CloseFile(FDW, nil); + AEngine.CloseFile(FDW, nil); DebugMsg(['-- Closing file ', ExtractFileName(TargetFile), ', PartSize = ', PartSize, ', Written = ', Written]); Result := True; end; @@ -1774,14 +1786,14 @@ var FD: TEngineFileDes; xx: string; begin Result := False; - Engine.GetFileSystemInfo(FilePath, x, TDF, xx); + AEngine.GetFileSystemInfo(FilePath, x, TDF, xx); // Calculate part size - if ParamInt64 = 0 then begin + if SplitMaxSize = 0 then begin if FileSize - SizeDone > TDF then CurrSize := TDF else CurrSize := FileSize - SizeDone; end else - if SizeDone + ParamInt64 > FileSize then CurrSize := FileSize - SizeDone - else CurrSize := ParamInt64; + if SizeDone + SplitMaxSize > FileSize then CurrSize := FileSize - SizeDone + else CurrSize := SplitMaxSize; if (TDF < 512) {or (CurrSize < 512)} or (TDF < CurrSize) then begin DebugMsg(['-- New disk question']); libc_chdir('/'); @@ -1803,13 +1815,13 @@ var i: integer; xx: string; begin // * TODO: check error - Stat := Engine.GetFileInfo(ParamString1, True, True, nil); + Stat := AEngine.GetFileInfo(SplitSourceFile, True, True, nil); if not Assigned(Stat) then begin - FCancelMessage := Format(LANGCannotOpenFileS, [StrToUTF8(ParamString1)]); + FCancelMessage := Format(LANGCannotOpenFileS, [StrToUTF8(SplitSourceFile)]); FShowCancelMessage := True; Exit; end; - if (ParamInt64 > 0) and (Stat^.Size > ParamInt64 * 999) then begin + if (SplitMaxSize > 0) and (Stat^.Size > SplitMaxSize * 999) then begin FCancelMessage := LANGCannotSplitTheFileToMoreThan999Parts; FShowCancelMessage := True; Exit; @@ -1829,20 +1841,20 @@ begin Exit; end; // * TODO: check error - FD := Engine.OpenFile(ParamString1, omRead, @Error); + FD := AEngine.OpenFile(SplitSourceFile, omRead, @Error); if Error <> nil then begin - FCancelMessage := Format(LANGAnErrorOccuredWhileOpeningFileSS, [StrToUTF8(ParamString1), Error^.message]); + FCancelMessage := Format(LANGAnErrorOccuredWhileOpeningFileSS, [StrToUTF8(SplitSourceFile), Error^.message]); libc_free(Buffer); Exit; end; - FilePath := IncludeTrailingPathDelimiter(ProcessPattern(Engine, ParamString2, Engine.Path, '', True)); - FileName := ExtractFileName(ParamString1); + FilePath := IncludeTrailingPathDelimiter(ProcessPattern(AEngine, SplitTargetPath, AEngine.Path, '', True)); + FileName := ExtractFileName(SplitSourceFile); OriginalFName := FileName; if Pos('.', FileName) > 1 then FileName := ChangeFileExt(FileName, '.001') else FileName := FileName + '.001'; PrivateCancel := False; - if ParamInt64 > 0 then begin + if SplitMaxSize > 0 then begin SetProgress2Params(FileSize); UpdateProgress2(0, '0 %'); end else begin @@ -1853,9 +1865,9 @@ begin CommitGUIUpdate; repeat - Engine.GetFileSystemInfo(FilePath, x, TDF, xx); + AEngine.GetFileSystemInfo(FilePath, x, TDF, xx); // Delete target files if necessary - if ParamBool1 and ((TDF < 512) or (TDF < FileSize) or (TDF < ParamInt64)) then try + if SplitDeleteTarget and ((TDF < 512) or (TDF < FileSize) or (TDF < SplitMaxSize)) then try if List.Count > 0 then for i := List.Count - 1 downto 0 do FreeDataItem(PDataItem(List[i])); @@ -1877,7 +1889,7 @@ begin end; } except end; // Test for target file existence - if Engine.FileExists(IncludeTrailingPathDelimiter(FilePath) + FileName, False) then begin + if AEngine.FileExists(IncludeTrailingPathDelimiter(FilePath) + FileName, False) then begin b := ShowMessageBox(Format(LANGTheTargetFileSAlreadyExistsDoYouWantToOverwriteIt, [StrToUTF8(IncludeTrailingPathDelimiter(FilePath) + FileName)]), [mbYes, mbNo], mbQuestion, mbNone, mbNo) = mbYes; if b then begin // * TODO: check error @@ -1899,15 +1911,15 @@ begin ws := 0; if (CurrSize >= 512) and (TDF >= CurrSize) then begin b := WriteSplitPart(IncludeTrailingPathDelimiter(FilePath) + FileName, CurrSize, ws); - if (not b) and (ParamInt64 > 0) then begin + if (not b) and (SplitMaxSize > 0) then begin FCancelMessage := Format(LANGAnErrorOccuredWhileOperationS, [Error^.message]); FShowCancelMessage := True; PrivateCancel := True; Break; end; Inc(SizeDone, ws); - if ParamInt64 > 0 then UpdateProgress2(SizeDone, Format('%d %%', [Trunc(SizeDone / FileSize * 100)])) - else UpdateProgress1(SizeDone, Format('%d %%', [Trunc(SizeDone / FileSize * 100)])); + if SplitMaxSize > 0 then UpdateProgress2(SizeDone, Format('%d %%', [Trunc(SizeDone / FileSize * 100)])) + else UpdateProgress1(SizeDone, Format('%d %%', [Trunc(SizeDone / FileSize * 100)])); CommitGUIUpdate; end; // Free space check - New disk question after operation @@ -1927,10 +1939,10 @@ begin end; if not (FCancelled or PrivateCancel) then begin repeat - Engine.GetFileSystemInfo(FilePath, x, TDF, xx); + AEngine.GetFileSystemInfo(FilePath, x, TDF, xx); if (TDF < 512) and (not NewDiskQuestion) then Break; until (TDF >= 512) or PrivateCancel or FCancelled; - if WriteCRCFile(DialogsParentWindow, Engine, IncludeTrailingPathDelimiter(FilePath) + FileName, OriginalFName, SizeDone, FileCRC) + if WriteCRCFile(DialogsParentWindow, AEngine, IncludeTrailingPathDelimiter(FilePath) + FileName, OriginalFName, SizeDone, FileCRC) then ShowMessageBox(Format(LANGSplitOfSSucceeded, [StrToUTF8(OriginalFName)]), [mbOK], mbInfo, mbNone, mbOK) else begin FCancelMessage := Format(LANGSplitOfSFailed, [StrToUTF8(OriginalFName)]); @@ -1938,7 +1950,7 @@ begin end; end; // * TODO: set real error, also free it - Engine.CloseFile(FD, nil); + AEngine.CloseFile(FD, nil); if List.Count > 0 then for i := List.Count - 1 downto 0 do FreeDataItem(PDataItem(List[i])); @@ -1951,10 +1963,6 @@ end; (********************************************************************************************************************************) (********************************************************************************************************************************) procedure TWorkerThread.ChmodFilesWorker; -// ParamBool1 = Recursive -// ParamInt1 = All/Dir/Files -// ParamCardinal1 = Mode - var SkipAll: boolean; function HandleChmod(AFileRec: PDataItemSL): boolean; @@ -1963,11 +1971,11 @@ var SkipAll: boolean; begin Result := True; // DebugMsg(['Chmod Debug: IsDir: ', AFileRec^.IsDir, ', Stage1: ', AFileRec^.Stage1, ', IsLnk: ', AFileRec^.IsLnk, '; Result = ', AFileRec^.IsDir and AFileRec^.Stage1 and (not AFileRec^.IsLnk)]); - if AFileRec^.DataItem^.IsDir and ParamBool1 and AFileRec^.Stage1 and (not AFileRec^.DataItem^.IsLnk) then Exit; - if (not AFileRec^.DataItem^.IsDir) and ParamBool1 and (ParamInt1 = 1) then Exit; // Directories only - if AFileRec^.DataItem^.IsDir and ParamBool1 and (ParamInt1 = 2) then Exit; // Files only + if AFileRec^.DataItem^.IsDir and (ChmodRecurseType >= 0) and AFileRec^.Stage1 and (not AFileRec^.DataItem^.IsLnk) then Exit; + if (not AFileRec^.DataItem^.IsDir) and (ChmodRecurseType >= 0) and (ChmodRecurseType = 1) then Exit; // Directories only + if AFileRec^.DataItem^.IsDir and (ChmodRecurseType >= 0) and (ChmodRecurseType = 2) then Exit; // Files only // * TODO: check error - Res := Engine.Chmod(String(AFileRec^.DataItem^.FName), ParamCardinal1, nil); + Res := AEngine.Chmod(String(AFileRec^.DataItem^.FName), ChmodMode, nil); // DebugMsg(['Result : ', Res]); if not Res then if SkipAll then Result := True else @@ -1993,7 +2001,7 @@ var i: longint; begin SkipAll := False; AList := TList.Create; - PrepareJobFilesFromPanel(AList, not ParamBool1); + PrepareJobFilesFromPanel(AList, ChmodRecurseType < 0); libc_chdir('/'); SetProgress1Params(AList.Count); UpdateProgress1(0, '0 %'); @@ -2029,9 +2037,6 @@ end; (********************************************************************************************************************************) (********************************************************************************************************************************) procedure TWorkerThread.ChownFilesWorker; -// ParamBool1 = Recursive -// ParamCardinal1 = UID -// ParamCardinal2 = GID var SkipAll: boolean; function HandleChown(AFileRec: PDataItemSL): boolean; @@ -2040,10 +2045,10 @@ var SkipAll: boolean; begin Result := True; // DebugMsg(['Chown Debug: IsDir: ', AFileRec^.IsDir, ', Stage1: ', AFileRec^.Stage1, ', IsLnk: ', AFileRec^.IsLnk, '; Result = ', AFileRec^.IsDir and AFileRec^.Stage1 and (not AFileRec^.IsLnk)]); - if (AFileRec^.DataItem^.IsDir and ParamBool1 and AFileRec^.Stage1 and (not AFileRec^.DataItem^.IsLnk)) or - ((not AFileRec^.DataItem^.IsDir) and ParamBool1) then Exit; + if (AFileRec^.DataItem^.IsDir and ChownRecursive and AFileRec^.Stage1 and (not AFileRec^.DataItem^.IsLnk)) or + ((not AFileRec^.DataItem^.IsDir) and ChownRecursive) then Exit; // * TODO: check error - Res := Engine.Chown(String(AFileRec^.DataItem^.FName), ParamCardinal1, ParamCardinal2, nil); + Res := AEngine.Chown(String(AFileRec^.DataItem^.FName), ChownUID, ChownGID, nil); // DebugMsg(['Result : ', Res]); if not Res then if SkipAll then Result := True else @@ -2069,7 +2074,7 @@ var i: longint; begin SkipAll := False; AList := TList.Create; - PrepareJobFilesFromPanel(AList, not ParamBool1); + PrepareJobFilesFromPanel(AList, not ChownRecursive); libc_chdir('/'); SetProgress1Params(AList.Count); UpdateProgress1(0, '0 %'); @@ -2231,7 +2236,7 @@ begin end; RunningTime := MilliSecondsBetween(tt, Now); finally - Finished := True; + FFinished := True; end; end; @@ -2259,7 +2264,7 @@ begin try OpenResult := (AEngine as TVFSEngine).VFSOpenURI(URI, @vfs_ask_question_callback, @vfs_ask_password_callback, nil, Self, @OpenError); finally - Finished := True; + FFinished := True; end; end; |
