summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--vfs/UVFSCore.pas90
-rw-r--r--vfs/uVFSprototypes.pas10
2 files changed, 42 insertions, 58 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;
diff --git a/vfs/uVFSprototypes.pas b/vfs/uVFSprototypes.pas
index df45ecb..6959a7b 100644
--- a/vfs/uVFSprototypes.pas
+++ b/vfs/uVFSprototypes.pas
@@ -135,15 +135,13 @@ type
PVFSLogFunc = ^TVFSLogFunc;
TVFSLogFunc = procedure(S: PChar); cdecl;
- TVFSAllocNeeded = function: integer; cdecl;
- // Returns sizeof internal structure of TVFSGlobs in the plugin - host application will then allocate corresponding amount of memory
- TVFSInit = procedure (g:TVFSGlobs; LogFunc: PVFSLogFunc); cdecl;
- // Performs intialization of the plugin and sets the log function for the module (assume allocated memory for TVFSGlobs)
- TVFSDestroy = procedure (g:TVFSGlobs); cdecl;
+ TVFSNew = function (LogFunc: PVFSLogFunc): TVFSGlobs; cdecl;
+ // Allocates memory for the globs structure and performs intialization of the plugin
+ 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
- // The current version for this API is '3' - please use the constant declared above as return value
+ // Please use the cVFSVersion constant as return value
TVFSGetInfo = function: TVFSInfo; cdecl;
// Returns the structure with module info
TVFSGetPrefix = function (g:TVFSGlobs): PChar; cdecl;