diff options
| author | Tomas Bzatek <tbzatek@users.sourceforge.net> | 2009-11-29 16:29:03 +0100 |
|---|---|---|
| committer | Tomas Bzatek <tbzatek@users.sourceforge.net> | 2009-11-29 16:29:03 +0100 |
| commit | 959269c4432632e9228a5fa148eed2255e508554 (patch) | |
| tree | 090517465da49e84c7b3ec117f88d52ccd903107 /vfs/UVFSCore.pas | |
| parent | 9883e3b4eec8e457b49cb70ca006f5f7601332da (diff) | |
| download | tuxcmd-959269c4432632e9228a5fa148eed2255e508554.tar.xz | |
Introduce copy operation start/stop callsv0.6.73
This is the first step for a rapid extraction speed increase as we
don't need to open&seek for every file. Sorting by inode is still
need to be written but most archives work fine as they are.
TODO: writing into the archive needs special care (see TODO in zip plugin)
Diffstat (limited to 'vfs/UVFSCore.pas')
| -rw-r--r-- | vfs/UVFSCore.pas | 91 |
1 files changed, 69 insertions, 22 deletions
diff --git a/vfs/UVFSCore.pas b/vfs/UVFSCore.pas index 2bccea7..ff5445d 100644 --- a/vfs/UVFSCore.pas +++ b/vfs/UVFSCore.pas @@ -66,6 +66,8 @@ type FVFSGetPasswordRequired: TVFSGetPasswordRequired; FVFSSetCallbacks: TVFSSetCallbacks; FVFSResetPassword: TVFSResetPassword; + FVFSStartCopyOperation: TVFSStartCopyOperation; + FVFSStopCopyOperation: TVFSStopCopyOperation; function GetHandlesArchives: boolean; function GetHandlesNetwork: boolean; public @@ -152,11 +154,11 @@ type function GetPasswordRequired: boolean; procedure ResetPassword; - // the callbacks here are used for next volume prompts, password prompts (encrypted archives) - as long as this is specific to each file - function CopyFileInEx(Sender: Pointer; const SourceFile, DestFile: string; ErrorFunc: TEngineErrorFunc; Append: boolean; - AskQuestionCallback: PVFSAskQuestionCallback; AskPasswordCallback: PVFSAskPasswordCallback; ProgressCallback: PVFSProgressCallback; CallbackData: Pointer): boolean; - function CopyFileOutEx(Sender: Pointer; const SourceFile, DestFile: string; ErrorFunc: TEngineErrorFunc; Append: boolean; - AskQuestionCallback: PVFSAskQuestionCallback; AskPasswordCallback: PVFSAskPasswordCallback; ProgressCallback: PVFSProgressCallback; CallbackData: Pointer): boolean; + // callbacks here are used for next volume prompts, password prompts (encrypted archives) + function StartCopyOperation(Sender: Pointer; ErrorFunc: TEngineErrorFunc; AskQuestionCallback: PVFSAskQuestionCallback; AskPasswordCallback: PVFSAskPasswordCallback; ProgressCallback: PVFSProgressCallback; CallbackData: Pointer): boolean; + function StopCopyOperation(Sender: Pointer; ErrorFunc: TEngineErrorFunc): boolean; + function CopyFileInEx(Sender: Pointer; const SourceFile, DestFile: string; ErrorFunc: TEngineErrorFunc; Append: boolean): boolean; + function CopyFileOutEx(Sender: Pointer; const SourceFile, DestFile: string; ErrorFunc: TEngineErrorFunc; Append: boolean): boolean; published property Path: string read GetPath write SetPath; property BlockSize: Cardinal read GetBlockSize write SetBlockSize; @@ -242,6 +244,8 @@ begin @FVFSGetPasswordRequired := dlsym(ModuleHandle, 'VFSGetPasswordRequired'); @FVFSSetCallbacks := dlsym(ModuleHandle, 'VFSSetCallbacks'); @FVFSResetPassword := dlsym(ModuleHandle, 'VFSResetPassword'); + @FVFSStartCopyOperation := dlsym(ModuleHandle, 'VFSStartCopyOperation'); + @FVFSStopCopyOperation := dlsym(ModuleHandle, 'VFSStopCopyOperation'); // Initialize the extensions list SetLength(Extensions, 0); @@ -766,37 +770,34 @@ end; (********************************************************************************************************************************) function TVFSEngine.CopyFileIn(Sender: Pointer; const SourceFile, DestFile: string; ProgressFunc: TEngineProgressFunc; ErrorFunc: TEngineErrorFunc; Append: boolean): boolean; begin - Result := CopyFileInEx(Sender, SourceFile, DestFile, ErrorFunc, Append, nil, nil, nil, nil); + Result := StartCopyOperation(Sender, ErrorFunc, nil, nil, nil, nil); + Result := Result and CopyFileInEx(Sender, SourceFile, DestFile, ErrorFunc, Append); + Result := Result and StopCopyOperation(Sender, ErrorFunc); end; function TVFSEngine.CopyFileOut(Sender: Pointer; const SourceFile, DestFile: string; ProgressFunc: TEngineProgressFunc; ErrorFunc: TEngineErrorFunc; Append: boolean): boolean; begin - Result := CopyFileInEx(Sender, SourceFile, DestFile, ErrorFunc, Append, nil, nil, nil, nil); + Result := StartCopyOperation(Sender, ErrorFunc, nil, nil, nil, nil); + Result := Result and CopyFileInEx(Sender, SourceFile, DestFile, ErrorFunc, Append); + Result := Result and StopCopyOperation(Sender, ErrorFunc); end; -function TVFSEngine.CopyFileOutEx(Sender: Pointer; const SourceFile, DestFile: string; ErrorFunc: TEngineErrorFunc; Append: boolean; - AskQuestionCallback: PVFSAskQuestionCallback; AskPasswordCallback: PVFSAskPasswordCallback; ProgressCallback: PVFSProgressCallback; CallbackData: Pointer): boolean; +function TVFSEngine.CopyFileOutEx(Sender: Pointer; const SourceFile, DestFile: string; ErrorFunc: TEngineErrorFunc; Append: boolean): boolean; var Res: TVFSResult; begin Result := False; try if @FSourcePlugin.FVFSCopyToLocal <> nil then begin -// DebugMsg(['0 $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$']); -// DebugMsg([' Pointer(FGlobs) = 0x', IntToHex(Int64(FGlobs), 16), ', Pointer(@NewVFSCopyCallBackFunc) = 0x', IntToHex(Int64(@NewVFSCopyCallBackFunc), 16), ', Pointer(Self) = 0x', IntToHex(Int64(Self), 16)]); try - if @FSourcePlugin.FVFSSetCallbacks <> nil then - FSourcePlugin.FVFSSetCallbacks(FGlobs, AskQuestionCallback, AskPasswordCallback, ProgressCallback, CallbackData); Res := FSourcePlugin.FVFSCopyToLocal(FGlobs, PChar(SourceFile), PChar(DestFile), Append); - if @FSourcePlugin.FVFSSetCallbacks <> nil then - FSourcePlugin.FVFSSetCallbacks(FGlobs, nil, nil, nil, nil); except on E: Exception do begin DebugMsg(['*** Exception raised in TVFSEngine.CopyFileOut(Sender=', QWord(Sender), ', SourceFile=', SourceFile, ', DestFile=', DestFile, '): (', E.ClassName, '): ', E.Message]); Res := cVFS_WriteErr; end; end; -// DebugMsg(['1 $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$']); Result := Res = cVFS_OK; + // * TODO: Port to GError if (Res <> cVFS_OK) and Assigned(ErrorFunc) then case Res of cVFS_ReadErr: Result := ErrorFunc(Sender, 6, 0, SourceFile); @@ -810,19 +811,14 @@ begin end; end; -function TVFSEngine.CopyFileInEx(Sender: Pointer; const SourceFile, DestFile: string; ErrorFunc: TEngineErrorFunc; - Append: boolean; AskQuestionCallback: PVFSAskQuestionCallback; AskPasswordCallback: PVFSAskPasswordCallback; ProgressCallback: PVFSProgressCallback; CallbackData: Pointer): boolean; +function TVFSEngine.CopyFileInEx(Sender: Pointer; const SourceFile, DestFile: string; ErrorFunc: TEngineErrorFunc; Append: boolean): boolean; var Res: TVFSResult; begin Result := False; try if @FSourcePlugin.FVFSCopyFromLocal <> nil then begin try - if @FSourcePlugin.FVFSSetCallbacks <> nil then - FSourcePlugin.FVFSSetCallbacks(FGlobs, AskQuestionCallback, AskPasswordCallback, ProgressCallback, CallbackData); Res := FSourcePlugin.FVFSCopyFromLocal(FGlobs, PChar(SourceFile), PChar(DestFile), Append); - if @FSourcePlugin.FVFSSetCallbacks <> nil then - FSourcePlugin.FVFSSetCallbacks(FGlobs, nil, nil, nil, nil); except on E: Exception do begin DebugMsg(['*** Exception raised in TVFSEngine.CopyFileIn(Sender=', QWord(Sender), ', SourceFile=', SourceFile, ', DestFile=', DestFile, '): (', E.ClassName, '): ', E.Message]); @@ -830,6 +826,7 @@ begin end; end; Result := Res = cVFS_OK; + // * TODO: Port to GError if (Res <> cVFS_OK) and Assigned(ErrorFunc) then case Res of cVFS_ReadErr: Result := ErrorFunc(Sender, 6, 0, SourceFile); @@ -843,6 +840,56 @@ begin end; end; +function TVFSEngine.StartCopyOperation(Sender: Pointer; ErrorFunc: TEngineErrorFunc; AskQuestionCallback: PVFSAskQuestionCallback; AskPasswordCallback: PVFSAskPasswordCallback; ProgressCallback: PVFSProgressCallback; CallbackData: Pointer): boolean; +var Res: TVFSResult; +begin + Result := False; + try + if @FSourcePlugin.FVFSSetCallbacks <> nil then + FSourcePlugin.FVFSSetCallbacks(FGlobs, AskQuestionCallback, AskPasswordCallback, ProgressCallback, CallbackData); + if @FSourcePlugin.FVFSStartCopyOperation <> nil then begin + Res := FSourcePlugin.FVFSStartCopyOperation(FGlobs); + Result := Res = cVFS_OK; + // * TODO: Port to GError + if (Res <> cVFS_OK) and Assigned(ErrorFunc) then + case Res of + cVFS_ReadErr: Result := ErrorFunc(Sender, 6, 0, 'StartCopyOperation'); + cVFS_WriteErr: Result := ErrorFunc(Sender, 7, 0, 'StartCopyOperation'); + cVFS_mallocFailed: ErrorFunc(Sender, 1, 0, 'StartCopyOperation'); + cVFS_Cancelled: ErrorFunc(Sender, 0, 0, 'StartCopyOperation'); + end; + end else + ErrorFunc(Sender, 2, 0, 'StartCopyOperation not supported'); + except + on E: Exception do DebugMsg(['*** Exception raised in TVFSEngine.StartCopyOperation(Sender=', QWord(Sender), '): (', E.ClassName, '): ', E.Message]); + end; +end; + +function TVFSEngine.StopCopyOperation(Sender: Pointer; ErrorFunc: TEngineErrorFunc): boolean; +var Res: TVFSResult; +begin + Result := False; + try + if @FSourcePlugin.FVFSSetCallbacks <> nil then + FSourcePlugin.FVFSSetCallbacks(FGlobs, nil, nil, nil, nil); + if @FSourcePlugin.FVFSStopCopyOperation <> nil then begin + Res := FSourcePlugin.FVFSStopCopyOperation(FGlobs); + Result := Res = cVFS_OK; + // * TODO: Port to GError + if (Res <> cVFS_OK) and Assigned(ErrorFunc) then + case Res of + cVFS_ReadErr: Result := ErrorFunc(Sender, 6, 0, 'StopCopyOperation'); + cVFS_WriteErr: Result := ErrorFunc(Sender, 7, 0, 'StopCopyOperation'); + cVFS_mallocFailed: ErrorFunc(Sender, 1, 0, 'StopCopyOperation'); + cVFS_Cancelled: ErrorFunc(Sender, 0, 0, 'StopCopyOperation'); + end; + end else + ErrorFunc(Sender, 5, 0, 'StopCopyOperation not supported'); + except + on E: Exception do DebugMsg(['*** Exception raised in TVFSEngine.StopCopyOperation(Sender=', QWord(Sender), '): (', E.ClassName, '): ', E.Message]); + end; +end; + (********************************************************************************************************************************) (********************************************************************************************************************************) |
