diff options
| author | Tomas Bzatek <tbzatek@users.sourceforge.net> | 2008-10-05 12:24:55 +0200 |
|---|---|---|
| committer | Tomas Bzatek <tbzatek@users.sourceforge.net> | 2008-10-05 12:24:55 +0200 |
| commit | ace02c1d8fb3ae997efbac0a12d3bd0533bd93d9 (patch) | |
| tree | 843a5833424434aea08b32759f62392f010b1f8f /vfs/UVFSCore.pas | |
| parent | 87209148425d31a6fe4e60da57b729af2659bb4a (diff) | |
| download | tuxcmd-ace02c1d8fb3ae997efbac0a12d3bd0533bd93d9.tar.xz | |
Move plugin global data allocation back to the module
Diffstat (limited to 'vfs/UVFSCore.pas')
| -rw-r--r-- | vfs/UVFSCore.pas | 90 |
1 files changed, 38 insertions, 52 deletions
diff --git a/vfs/UVFSCore.pas b/vfs/UVFSCore.pas index 539295d..0237121 100644 --- a/vfs/UVFSCore.pas +++ b/vfs/UVFSCore.pas @@ -27,9 +27,8 @@ uses GTKForms, ULibc, Classes, uVFSprototypes, UEngines, UCoreUtils; type TVFSPlugin = class private - FVFSAllocNeeded: TVFSAllocNeeded; - FVFSInit: TVFSInit; - FVFSDestroy: TVFSDestroy; + FVFSNew: TVFSNew; + FVFSFree: TVFSFree; FVFSVersion: TVFSVersion; FVFSGetInfo: TVFSGetInfo; FVFSOpen: TVFSOpen; @@ -184,9 +183,8 @@ begin ModuleHandle := PluginHandle; // Find the symbols - @FVFSAllocNeeded := dlsym(ModuleHandle, 'VFSAllocNeeded'); - @FVFSInit := dlsym(ModuleHandle, 'VFSInit'); - @FVFSDestroy := dlsym(ModuleHandle, 'VFSDestroy'); + @FVFSNew := dlsym(ModuleHandle, 'VFSNew'); + @FVFSFree := dlsym(ModuleHandle, 'VFSFree'); @FVFSVersion := dlsym(ModuleHandle, 'VFSVersion'); @FVFSGetInfo := dlsym(ModuleHandle, 'VFSGetInfo'); @FVFSOpen := dlsym(ModuleHandle, 'VFSOpen'); @@ -292,57 +290,40 @@ begin FBlockSize := 65536; ArchiveMode := False; BreakProcessingKind := 0; - if @FSourcePlugin.FVFSAllocNeeded <> nil then begin - FGlobs := malloc(FSourcePlugin.FVFSAllocNeeded); - memset(FGlobs, 0, FSourcePlugin.FVFSAllocNeeded); - end else begin - FGlobs := malloc(SizeOf(FGlobs)); - memset(FGlobs, 0, SizeOf(FGlobs)); - end; - -{ - DebugMsg(['sizeof(TVFSItem) = ', sizeof(TVFSItem)]); - DebugMsg(['sizeof(TVFSItem.FName) = ', sizeof(TVFSItem.FName)]); - DebugMsg(['sizeof(TVFSItem.iSize) = ', sizeof(TVFSItem.iSize)]); - DebugMsg(['sizeof(TVFSItem.m_time) = ', sizeof(TVFSItem.m_time)]); - DebugMsg(['sizeof(TVFSItem.a_time) = ', sizeof(TVFSItem.a_time)]); - DebugMsg(['sizeof(TVFSItem.c_time) = ', sizeof(TVFSItem.c_time)]); - DebugMsg(['sizeof(TVFSItem.iMode) = ', sizeof(TVFSItem.iMode)]); - DebugMsg(['sizeof(TVFSItem.sLinkTo) = ', sizeof(TVFSItem.sLinkTo)]); - DebugMsg(['sizeof(TVFSItem.iUID) = ', sizeof(TVFSItem.iUID)]); - DebugMsg(['sizeof(TVFSItem.iGID) = ', sizeof(TVFSItem.iGID)]); - DebugMsg(['sizeof(TVFSItem.ItemType) = ', sizeof(TVFSItem.ItemType)]); -} - if @FSourcePlugin.FVFSInit <> nil then FSourcePlugin.FVFSInit(FGlobs, @VFSLogFunc); + FGlobs := nil; FPassword := ''; + + if @FSourcePlugin.FVFSNew <> nil then FGlobs := FSourcePlugin.FVFSNew(@VFSLogFunc); +end; + +destructor TVFSEngine.Destroy; +begin + try + if @FSourcePlugin.FVFSFree <> nil then FSourcePlugin.FVFSFree(FGlobs); + except + on E: Exception do DebugMsg(['*** TVFSEngine.Destroy() -Exception: ', E.Message]); + end; end; function TVFSEngine.VFSOpenURI(OpenFile: string): boolean; begin Result := False; - if @FSourcePlugin.FVFSOpen <> nil then Result := FSourcePlugin.FVFSOpen(FGlobs, PChar(OpenFile)) = cVFS_OK; + if (FGlobs <> nil) and (@FSourcePlugin.FVFSOpen <> nil) + then Result := FSourcePlugin.FVFSOpen(FGlobs, PChar(OpenFile)) = cVFS_OK; end; function TVFSEngine.VFSOpenEx(OpenFile: string): TVFSResult; begin Result := cVFS_OK; - if @FSourcePlugin.FVFSOpen <> nil then Result := FSourcePlugin.FVFSOpen(FGlobs, PChar(OpenFile)); + if (FGlobs <> nil) and (@FSourcePlugin.FVFSOpen <> nil) + then Result := FSourcePlugin.FVFSOpen(FGlobs, PChar(OpenFile)); end; function TVFSEngine.VFSClose: boolean; begin Result := False; - if @FSourcePlugin.FVFSClose <> nil then Result := FSourcePlugin.FVFSClose(FGlobs) = cVFS_OK; -end; - -destructor TVFSEngine.Destroy; -begin - try - if @FSourcePlugin.FVFSDestroy <> nil then FSourcePlugin.FVFSDestroy(FGlobs); - libc_free(FGlobs); - except - on E: Exception do DebugMsg(['*** TVFSEngine.Destroy() -Exception: ', E.Message]); - end; + if (FGlobs <> nil) and (@FSourcePlugin.FVFSClose <> nil) + then Result := FSourcePlugin.FVFSClose(FGlobs) = cVFS_OK; end; function TVFSEngine.GetListing(var List: TList; const AddDotFiles: boolean; APath: string): integer; @@ -457,7 +438,7 @@ end; function TVFSEngine.GetFileSystemSize(const APath: string): Int64; begin - if @FSourcePlugin.FVFSGetFileSystemSize <> nil + if (FGlobs <> nil) and (@FSourcePlugin.FVFSGetFileSystemSize <> nil) then Result := FSourcePlugin.FVFSGetFileSystemSize(FGlobs, PChar(APath)) else Result := 0; end; @@ -469,7 +450,7 @@ end; function TVFSEngine.GetFileSystemFree(const APath: string): Int64; begin - if @FSourcePlugin.FVFSGetFileSystemFree <> nil + if (FGlobs <> nil) and (@FSourcePlugin.FVFSGetFileSystemFree <> nil) then Result := FSourcePlugin.FVFSGetFileSystemFree(FGlobs, PChar(APath)) else Result := 0; end; @@ -496,14 +477,16 @@ end; function TVFSEngine.GetPrefix: string; begin - if @FSourcePlugin.FVFSGetPrefix <> nil then Result := URIHidePassword(FSourcePlugin.FVFSGetPrefix(FGlobs)) - else Result := 'VFS'; + if (FGlobs <> nil) and (@FSourcePlugin.FVFSGetPrefix <> nil) + then Result := URIHidePassword(FSourcePlugin.FVFSGetPrefix(FGlobs)) + else Result := 'VFS'; end; function TVFSEngine.GetPath: string; begin - if @FSourcePlugin.FVFSGetPath <> nil then Result := FSourcePlugin.FVFSGetPath(FGlobs) - else Result := '/'; + if (FGlobs <> nil) and (@FSourcePlugin.FVFSGetPath <> nil) + then Result := FSourcePlugin.FVFSGetPath(FGlobs) + else Result := '/'; end; function TVFSEngine.ChangeDir(const NewPath: string; const ShowProgress: boolean = True): integer; @@ -526,14 +509,16 @@ end; function TVFSEngine.Login(Username, Password: string): integer; begin - if @FSourcePlugin.FVFSLogin <> nil then Result := FSourcePlugin.FVFSLogin(FGlobs, PChar(Username), PChar(Password)) - else Result := cVFS_OK; + if (FGlobs <> nil) and (@FSourcePlugin.FVFSLogin <> nil) + then Result := FSourcePlugin.FVFSLogin(FGlobs, PChar(Username), PChar(Password)) + else Result := cVFS_OK; end; function TVFSEngine.FileExists(const FileName: string; const Use_lstat: boolean = False): Boolean; begin - if @FSourcePlugin.FVFSFileExists <> nil then Result := FSourcePlugin.FVFSFileExists(FGlobs, PChar(FileName), Use_lstat) - else Result := False; + if (FGlobs <> nil) and (@FSourcePlugin.FVFSFileExists <> nil) + then Result := FSourcePlugin.FVFSFileExists(FGlobs, PChar(FileName), Use_lstat) + else Result := False; end; function TVFSEngine.DirectoryExists(const FileName: string; const Use_lstat: boolean = False): Boolean; @@ -771,7 +756,8 @@ end; procedure TVFSEngine.SetBlockSize(Value: Cardinal); begin - if @FSourcePlugin.FVFSSetBlockSize <> nil then FSourcePlugin.FVFSSetBlockSize(FGlobs, Value); + if (FGlobs <> nil) and (@FSourcePlugin.FVFSSetBlockSize <> nil) + then FSourcePlugin.FVFSSetBlockSize(FGlobs, Value); end; |
