summaryrefslogtreecommitdiff
path: root/vfs/UVFSCore.pas
diff options
context:
space:
mode:
Diffstat (limited to 'vfs/UVFSCore.pas')
-rw-r--r--vfs/UVFSCore.pas469
1 files changed, 246 insertions, 223 deletions
diff --git a/vfs/UVFSCore.pas b/vfs/UVFSCore.pas
index cf3e36a..d875b83 100644
--- a/vfs/UVFSCore.pas
+++ b/vfs/UVFSCore.pas
@@ -97,6 +97,8 @@ type
FBlockSize: Cardinal;
FArchiveMode: boolean;
FArchivePath: string;
+ FCopyProgressCallback: PVFSProgressCallback;
+ FCopyCallbackData: Pointer;
function GetPluginID: string;
function GetDataItemFromVFSItem(P: PVFSItem): PDataItem;
function GetArchiveStreamingType: boolean;
@@ -109,10 +111,10 @@ type
constructor Create(SourcePlugin: TVFSPlugin);
destructor Destroy; override;
- function GetListing(List: TList; const APath: string; AddDotFiles, FollowSymlinks, AddFullPath: boolean): integer; override;
- function GetFileInfo(const APath: string; FollowSymlinks, AddFullPath: boolean): PDataItem; override;
+ function GetListing(List: TList; const APath: string; AddDotFiles, FollowSymlinks, AddFullPath: boolean; Error: PPGError): boolean; override;
+ function GetFileInfo(const APath: string; FollowSymlinks, AddFullPath: boolean; Error: PPGError): PDataItem; override;
- function ChangeDir(const NewPath: string): integer; override;
+ function ChangeDir(const NewPath: string; Error: PPGError): boolean; override;
function GetPath: string; override;
procedure SetPath(Value: string); override;
@@ -124,32 +126,32 @@ type
function IsOnROMedium(const FileName: string): boolean; override;
function FileCanRun(const FileName: string): boolean; override;
- function MakeDir(const NewDir: string): integer; override;
- function Remove(const APath: string): integer; override;
- function MakeSymLink(const NewFileName, PointTo: string): integer; override;
- function Chmod(const FileName: string; Mode: cuLong): integer; override;
- function Chown(const FileName: string; UID, GID: cuLong): integer; override;
- function RenameFile(const SourceFile, DestFile: string): integer; override;
- function ChangeTimes(const APath: string; mtime, atime: time_t): integer; override;
+ function MakeDir(const NewDir: string; Error: PPGError): boolean; override;
+ function Remove(const APath: string; Error: PPGError): boolean; override;
+ function MakeSymLink(const NewFileName, PointTo: string; Error: PPGError): boolean; override;
+ function Chmod(const FileName: string; Mode: cuLong; Error: PPGError): boolean; override;
+ function Chown(const FileName: string; UID, GID: cuLong; Error: PPGError): boolean; override;
+ function RenameFile(const SourceFile, DestFile: string; Error: PPGError): boolean; override;
+ function ChangeTimes(const APath: string; mtime, atime: time_t; Error: PPGError): boolean; override;
function GetBlockSize: guint32; override;
procedure SetBlockSize(Value: guint32); override;
- function CopyFileIn(Sender: Pointer; const SourceFile, DestFile: string; ProgressFunc: TEngineProgressFunc; ErrorFunc: TEngineErrorFunc; Append: boolean): boolean; override;
- function CopyFileOut(Sender: Pointer; const SourceFile, DestFile: string; ProgressFunc: TEngineProgressFunc; ErrorFunc: TEngineErrorFunc; Append: boolean): boolean; override;
+ function CopyFileIn(const SourceFile, DestFile: string; Append: boolean; ProgressFunc: TEngineProgressFunc; Sender: Pointer): boolean; override;
+ function CopyFileOut(const SourceFile, DestFile: string; Append: boolean; ProgressFunc: TEngineProgressFunc; Sender: Pointer): boolean; override;
function IsOnSameFS(const Path1, Path2: string; FollowSymlinks: boolean): boolean; override;
function TwoSameFiles(const Path1, Path2: string; FollowSymlinks: boolean): boolean; override;
- function OpenFile(const APath: string; Mode: integer; var Error: integer): TEngineFileDes; override;
- function ReadFile(const FileDescriptor: TEngineFileDes; Buffer: Pointer; ABlockSize: integer; var Error: integer): integer; override;
- function WriteFile(const FileDescriptor: TEngineFileDes; Buffer: Pointer; BytesCount: integer; var Error: integer): integer; override;
- function CloseFile(const FileDescriptor: TEngineFileDes): integer; override;
- function FileSeek(const FileDescriptor: TEngineFileDes; const AbsoluteOffset: Int64; var Error: integer): Int64; override;
+ function OpenFile(const APath: string; Mode: integer; Error: PPGError): TEngineFileDes; override;
+ function ReadFile(const FileDescriptor: TEngineFileDes; Buffer: Pointer; ABlockSize: integer; Error: PPGError): integer; override;
+ function WriteFile(const FileDescriptor: TEngineFileDes; Buffer: Pointer; BytesCount: integer; Error: PPGError): integer; override;
+ function CloseFile(const FileDescriptor: TEngineFileDes; Error: PPGError): boolean; override;
+ function FileSeek(const FileDescriptor: TEngineFileDes; const AbsoluteOffset: Int64; Error: PPGError): Int64; override;
// VFS additions
- function VFSOpenURI(const URI: string; AskQuestionCallback: PVFSAskQuestionCallback; AskPasswordCallback: PVFSAskPasswordCallback; ProgressCallback: PVFSProgressCallback; CallbackData: Pointer): boolean;
- function VFSOpenEx(const OpenFile: string; AskQuestionCallback: PVFSAskQuestionCallback; AskPasswordCallback: PVFSAskPasswordCallback; ProgressCallback: PVFSProgressCallback; CallbackData: Pointer): TVFSResult;
- function VFSClose: boolean;
- function ChangeDirEx(const NewPath: string; AskQuestionCallback: PVFSAskQuestionCallback; AskPasswordCallback: PVFSAskPasswordCallback; ProgressCallback: PVFSProgressCallback; CallbackData: Pointer): integer;
+ function VFSOpenURI(const URI: string; AskQuestionCallback: PVFSAskQuestionCallback; AskPasswordCallback: PVFSAskPasswordCallback; ProgressCallback: PVFSProgressCallback; CallbackData: Pointer; Error: PPGError): boolean;
+ function VFSOpenEx(const OpenFile: string; AskQuestionCallback: PVFSAskQuestionCallback; AskPasswordCallback: PVFSAskPasswordCallback; ProgressCallback: PVFSProgressCallback; CallbackData: Pointer; Error: PPGError): boolean;
+ function VFSClose(Error: PPGError): boolean;
+ function ChangeDirEx(const NewPath: string; AskQuestionCallback: PVFSAskQuestionCallback; AskPasswordCallback: PVFSAskPasswordCallback; ProgressCallback: PVFSProgressCallback; CallbackData: Pointer; Error: PPGError): boolean;
function GetPathURI: string;
@@ -157,10 +159,10 @@ type
procedure ResetPassword;
// 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;
+ function StartCopyOperation(AskQuestionCallback: PVFSAskQuestionCallback; AskPasswordCallback: PVFSAskPasswordCallback; ProgressCallback: PVFSProgressCallback; CallbackData: Pointer): boolean;
+ function StopCopyOperation(ProgressCallback: PVFSProgressCallback; CallbackData: Pointer): boolean;
+ function CopyFileOutEx(const SourceFile, DestFile: string; Append: boolean): boolean;
+ function CopyFileInEx(const SourceFile, DestFile: string; Append: boolean): boolean;
published
property PluginID: string read GetPluginID;
property ArchiveMode: boolean read FArchiveMode;
@@ -176,7 +178,7 @@ var PluginList: TList;
implementation
-uses SysUtils, UConfig, ULocale;
+uses SysUtils, UConfig, ULocale, UError;
const ConstGlobalModulePath1 = '/usr/lib/tuxcmd';
@@ -359,6 +361,8 @@ begin
RemoveFileOnClose := '';
OpenedFromQuickConnect := False;
CustomPluginIDSave := '';
+ FCopyProgressCallback := nil;
+ FCopyCallbackData := nil;
if @FSourcePlugin.FVFSNew <> nil then FGlobs := FSourcePlugin.FVFSNew(@VFSLogFunc);
end;
@@ -375,13 +379,13 @@ begin
end;
end;
-function TVFSEngine.VFSOpenURI(const URI: string; AskQuestionCallback: PVFSAskQuestionCallback; AskPasswordCallback: PVFSAskPasswordCallback; ProgressCallback: PVFSProgressCallback; CallbackData: Pointer): boolean;
+function TVFSEngine.VFSOpenURI(const URI: string; AskQuestionCallback: PVFSAskQuestionCallback; AskPasswordCallback: PVFSAskPasswordCallback; ProgressCallback: PVFSProgressCallback; CallbackData: Pointer; Error: PPGError): boolean;
begin
Result := False;
if (FGlobs <> nil) and (@FSourcePlugin.FVFSOpenURI <> nil) then begin
if @FSourcePlugin.FVFSSetCallbacks <> nil then
FSourcePlugin.FVFSSetCallbacks(FGlobs, AskQuestionCallback, AskPasswordCallback, ProgressCallback, CallbackData);
- Result := FSourcePlugin.FVFSOpenURI(FGlobs, PChar(URI)) = cVFS_OK;
+ Result := FSourcePlugin.FVFSOpenURI(FGlobs, PChar(URI), Error);
FArchiveMode := False;
FArchivePath := '';
if @FSourcePlugin.FVFSSetCallbacks <> nil then
@@ -389,27 +393,27 @@ begin
end;
end;
-function TVFSEngine.VFSOpenEx(const OpenFile: string; AskQuestionCallback: PVFSAskQuestionCallback; AskPasswordCallback: PVFSAskPasswordCallback; ProgressCallback: PVFSProgressCallback; CallbackData: Pointer): TVFSResult;
+function TVFSEngine.VFSOpenEx(const OpenFile: string; AskQuestionCallback: PVFSAskQuestionCallback; AskPasswordCallback: PVFSAskPasswordCallback; ProgressCallback: PVFSProgressCallback; CallbackData: Pointer; Error: PPGError): boolean;
begin
- Result := cVFS_OK;
+ Result := False;
if (FGlobs <> nil) and (@FSourcePlugin.FVFSOpenArchive <> nil) then begin
if @FSourcePlugin.FVFSSetCallbacks <> nil then
FSourcePlugin.FVFSSetCallbacks(FGlobs, AskQuestionCallback, AskPasswordCallback, ProgressCallback, CallbackData);
- Result := FSourcePlugin.FVFSOpenArchive(FGlobs, PChar(OpenFile));
+ Result := FSourcePlugin.FVFSOpenArchive(FGlobs, PChar(OpenFile), Error);
FArchiveMode := True;
- if Result = cVFS_OK then FArchivePath := OpenFile
- else FArchivePath := '';
+ if Result then FArchivePath := OpenFile
+ else FArchivePath := '';
if @FSourcePlugin.FVFSSetCallbacks <> nil then
FSourcePlugin.FVFSSetCallbacks(FGlobs, nil, nil, nil, nil);
end;
end;
(********************************************************************************************************************************)
-function TVFSEngine.VFSClose: boolean;
+function TVFSEngine.VFSClose(Error: PPGError): boolean;
begin
Result := False;
- if (FGlobs <> nil) and (@FSourcePlugin.FVFSClose <> nil)
- then Result := FSourcePlugin.FVFSClose(FGlobs) = cVFS_OK;
+ if (FGlobs <> nil) and (@FSourcePlugin.FVFSClose <> nil) then
+ Result := FSourcePlugin.FVFSClose(FGlobs, Error);
end;
function TVFSEngine.GetDataItemFromVFSItem(P: PVFSItem): PDataItem;
@@ -444,30 +448,21 @@ begin
Result := Item;
end;
-function TVFSEngine.GetListing(List: TList; const APath: string; AddDotFiles, FollowSymlinks, AddFullPath: boolean): integer;
+function TVFSEngine.GetListing(List: TList; const APath: string; AddDotFiles, FollowSymlinks, AddFullPath: boolean; Error: PPGError): boolean;
var P: PVFSItem;
Item: PDataItem;
- Res: integer;
+ FError: PGError;
begin
DebugMsg(['^^VFS (II): GetListing begin']);
- Result := 0;
+ Result := False;
try
- if @FSourcePlugin.FVFSListFirst = nil then begin
- Result := ERRNoAccess;
- Exit;
- end;
- P := real_libc_malloc(sizeof(TVFSItem));
- memset(P, 0, sizeof(TVFSItem));
- Res := FSourcePlugin.FVFSListFirst(FGlobs, PChar(APath), P, FollowSymlinks, AddFullPath);
- if Res <> cVFS_OK then begin
- FSourcePlugin.FVFSListClose(FGlobs);
- if Res = cVFS_Not_More_Files then Result := 0
- else Result := Res;
- real_libc_free(P);
+ if (@FSourcePlugin.FVFSListFirst = nil) or (@FSourcePlugin.FVFSListNext = nil) or (@FSourcePlugin.FVFSListClose = nil) then begin
+ g_set_error(Error, G_IO_ERROR, gint(G_IO_ERROR_NOT_SUPPORTED), '%s', 'File listing not supported by the VFS module.');
Exit;
end;
-
- repeat
+ FError := nil;
+ P := FSourcePlugin.FVFSListFirst(FGlobs, PChar(APath), FollowSymlinks, AddFullPath, @FError);
+ while (P <> nil) and (BreakProcessingType <> 2) do begin
if (strlen(P^.FName) > 0) and (AddDotFiles or (P^.FName[0] <> '.')) then begin
Item := GetDataItemFromVFSItem(P);
List.Add(Item);
@@ -475,14 +470,22 @@ begin
if P^.FName <> nil then real_libc_free(P^.FName);
if P^.FDisplayName <> nil then real_libc_free(P^.FDisplayName);
if P^.sLinkTo <> nil then real_libc_free(P^.sLinkTo);
- memset(P, 0, sizeof(TVFSItem));
- Res := FSourcePlugin.FVFSListNext(FGlobs, P);
- until (Res <> cVFS_OK) or (BreakProcessingType = 2);
- if BreakProcessingType <> 0 then DebugMsg(['^^VFS (WW): GetListing: stopped by BreakProcessing']);
-
+ real_libc_free(P);
+ P := FSourcePlugin.FVFSListNext(FGlobs, @FError);
+ end;
+ Result := FError = nil;
+ if BreakProcessingType <> 0 then begin
+ DebugMsg(['^^VFS (WW): GetListing: stopped by BreakProcessing']);
+ g_set_error(Error, G_IO_ERROR, gint(G_IO_ERROR_CANCELLED), '%s', 'The operation has been cancelled.');
+ Result := False;
+ end else begin
+ if (Error <> nil) and (FError <> nil) then
+ Error^ := g_error_copy(FError);
+ end;
+ if FError <> nil then
+ g_error_free(FError);
real_libc_free(P);
- FSourcePlugin.FVFSListClose(FGlobs);
- if Res <> cVFS_Not_More_Files then Result := Res;
+ FSourcePlugin.FVFSListClose(FGlobs, nil);
except
on E: Exception do
DebugMsg(['^^VFS (EE): GetListing: Exception: ', E.Message]);
@@ -491,18 +494,19 @@ begin
DebugMsg(['^^VFS (II): GetListing end.']);
end;
-function TVFSEngine.GetFileInfo(const APath: string; FollowSymlinks, AddFullPath: boolean): PDataItem;
+function TVFSEngine.GetFileInfo(const APath: string; FollowSymlinks, AddFullPath: boolean; Error: PPGError): PDataItem;
var P: PVFSItem;
- Res: integer;
begin
DebugMsg(['^^VFS (II): GetFileInfo begin']);
Result := nil;
- if @FSourcePlugin.FVFSFileInfo = nil then Exit;
+
+ if @FSourcePlugin.FVFSFileInfo = nil then begin
+ g_set_error(Error, G_IO_ERROR, gint(G_IO_ERROR_NOT_SUPPORTED), '%s', 'Querying file info is not supported by the VFS module.');
+ Exit;
+ end;
try
- P := real_libc_malloc(sizeof(TVFSItem));
- memset(P, 0, sizeof(TVFSItem));
- Res := FSourcePlugin.FVFSFileInfo(FGlobs, PChar(APath), P, FollowSymlinks, AddFullPath);
- if Res = cVFS_OK then
+ P := FSourcePlugin.FVFSFileInfo(FGlobs, PChar(APath), FollowSymlinks, AddFullPath, Error);
+ if P <> nil then
Result := GetDataItemFromVFSItem(P);
if P^.FName <> nil then real_libc_free(P^.FName);
if P^.FDisplayName <> nil then real_libc_free(P^.FDisplayName);
@@ -527,13 +531,12 @@ begin
AFSSize := -1;
AFSFree := -1;
AFSName := nil;
- if FSourcePlugin.FVFSGetFileSystemInfo(FGlobs, PChar(APath), @AFSSize, @AFSFree, @AFSName) = cVFS_OK then begin
- FSSize := AFSSize;
- FSFree := AFSFree;
- if AFSName <> nil then begin
- FSName := string(AFSName);
- real_libc_free(AFSName);
- end;
+ FSourcePlugin.FVFSGetFileSystemInfo(FGlobs, PChar(APath), @AFSSize, @AFSFree, @AFSName);
+ FSSize := AFSSize;
+ FSFree := AFSFree;
+ if AFSName <> nil then begin
+ FSName := string(AFSName);
+ real_libc_free(AFSName);
end;
end;
end;
@@ -546,7 +549,7 @@ end;
function TVFSEngine.FileCanRun(const FileName: string): boolean;
var Item: PDataItem;
begin
- Item := GetFileInfo(FileName, True, True);
+ Item := GetFileInfo(FileName, True, True, nil);
Result := (Item <> nil) and Item^.IsExecutable;
FreeDataItem(Item);
end;
@@ -577,26 +580,23 @@ begin
end;
end;
-function TVFSEngine.ChangeDir(const NewPath: string): integer;
+function TVFSEngine.ChangeDir(const NewPath: string; Error: PPGError): boolean;
begin
- DebugMsg(['^^VFS (II): ChangeDir begin']);
- Result := 0;
+ Result := False;
try
- Result := FSourcePlugin.FVFSChangeDir(FGlobs, PChar(NewPath));
-// Sleep(3000);
+ Result := FSourcePlugin.FVFSChangeDir(FGlobs, PChar(NewPath), Error);
except
on E: Exception do DebugMsg(['^^VFS (EE): ChangeDir: Exception: ', E.Message]);
end;
- DebugMsg(['^^VFS (II): ChangeDir end.']);
end;
-function TVFSEngine.ChangeDirEx(const NewPath: string; AskQuestionCallback: PVFSAskQuestionCallback; AskPasswordCallback: PVFSAskPasswordCallback; ProgressCallback: PVFSProgressCallback; CallbackData: Pointer): integer;
+function TVFSEngine.ChangeDirEx(const NewPath: string; AskQuestionCallback: PVFSAskQuestionCallback; AskPasswordCallback: PVFSAskPasswordCallback; ProgressCallback: PVFSProgressCallback; CallbackData: Pointer; Error: PPGError): boolean;
begin
- Result := ERRNoAccess;
+ Result := False;
if (FGlobs <> nil) and (@FSourcePlugin.FVFSChangeDir <> nil) then begin
if @FSourcePlugin.FVFSSetCallbacks <> nil then
FSourcePlugin.FVFSSetCallbacks(FGlobs, AskQuestionCallback, AskPasswordCallback, ProgressCallback, CallbackData);
- Result := ChangeDir(NewPath);
+ Result := ChangeDir(NewPath, Error);
if @FSourcePlugin.FVFSSetCallbacks <> nil then
FSourcePlugin.FVFSSetCallbacks(FGlobs, nil, nil, nil, nil);
end;
@@ -604,7 +604,7 @@ end;
procedure TVFSEngine.SetPath(Value: string);
begin
- ChangeDir(Value);
+ ChangeDir(Value, nil);
end;
function TVFSEngine.FileExists(const FileName: string; FollowSymlinks: boolean): boolean;
@@ -614,9 +614,8 @@ begin
if (FGlobs = nil) or (@FSourcePlugin.FVFSFileInfo = nil) then
Exit;
try
- P := real_libc_malloc(sizeof(TVFSItem));
- memset(P, 0, sizeof(TVFSItem));
- Result := FSourcePlugin.FVFSFileInfo(FGlobs, PChar(FileName), P, FollowSymlinks, False) = cVFS_OK;
+ P := FSourcePlugin.FVFSFileInfo(FGlobs, PChar(FileName), FollowSymlinks, False, nil);
+ Result := P <> nil;
real_libc_free(P);
except
on E: Exception do
@@ -626,16 +625,13 @@ end;
function TVFSEngine.DirectoryExists(const FileName: string; FollowSymlinks: boolean): boolean;
var P: PVFSItem;
- Res: integer;
begin
Result := False;
if (FGlobs = nil) or (@FSourcePlugin.FVFSFileInfo = nil) then
Exit;
try
- P := real_libc_malloc(sizeof(TVFSItem));
- memset(P, 0, sizeof(TVFSItem));
- Res := FSourcePlugin.FVFSFileInfo(FGlobs, PChar(FileName), P, FollowSymlinks, False);
- Result := (Res = cVFS_OK) and (TVFSItemType(P^.ItemType) = vDirectory);
+ P := FSourcePlugin.FVFSFileInfo(FGlobs, PChar(FileName), FollowSymlinks, False, nil);
+ Result := (P <> nil) and (TVFSItemType(P^.ItemType) = vDirectory);
real_libc_free(P);
except
on E: Exception do
@@ -643,46 +639,74 @@ begin
end;
end;
-function TVFSEngine.MakeDir(const NewDir: string): integer;
+function TVFSEngine.MakeDir(const NewDir: string; Error: PPGError): boolean;
begin
- if @FSourcePlugin.FVFSMkDir <> nil then Result := FSourcePlugin.FVFSMkDir(FGlobs, PChar(NewDir))
- else Result := cVFS_Failed;
+ if @FSourcePlugin.FVFSMkDir <> nil then
+ Result := FSourcePlugin.FVFSMkDir(FGlobs, PChar(NewDir), Error)
+ else begin
+ Result := False;
+ g_set_error(Error, G_IO_ERROR, gint(G_IO_ERROR_NOT_SUPPORTED), '%s', 'Creating directories is not supported by the VFS module.');
+ end;
end;
-function TVFSEngine.Remove(const APath: string): integer;
+function TVFSEngine.Remove(const APath: string; Error: PPGError): boolean;
begin
- if @FSourcePlugin.FVFSRemove <> nil then Result := FSourcePlugin.FVFSRemove(FGlobs, PChar(APath))
- else Result := cVFS_Failed;
+ if @FSourcePlugin.FVFSRemove <> nil then
+ Result := FSourcePlugin.FVFSRemove(FGlobs, PChar(APath), Error)
+ else begin
+ Result := False;
+ g_set_error(Error, G_IO_ERROR, gint(G_IO_ERROR_NOT_SUPPORTED), '%s', 'Removing files is not supported by the VFS module.');
+ end;
end;
-function TVFSEngine.RenameFile(const SourceFile, DestFile: string): integer;
+function TVFSEngine.RenameFile(const SourceFile, DestFile: string; Error: PPGError): boolean;
begin
- if @FSourcePlugin.FVFSRename <> nil then Result := FSourcePlugin.FVFSRename(FGlobs, PChar(SourceFile), PChar(DestFile))
- else Result := cVFS_Failed;
+ if @FSourcePlugin.FVFSRename <> nil then
+ Result := FSourcePlugin.FVFSRename(FGlobs, PChar(SourceFile), PChar(DestFile), Error)
+ else begin
+ Result := False;
+ g_set_error(Error, G_IO_ERROR, gint(G_IO_ERROR_NOT_SUPPORTED), '%s', 'Renaming files is not supported by the VFS module.');
+ end;
end;
-function TVFSEngine.MakeSymLink(const NewFileName, PointTo: string): integer;
+function TVFSEngine.MakeSymLink(const NewFileName, PointTo: string; Error: PPGError): boolean;
begin
- if @FSourcePlugin.FVFSMakeSymLink <> nil then Result := FSourcePlugin.FVFSMakeSymLink(FGlobs, PChar(NewFileName), PChar(PointTo))
- else Result := cVFS_Failed;
+ if @FSourcePlugin.FVFSMakeSymLink <> nil then
+ Result := FSourcePlugin.FVFSMakeSymLink(FGlobs, PChar(NewFileName), PChar(PointTo), Error)
+ else begin
+ Result := False;
+ g_set_error(Error, G_IO_ERROR, gint(G_IO_ERROR_NOT_SUPPORTED), '%s', 'Creating symbolic links is not supported by the VFS module.');
+ end;
end;
-function TVFSEngine.Chmod(const FileName: string; Mode: cuLong): integer;
+function TVFSEngine.Chmod(const FileName: string; Mode: cuLong; Error: PPGError): boolean;
begin
- if @FSourcePlugin.FVFSChmod <> nil then Result := FSourcePlugin.FVFSChmod(FGlobs, PChar(FileName), Mode)
- else Result := cVFS_Failed;
+ if @FSourcePlugin.FVFSChmod <> nil then
+ Result := FSourcePlugin.FVFSChmod(FGlobs, PChar(FileName), Mode, Error)
+ else begin
+ Result := False;
+ g_set_error(Error, G_IO_ERROR, gint(G_IO_ERROR_NOT_SUPPORTED), '%s', 'Chmod is not supported by the VFS module.');
+ end;
end;
-function TVFSEngine.Chown(const FileName: string; UID, GID: cuLong): integer;
+function TVFSEngine.Chown(const FileName: string; UID, GID: cuLong; Error: PPGError): boolean;
begin
- if @FSourcePlugin.FVFSChown <> nil then Result := FSourcePlugin.FVFSChown(FGlobs, PChar(FileName), UID, GID)
- else Result := cVFS_Failed;
+ if @FSourcePlugin.FVFSChown <> nil then
+ Result := FSourcePlugin.FVFSChown(FGlobs, PChar(FileName), UID, GID, Error)
+ else begin
+ Result := False;
+ g_set_error(Error, G_IO_ERROR, gint(G_IO_ERROR_NOT_SUPPORTED), '%s', 'Chown is not supported by the VFS module.');
+ end;
end;
-function TVFSEngine.ChangeTimes(const APath: string; mtime, atime: time_t): integer;
+function TVFSEngine.ChangeTimes(const APath: string; mtime, atime: time_t; Error: PPGError): boolean;
begin
- if @FSourcePlugin.FVFSChangeTimes <> nil then Result := FSourcePlugin.FVFSChangeTimes(FGlobs, PChar(APath), mtime, atime)
- else Result := cVFS_Failed;
+ if @FSourcePlugin.FVFSChangeTimes <> nil then
+ Result := FSourcePlugin.FVFSChangeTimes(FGlobs, PChar(APath), mtime, atime, Error)
+ else begin
+ Result := False;
+ g_set_error(Error, G_IO_ERROR, gint(G_IO_ERROR_NOT_SUPPORTED), '%s', 'Changing timestamps is not supported by the VFS module.');
+ end;
end;
function TVFSEngine.GetDirSize(const APath: string): Int64;
@@ -719,46 +743,51 @@ begin
else Result := True;
end;
-function TVFSEngine.OpenFile(const APath: string; Mode: integer; var Error: integer): TEngineFileDes;
-var i: integer;
+function TVFSEngine.OpenFile(const APath: string; Mode: integer; Error: PPGError): TEngineFileDes;
begin
- if @FSourcePlugin.FVFSOpenFile <> nil then begin
- Result := FSourcePlugin.FVFSOpenFile(FGlobs, PChar(APath), Mode, @i);
- Error := i;
- end else Result := nil;
+ if @FSourcePlugin.FVFSOpenFile <> nil then
+ Result := FSourcePlugin.FVFSOpenFile(FGlobs, PChar(APath), Mode, Error)
+ else begin
+ Result := nil;
+ g_set_error(Error, G_IO_ERROR, gint(G_IO_ERROR_NOT_SUPPORTED), '%s', 'Manual opening files is not supported by the VFS module.');
+ end;
end;
-function TVFSEngine.ReadFile(const FileDescriptor: TEngineFileDes; Buffer: Pointer; ABlockSize: integer; var Error: integer): integer;
-var i: integer;
+function TVFSEngine.ReadFile(const FileDescriptor: TEngineFileDes; Buffer: Pointer; ABlockSize: integer; Error: PPGError): integer;
begin
- if @FSourcePlugin.FVFSReadFile <> nil then begin
- Result := FSourcePlugin.FVFSReadFile(FGlobs, FileDescriptor, Buffer, ABlockSize, @i);
- Error := i;
- end else Result := -1;
+ if @FSourcePlugin.FVFSReadFile <> nil then
+ Result := FSourcePlugin.FVFSReadFile(FGlobs, FileDescriptor, Buffer, ABlockSize, Error)
+ else begin
+ Result := -1;
+ g_set_error(Error, G_IO_ERROR, gint(G_IO_ERROR_NOT_SUPPORTED), '%s', 'Manual read is not supported by the VFS module.');
+ end;
end;
-function TVFSEngine.WriteFile(const FileDescriptor: TEngineFileDes; Buffer: Pointer; BytesCount: integer; var Error: integer): integer;
-var i: integer;
+function TVFSEngine.WriteFile(const FileDescriptor: TEngineFileDes; Buffer: Pointer; BytesCount: integer; Error: PPGError): integer;
begin
- if @FSourcePlugin.FVFSWriteFile <> nil then begin
- Result := FSourcePlugin.FVFSWriteFile(FGlobs, FileDescriptor, Buffer, BytesCount, @i);
- Error := i;
- end else Result := -1;
+ if @FSourcePlugin.FVFSWriteFile <> nil then
+ Result := FSourcePlugin.FVFSWriteFile(FGlobs, FileDescriptor, Buffer, BytesCount, Error)
+ else begin
+ Result := -1;
+ g_set_error(Error, G_IO_ERROR, gint(G_IO_ERROR_NOT_SUPPORTED), '%s', 'Manual write is not supported by the VFS module.');
+ end;
end;
-function TVFSEngine.CloseFile(const FileDescriptor: TEngineFileDes): integer;
+function TVFSEngine.CloseFile(const FileDescriptor: TEngineFileDes; Error: PPGError): boolean;
begin
- if @FSourcePlugin.FVFSCloseFile <> nil then Result := FSourcePlugin.FVFSCloseFile(FGlobs, FileDescriptor)
- else Result := 0;
+ if @FSourcePlugin.FVFSCloseFile <> nil then
+ Result := FSourcePlugin.FVFSCloseFile(FGlobs, FileDescriptor, nil)
+ else Result := False;
end;
-function TVFSEngine.FileSeek(const FileDescriptor: TEngineFileDes; const AbsoluteOffset: Int64; var Error: integer): Int64;
-var i: integer;
+function TVFSEngine.FileSeek(const FileDescriptor: TEngineFileDes; const AbsoluteOffset: Int64; Error: PPGError): Int64;
begin
- if @FSourcePlugin.FVFSFileSeek <> nil then begin
- Result := FSourcePlugin.FVFSFileSeek(FGlobs, FileDescriptor, AbsoluteOffset, @i);
- Error := i;
- end else Result := -1;
+ if @FSourcePlugin.FVFSFileSeek <> nil then
+ Result := FSourcePlugin.FVFSFileSeek(FGlobs, FileDescriptor, AbsoluteOffset, Error)
+ else begin
+ Result := -1;
+ g_set_error(Error, G_IO_ERROR, gint(G_IO_ERROR_NOT_SUPPORTED), '%s', 'Manual seek is not supported by the VFS module.');
+ end;
end;
function TVFSEngine.TwoSameFiles(const Path1, Path2: string; FollowSymlinks: boolean): boolean;
@@ -770,129 +799,123 @@ end;
(********************************************************************************************************************************)
-function TVFSEngine.CopyFileIn(Sender: Pointer; const SourceFile, DestFile: string; ProgressFunc: TEngineProgressFunc; ErrorFunc: TEngineErrorFunc; Append: boolean): boolean;
+function TVFSEngine.CopyFileIn(const SourceFile, DestFile: string; Append: boolean; ProgressFunc: TEngineProgressFunc; Sender: Pointer): boolean;
begin
- Result := StartCopyOperation(Sender, ErrorFunc, nil, nil, nil, nil);
- Result := Result and CopyFileInEx(Sender, SourceFile, DestFile, ErrorFunc, Append);
- Result := Result and StopCopyOperation(Sender, ErrorFunc);
+ DebugMsg(['** (WW): deprecated method CopyFileIn called from a TVFSEngine instance!']);
+ Result := StartCopyOperation(nil, nil, nil, nil);
+ Result := Result and CopyFileInEx(SourceFile, DestFile, Append);
+ Result := Result and StopCopyOperation(nil, nil);
end;
-function TVFSEngine.CopyFileOut(Sender: Pointer; const SourceFile, DestFile: string; ProgressFunc: TEngineProgressFunc; ErrorFunc: TEngineErrorFunc; Append: boolean): boolean;
+function TVFSEngine.CopyFileOut(const SourceFile, DestFile: string; Append: boolean; ProgressFunc: TEngineProgressFunc; Sender: Pointer): boolean;
begin
- Result := StartCopyOperation(Sender, ErrorFunc, nil, nil, nil, nil);
- Result := Result and CopyFileInEx(Sender, SourceFile, DestFile, ErrorFunc, Append);
- Result := Result and StopCopyOperation(Sender, ErrorFunc);
+ DebugMsg(['** (WW): deprecated method CopyFileOut called from a TVFSEngine instance!']);
+ Result := StartCopyOperation(nil, nil, nil, nil);
+ Result := Result and CopyFileOutEx(SourceFile, DestFile, Append);
+ Result := Result and StopCopyOperation(nil, nil);
end;
-function TVFSEngine.CopyFileOutEx(Sender: Pointer; const SourceFile, DestFile: string; ErrorFunc: TEngineErrorFunc; Append: boolean): boolean;
-var Res: TVFSResult;
+function TVFSEngine.CopyFileOutEx(const SourceFile, DestFile: string; Append: boolean): boolean;
+var Error: PGError;
+ ACopyProgressCallback: TVFSProgressCallback;
begin
Result := False;
try
- if @FSourcePlugin.FVFSCopyToLocal <> nil then begin
- try
- Res := FSourcePlugin.FVFSCopyToLocal(FGlobs, PChar(SourceFile), PChar(DestFile), Append);
- 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;
+ Error := nil;
+ if @FSourcePlugin.FVFSCopyToLocal <> nil then
+ Result := FSourcePlugin.FVFSCopyToLocal(FGlobs, PChar(SourceFile), PChar(DestFile), Append, @Error)
+ else
+ g_set_error(@Error, G_IO_ERROR, gint(G_IO_ERROR_NOT_SUPPORTED), '%s', 'VFSCopyToLocal not supported by the VFS module.');
+ if Error <> nil then begin
+ if FCopyProgressCallback <> nil then begin
+ @ACopyProgressCallback := FCopyProgressCallback;
+ Result := ACopyProgressCallback(0, Error, FCopyCallbackData);
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);
- cVFS_WriteErr: Result := ErrorFunc(Sender, 7, 0, DestFile);
- cVFS_mallocFailed: ErrorFunc(Sender, 1, 0, SourceFile);
- cVFS_Cancelled: ErrorFunc(Sender, 0, 0, SourceFile);
- end;
- end else Result := False;
+ g_error_free(Error);
+ end;
except
- on E: Exception do DebugMsg(['*** Exception raised in TVFSEngine.CopyFileOut(Sender=', QWord(Sender), ', SourceFile=', SourceFile, ', DestFile=', DestFile, '): (', E.ClassName, '): ', E.Message]);
+ on E: Exception do begin
+ DebugMsg(['*** Exception raised in TVFSEngine.CopyFileOutEx(SourceFile=', SourceFile, ', DestFile=', DestFile, ', Append=', Append,'): (', E.ClassName, '): ', E.Message]);
+ Result := False;
+ end;
end;
end;
-function TVFSEngine.CopyFileInEx(Sender: Pointer; const SourceFile, DestFile: string; ErrorFunc: TEngineErrorFunc; Append: boolean): boolean;
-var Res: TVFSResult;
+function TVFSEngine.CopyFileInEx(const SourceFile, DestFile: string; Append: boolean): boolean;
+var Error: PGError;
+ACopyProgressCallback: TVFSProgressCallback;
begin
Result := False;
try
- if @FSourcePlugin.FVFSCopyFromLocal <> nil then begin
- try
- Res := FSourcePlugin.FVFSCopyFromLocal(FGlobs, PChar(SourceFile), PChar(DestFile), Append);
- except
- on E: Exception do begin
- DebugMsg(['*** Exception raised in TVFSEngine.CopyFileIn(Sender=', QWord(Sender), ', SourceFile=', SourceFile, ', DestFile=', DestFile, '): (', E.ClassName, '): ', E.Message]);
- Res := cVFS_WriteErr;
- end;
+ Error := nil;
+ if @FSourcePlugin.FVFSCopyFromLocal <> nil then
+ Result := FSourcePlugin.FVFSCopyFromLocal(FGlobs, PChar(SourceFile), PChar(DestFile), Append, @Error)
+ else
+ g_set_error(@Error, G_IO_ERROR, gint(G_IO_ERROR_NOT_SUPPORTED), '%s', 'VFSCopyFromLocal not supported by the VFS module.');
+ if Error <> nil then begin
+ if FCopyProgressCallback <> nil then begin
+ @ACopyProgressCallback := FCopyProgressCallback;
+ Result := ACopyProgressCallback(0, Error, FCopyCallbackData);
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);
- cVFS_WriteErr: Result := ErrorFunc(Sender, 7, 0, DestFile);
- cVFS_mallocFailed: ErrorFunc(Sender, 1, 0, SourceFile);
- cVFS_Cancelled: ErrorFunc(Sender, 0, 0, SourceFile);
- end;
- end else Result := False;
+ g_error_free(Error);
+ end;
except
- on E: Exception do DebugMsg(['*** Exception raised in TVFSEngine.CopyFileIn(Sender=', QWord(Sender), ', SourceFile=', SourceFile, ', DestFile=', DestFile, '): (', E.ClassName, '): ', E.Message]);
+ on E: Exception do begin
+ DebugMsg(['*** Exception raised in TVFSEngine.CopyFileInEx(SourceFile=', SourceFile, ', DestFile=', DestFile, ', Append=', Append,'): (', E.ClassName, '): ', E.Message]);
+ Result := False;
+ end;
end;
end;
-function TVFSEngine.StartCopyOperation(Sender: Pointer; ErrorFunc: TEngineErrorFunc; AskQuestionCallback: PVFSAskQuestionCallback; AskPasswordCallback: PVFSAskPasswordCallback; ProgressCallback: PVFSProgressCallback; CallbackData: Pointer): boolean;
-var Res: TVFSResult;
+function TVFSEngine.StartCopyOperation(AskQuestionCallback: PVFSAskQuestionCallback; AskPasswordCallback: PVFSAskPasswordCallback; ProgressCallback: PVFSProgressCallback; CallbackData: Pointer): boolean;
+var Error: PGError;
begin
Result := not ArchiveMode;
try
if @FSourcePlugin.FVFSSetCallbacks <> nil then
FSourcePlugin.FVFSSetCallbacks(FGlobs, AskQuestionCallback, AskPasswordCallback, ProgressCallback, CallbackData);
+ FCopyProgressCallback := ProgressCallback;
+ FCopyCallbackData := CallbackData;
if ArchiveMode then begin
- 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');
+ Error := nil;
+ if @FSourcePlugin.FVFSStartCopyOperation <> nil then
+ Result := FSourcePlugin.FVFSStartCopyOperation(FGlobs, @Error)
+ else
+ g_set_error(@Error, G_IO_ERROR, gint(G_IO_ERROR_NOT_SUPPORTED), '%s', 'VFSStartCopyOperation not supported by the VFS module.');
+ if Error <> nil then begin
+ if ProgressCallback <> nil then
+ Result := ProgressCallback^(0, Error, CallbackData);
+ g_error_free(Error);
+ end;
end;
except
- on E: Exception do DebugMsg(['*** Exception raised in TVFSEngine.StartCopyOperation(Sender=', QWord(Sender), '): (', E.ClassName, '): ', E.Message]);
+ on E: Exception do DebugMsg(['*** Exception raised in TVFSEngine.StartCopyOperation(CallbackData=', CallbackData, '): (', E.ClassName, '): ', E.Message]);
end;
end;
-function TVFSEngine.StopCopyOperation(Sender: Pointer; ErrorFunc: TEngineErrorFunc): boolean;
-var Res: TVFSResult;
+function TVFSEngine.StopCopyOperation(ProgressCallback: PVFSProgressCallback; CallbackData: Pointer): boolean;
+var Error: PGError;
begin
Result := not ArchiveMode;
try
if @FSourcePlugin.FVFSSetCallbacks <> nil then
FSourcePlugin.FVFSSetCallbacks(FGlobs, nil, nil, nil, nil);
if ArchiveMode then begin
- 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');
+ Error := nil;
+ if @FSourcePlugin.FVFSStopCopyOperation <> nil then
+ Result := FSourcePlugin.FVFSStopCopyOperation(FGlobs, @Error)
+ else
+ g_set_error(@Error, G_IO_ERROR, gint(G_IO_ERROR_NOT_SUPPORTED), '%s', 'VFSStopCopyOperation not supported by the VFS module.');
+ if Error <> nil then begin
+ if ProgressCallback <> nil then
+ Result := ProgressCallback^(0, Error, CallbackData);
+ g_error_free(Error);
+ end;
end;
+ FCopyProgressCallback := nil;
+ FCopyCallbackData := nil;
except
- on E: Exception do DebugMsg(['*** Exception raised in TVFSEngine.StopCopyOperation(Sender=', QWord(Sender), '): (', E.ClassName, '): ', E.Message]);
+ on E: Exception do DebugMsg(['*** Exception raised in TVFSEngine.StopCopyOperation(CallbackData=', CallbackData, '): (', E.ClassName, '): ', E.Message]);
end;
end;