MTA:Eir/FileSystem/createFilesystemInterface: Difference between revisions

From Multi Theft Auto: Wiki
Jump to navigation Jump to search
No edit summary
mNo edit summary
 
(4 intermediate revisions by one other user not shown)
Line 1: Line 1:
__NOTOC__
__NOTOC__
This function creates a FileSystem access point. An access point is your personal instance of the MTA:Eir FileSystem. The table returned by this function is the module namespace. There are no limits as to how many access points can be live at a time.
This function creates a FileSystem access point. An access point is your personal instance of the Eir FileSystem. The table returned by this function is the module namespace. There are no limits as to how many access points can be live at a time.
 
'''When using the fileSystem module, it is highly suggested to restrict access to this function to priviledged resources!'''


==Syntax==
==Syntax==
Line 11: Line 13:


==Example==
==Example==
<section name="Client" class="client" show="true">
<section name="Server" class="server" show="true">
This snippet sets up access to your resource in a simple server-side resource environment when using the FileSystem module.
This snippet sets up access to your resource in a simple server-side resource environment when using the FileSystem module.
<syntaxhighlight lang="lua">
<syntaxhighlight lang="lua">
Line 29: Line 31:


-- Check that we have access (i.e. passed OS priviledges test) for this folder.
-- Check that we have access (i.e. passed OS priviledges test) for this folder.
-- Will fail is the resource is not inside a folder in the deathmatch resources directory.
-- Will fail if the resource is not inside a folder in the deathmatch resources directory.
if not ( resRoot ) then
if not ( resRoot ) then
     outputDebugString( "cannot link resource instance directory" );
     outputDebugString( "cannot link resource instance directory" );

Latest revision as of 21:50, 16 January 2022

This function creates a FileSystem access point. An access point is your personal instance of the Eir FileSystem. The table returned by this function is the module namespace. There are no limits as to how many access points can be live at a time.

When using the fileSystem module, it is highly suggested to restrict access to this function to priviledged resources!

Syntax

table createFilesystemInterface ()

Returns

This function returns the table that denotes the FileSystem module namespace.

Example

Click to collapse [-]
Server

This snippet sets up access to your resource in a simple server-side resource environment when using the FileSystem module.

-- Create the interface.
local fsys = createFilesystemInterface();

-- Make sure we have access to the module.
-- Access could be blocked by acl.xml priviledges.
if not ( fsys ) then
    outputDebugString( "could not create FileSystem interface" );
    return false;
end

-- Assume the resource is located inside a folder in the deathmatch resources directory.
-- Then we create a raw OS filesystem link to it.
local resRoot = fsys.createTranslator( "mods/deathmatch/resources/" .. getResourceName(resource) .. "/" );

-- Check that we have access (i.e. passed OS priviledges test) for this folder.
-- Will fail if the resource is not inside a folder in the deathmatch resources directory.
if not ( resRoot ) then
    outputDebugString( "cannot link resource instance directory" );
    return false;
end

-- Open the "meta.xml" file.
local metaFile = resRoot.open( "meta.xml", "rb" );

-- Success!

FileSystem Library Functions

FileSystem Namespace Functions

FileSystem Translator Functions

FileSystem Archive Translator Functions

FileSystem File Functions