Difference between revisions of "TFile.CheckAccess"

From Soldat Community Wiki
Jump to: navigation, search
m (Example)
(Path syntax)
 
(2 intermediate revisions by 2 users not shown)
Line 8: Line 8:
 
Path to a file should be passed in unix-like syntax (slashes, not backslashes) where first character determinates where is the start point:
 
Path to a file should be passed in unix-like syntax (slashes, not backslashes) where first character determinates where is the start point:
  
* ''/'': if path begins from slash (/), it's assumed to start from hard disk root ("root / folder on unix, Disk on which soldatserver is located on windows (i.e. C:\). Script must be configured with [[Config|Sandboxed]] level 0 in order to be able to access entire host's harddrive.
+
* ''/'': if path begins from slash (/), it's assumed to start from hard disk root ("root / folder on unix, Disk on which soldatserver is located on windows (i.e. C:\). Script must be configured with [[ScriptCore3_config_file|Sandboxed]] level 0 in order to be able to access entire host's harddrive.
* ''~'': if path begins from tylda (~), it's assumed to start from script's data directory (soldatserver/scripts/yourscriptname/data/).
+
* ''~'': if path begins from tilde (~), it's assumed to start from script's data directory (soldatserver/scripts/yourscriptname/data/).
* Any else character is assumed to be part of the path and start point is set to soldatserver's directory, i.e. 'soldat.ini' points to soldatserver/soldat.ini. Script must be configured with [[Config|Sandboxed]] level 1 or 0 in order to be able to access anything above it's data directory.
+
* Any else character is assumed to be part of the path and start point is set to soldatserver's directory, i.e. ''[[soldat.ini]]'' points to soldatserver/soldat.ini. Script must be configured with [[ScriptCore3_config_file|Sandboxed]] level 1 or 0 in order to be able to access anything above it's data directory.
  
 
== Example ==
 
== Example ==

Latest revision as of 21:43, 16 April 2018

function CheckAccess(const FilePath: string): Boolean
 FilePath: a path to a file to check access for
 Result: Whenever file is accessible from script's sandbox or not

Description

This function checks whenever file pointed by FilePath can be opened by script's File API.

Path syntax

Path to a file should be passed in unix-like syntax (slashes, not backslashes) where first character determinates where is the start point:

  • /: if path begins from slash (/), it's assumed to start from hard disk root ("root / folder on unix, Disk on which soldatserver is located on windows (i.e. C:\). Script must be configured with Sandboxed level 0 in order to be able to access entire host's harddrive.
  • ~: if path begins from tilde (~), it's assumed to start from script's data directory (soldatserver/scripts/yourscriptname/data/).
  • Any else character is assumed to be part of the path and start point is set to soldatserver's directory, i.e. soldat.ini points to soldatserver/soldat.ini. Script must be configured with Sandboxed level 1 or 0 in order to be able to access anything above it's data directory.

Example

begin
  if File.CheckAccess('soldat.ini') then
    WriteLn('soldat ini seems to be accessible!')
  else
    WriteLn('access to soldat.ini denied.');
end;