From 4aba4d7597005af1efa12f420e01d5f938ad60d8 Mon Sep 17 00:00:00 2001 From: Tomas Bzatek Date: Sun, 25 Oct 2009 18:11:35 +0100 Subject: Clean VFS API up a little Strictly split archiving and networking mode, get rid of prefixes --- vfs/UVFSCore.pas | 57 +++++++++++++++++++++++--------------------------- vfs/uVFSprototypes.pas | 20 +++++++----------- 2 files changed, 34 insertions(+), 43 deletions(-) (limited to 'vfs') diff --git a/vfs/UVFSCore.pas b/vfs/UVFSCore.pas index 7516544..bf2cd9d 100644 --- a/vfs/UVFSCore.pas +++ b/vfs/UVFSCore.pas @@ -31,7 +31,8 @@ type FVFSFree: TVFSFree; FVFSVersion: TVFSVersion; FVFSGetInfo: TVFSGetInfo; - FVFSOpen: TVFSOpen; + FVFSOpenArchive: TVFSOpenArchive; + FVFSOpenURI: TVFSOpenURI; FVFSClose: TVFSClose; FVFSListFirst: TVFSListFirst; FVFSListNext: TVFSListNext; @@ -39,7 +40,6 @@ type FVFSChangeDir: TVFSChangeDir; FVFSGetPath: TVFSGetPath; FVFSGetPathURI: TVFSGetPathURI; - FVFSGetPrefix: TVFSGetPrefix; FVFSGetFileSystemSize: TVFSGetFileSystemSize; FVFSGetFileSystemFree: TVFSGetFileSystemFree; FVFSFileExists: TVFSFileExists; @@ -72,7 +72,7 @@ type function GetHandlesNetwork: boolean; public ModuleHandle: Pointer; - FullPath: string; // module path + FullModulePath: string; // module path Extensions, Services: TOpenStringArray; // the list of the extensions plugin can handle constructor Create(PluginHandle: Pointer); destructor Destroy; override; @@ -94,9 +94,10 @@ type FSourcePlugin: TVFSPlugin; FBlockSize: Cardinal; BreakProcessingKind: integer; + FArchiveMode: boolean; + FArchivePath: string; function GetPluginID: string; public - ArchiveMode: boolean; Password: string; PasswordUsed: boolean; RemoveFileOnClose: string; @@ -140,7 +141,6 @@ type function FileCanRun(const FileName: string): boolean; override; function GetPath: string; override; procedure SetPath(Value: string); override; - function GetPrefix: string; override; function GetPathURI: string; function GetBlockSize: Cardinal; override; @@ -160,6 +160,8 @@ type property Path: string read GetPath write SetPath; property BlockSize: Cardinal read GetBlockSize write SetBlockSize; property PluginID: string read GetPluginID; + property ArchiveMode: boolean read FArchiveMode; + property ArchivePath: string read FArchivePath; end; @@ -204,7 +206,8 @@ begin @FVFSFree := dlsym(ModuleHandle, 'VFSFree'); @FVFSVersion := dlsym(ModuleHandle, 'VFSVersion'); @FVFSGetInfo := dlsym(ModuleHandle, 'VFSGetInfo'); - @FVFSOpen := dlsym(ModuleHandle, 'VFSOpen'); + @FVFSOpenArchive := dlsym(ModuleHandle, 'VFSOpenArchive'); + @FVFSOpenURI := dlsym(ModuleHandle, 'VFSOpenURI'); @FVFSClose := dlsym(ModuleHandle, 'VFSClose'); @FVFSListFirst := dlsym(ModuleHandle, 'VFSListFirst'); @FVFSListNext := dlsym(ModuleHandle, 'VFSListNext'); @@ -212,7 +215,6 @@ begin @FVFSGetPath := dlsym(ModuleHandle, 'VFSGetPath'); @FVFSGetPathURI := dlsym(ModuleHandle, 'VFSGetPathURI'); @FVFSChangeDir := dlsym(ModuleHandle, 'VFSChangeDir'); - @FVFSGetPrefix := dlsym(ModuleHandle, 'VFSGetPrefix'); @FVFSGetFileSystemSize := dlsym(ModuleHandle, 'VFSGetFileSystemSize'); @FVFSGetFileSystemFree := dlsym(ModuleHandle, 'VFSGetFileSystemFree'); @FVFSFileExists := dlsym(ModuleHandle, 'VFSFileExists'); @@ -245,14 +247,14 @@ begin // Initialize the extensions list SetLength(Extensions, 0); SetLength(Services, 0); - if @FVFSGetArchiveExts <> nil then begin + if (@FVFSGetArchiveExts <> nil) and (@FVFSOpenArchive <> nil) then begin s := FVFSGetArchiveExts; if s <> nil then begin ParseString(String(s), ';', Extensions); real_libc_free(s); end; end; - if @FVFSGetNetworkServices <> nil then begin + if (@FVFSGetNetworkServices <> nil) and (@FVFSOpenURI <> nil) then begin s := FVFSGetNetworkServices; if s <> nil then begin ParseString(String(s), ';', Services); @@ -328,12 +330,12 @@ end; function TVFSPlugin.GetHandlesArchives: boolean; begin - Result := Length(Extensions) > 0; + Result := (Length(Extensions) > 0) and (@FVFSOpenArchive <> nil); end; function TVFSPlugin.GetHandlesNetwork: boolean; begin - Result := Length(Services) > 0; + Result := (Length(Services) > 0) and (@FVFSOpenURI <> nil); end; (********************************************************************************************************************************) @@ -343,7 +345,8 @@ begin inherited Create; FSourcePlugin := SourcePlugin; FBlockSize := 65536; - ArchiveMode := False; + FArchiveMode := False; + FArchivePath := ''; BreakProcessingKind := 0; FGlobs := nil; Password := ''; @@ -370,10 +373,12 @@ end; function TVFSEngine.VFSOpenURI(URI: string; AskQuestionCallback: PVFSAskQuestionCallback; AskPasswordCallback: PVFSAskPasswordCallback; ProgressCallback: PVFSProgressCallback; CallbackData: Pointer): boolean; begin Result := False; - if (FGlobs <> nil) and (@FSourcePlugin.FVFSOpen <> nil) then begin + if (FGlobs <> nil) and (@FSourcePlugin.FVFSOpenURI <> nil) then begin if @FSourcePlugin.FVFSSetCallbacks <> nil then FSourcePlugin.FVFSSetCallbacks(FGlobs, AskQuestionCallback, AskPasswordCallback, ProgressCallback, CallbackData); - Result := FSourcePlugin.FVFSOpen(FGlobs, PChar(URI)) = cVFS_OK; + Result := FSourcePlugin.FVFSOpenURI(FGlobs, PChar(URI)) = cVFS_OK; + FArchiveMode := False; + FArchivePath := ''; if @FSourcePlugin.FVFSSetCallbacks <> nil then FSourcePlugin.FVFSSetCallbacks(FGlobs, nil, nil, nil, nil); end; @@ -382,10 +387,13 @@ end; function TVFSEngine.VFSOpenEx(OpenFile: string; AskQuestionCallback: PVFSAskQuestionCallback; AskPasswordCallback: PVFSAskPasswordCallback; ProgressCallback: PVFSProgressCallback; CallbackData: Pointer): TVFSResult; begin Result := cVFS_OK; - if (FGlobs <> nil) and (@FSourcePlugin.FVFSOpen <> nil) then begin + if (FGlobs <> nil) and (@FSourcePlugin.FVFSOpenArchive <> nil) then begin if @FSourcePlugin.FVFSSetCallbacks <> nil then FSourcePlugin.FVFSSetCallbacks(FGlobs, AskQuestionCallback, AskPasswordCallback, ProgressCallback, CallbackData); - Result := FSourcePlugin.FVFSOpen(FGlobs, PChar(OpenFile)); + Result := FSourcePlugin.FVFSOpenArchive(FGlobs, PChar(OpenFile)); + FArchiveMode := True; + if Result = cVFS_OK then FArchivePath := OpenFile + else FArchivePath := ''; if @FSourcePlugin.FVFSSetCallbacks <> nil then FSourcePlugin.FVFSSetCallbacks(FGlobs, nil, nil, nil, nil); end; @@ -550,19 +558,6 @@ begin FreeDataItem(Item); end; -function TVFSEngine.GetPrefix: string; -var s: PChar; -begin - Result := 'VFS'; - if (FGlobs <> nil) and (@FSourcePlugin.FVFSGetPrefix <> nil) then begin - s := FSourcePlugin.FVFSGetPrefix(FGlobs); - if s <> nil then begin - Result := String(s); - real_libc_free(s); - end; - end; -end; - function TVFSEngine.GetPath: string; var s: PChar; begin @@ -1128,7 +1123,7 @@ begin b := False; if PluginList.Count > 0 then for i := 0 to PluginList.Count - 1 do - if CompareStr(TVFSPlugin(PluginList[i]).FullPath, IncludeTrailingPathDelimiter(s) + Buf) = 0 then begin + if CompareStr(TVFSPlugin(PluginList[i]).FullModulePath, IncludeTrailingPathDelimiter(s) + Buf) = 0 then begin b := True; Break; end; @@ -1140,7 +1135,7 @@ begin @VFSVersionFunc := dlsym(ModuleHandler, 'VFSVersion'); if (@VFSVersionFunc <> nil) and (VFSVersionFunc = ConstVFSVersionRequired) then begin PluginItem := TVFSPlugin.Create(ModuleHandler); - PluginItem.FullPath := IncludeTrailingPathDelimiter(s) + Buf; + PluginItem.FullModulePath := IncludeTrailingPathDelimiter(s) + Buf; PluginList.Add(PluginItem); end else DebugMsg([' $XXX: Error getting version info or version mismatch']); except end; diff --git a/vfs/uVFSprototypes.pas b/vfs/uVFSprototypes.pas index 01a31d3..5da4bc9 100644 --- a/vfs/uVFSprototypes.pas +++ b/vfs/uVFSprototypes.pas @@ -184,7 +184,7 @@ type user_data: Pointer): LongBool; cdecl; type - // Log function which could plugin call - the application must handle the messages (e.g. write them to the stdout) + // Log function for plugin debugging output - host application will print or save these messages PVFSLogFunc = ^TVFSLogFunc; TVFSLogFunc = procedure(const S: PChar); cdecl; @@ -193,16 +193,10 @@ type TVFSFree = procedure (g: TVFSGlobs); cdecl; // Performs cleanup and destroy all objects TVFSVersion = function: integer; cdecl; - // Returns API Version; the host application checks for this number and if the returned number is less than a value required by the host application, the module is not loaded - // Please use the cVFSVersion constant as return value + // Returns VFS API Version; must match version hardcoded in the host program, otherwise the module is not loaded + // Please use the cVFSVersion constant as a return value TVFSGetInfo = function: PVFSInfo; cdecl; // Returns module info struct, tuxcmd will take care of memory deallocation - TVFSGetPrefix = function (g:TVFSGlobs): PChar; cdecl; - // Returns prefix used in the application to show difference between local and VFS filesystems (e.g. "ftp" or "smb") - // tuxcmd will take care of memory deallocation - TVFSGetCharset = function (g:TVFSGlobs): PChar; cdecl; - // TODO: Returns charset which the plugin uses - // tuxcmd will take care of memory deallocation TVFSGetArchiveExts = function: PChar; cdecl; // Returns the list of filename extensions which the module can handle separated by ';' (without a leading dots) // Returning NULL or not defining the symbol at all means plugin can't handle archives @@ -217,9 +211,11 @@ type // Sets the block size for I/O operations (not all modules supports this) - TVFSOpen = function (g:TVFSGlobs; const sName: PChar): TVFSResult; cdecl; - // TODO: Opens the location (file or URI/URL) - // In case of URI, do not supply password encoded in the string; plugin will automatically spawn the TVFSAskPasswordCallback callback + TVFSOpenArchive = function (g:TVFSGlobs; const sName: PChar): TVFSResult; cdecl; + // Opens specified archive. This will also switch plugin (an instance) into archiving mode + TVFSOpenURI = function (g:TVFSGlobs; const sURI: PChar): TVFSResult; cdecl; + // Opens specified network location. This will also switch plugin (an instance) into networking mode + // In case of URI, do not supply password encoded in the string; plugin will automatically spawn the TVFSAskPasswordCallback callback when needed TVFSClose = function (g:TVFSGlobs): TVFSResult; cdecl; // Closes the file or connection to the server TVFSMkDir = function (g:TVFSGlobs; const sDirName: PChar): TVFSResult; cdecl; -- cgit v1.2.3