This page has been translated automatically.
UnigineScript
The Language
Core Library
Engine Library
Node-Related Classes
GUI-Related Classes
Plugins Library
High-Level Systems
Samples
C++ API
API Reference
Integration Samples
Usage Examples
C++ Plugins
Content Creation
Materials
Unigine Material Library
Tutorials
Warning! This version of documentation is OUTDATED, as it describes an older SDK version! Please switch to the documentation for the latest SDK version.
Warning! This version of documentation describes an old SDK version which is no longer supported! Please upgrade to the latest SDK version.

engine.filesystem Functions

These set of functions allows for the following:

  • Gives control over loading of files under the data directory, including files in ZIP and UNG packages. Such packages are automatically handled by the engine and all their files are automatically added to the file system.
  • Allows to add ZIP and UNG packages that are outside the data directory. After that, files in them are accessed in a usual way, by specifying a path to the file only inside the package.
  • Allows to add directories (even with ZIP and UNG packages) that are outside the data directory by specifying a link to it in a *.ulink.

Additionally, modifiers for files can be used (see details below).

Loading Files on Demand

To load files on demand, call these functions in the following order:

  1. First engine.filesystem.loadFile() function is called to place the file in the queue for loading.
  2. After that, different operations can be performed:

Adding Directories via ULINK

To add a directory that is outside the data directory, add a special file that contains a link to this directory. This link file has *.ulink extension and is stored anywhere inside data. When the engine scans through files and comes across such link file, it adds all files from the specified directory. If ZIP and UNG packages are found between them, they are also added to the file system.

  • A directory path inside can be specified relative to the data directory. It must end with a slash:
    Source code
    ../../my_project/resources/
    
  • An absolute path can be specified (slash in the end is required).
    For example, on Windows:
    Source code
    D:\resources\
    
    On Linux or Mac OS X:
    Source code
    /username/resources/
    

Using Modifiers

FileSystem can handle modifiers for files and folders, for example, file.ps3.node, texture.eng.dds or folder.android. Modifiers allow to store in one project folder and load different resources depending on the localization language or platform on which the application is run.

  • Only one modifier per file or folder can be used. If a folder has a modifier, files inside of it should not have modifiers.
  • Files without modifiers have the lowest priority when loading.

To be handled, modifiers need to be registered first via engine.filesystem.addModifier().

int engine.filesystem.addBufferFile (string name)

Buffers a file in the memory. It can be used for files that are frequently modified in run-time (for example, images). After such file is loaded from a disk and written into a buffer in the memory, its modifications can be saved fast into this buffer.

Arguments

  • string name - File to add into a buffer.

Return value

1 if the file is successfully added into a buffer; otherwise, 0.

int engine.filesystem.addCacheFile (string name)

Caches a file in the memory. It can be used for files that are accessed multiple times in run-time (for example, textures are read two times in a row). Such files are loaded into the memory for faster reading.

Arguments

  • string name - File to add to a cache.

Return value

1 if the file is successfully added to a cache; otherwise, 0.

void engine.filesystem.addModifier (string name)

Registers a new modifier in the file system.

Arguments

  • string name - Modifier name.

int engine.filesystem.checkFile (string name)

Checks whether the file was loaded to the queue or not.

Arguments

  • string name - File name.

Return value

1 if the file is loaded to the file system; otherwise - 0.

int engine.filesystem.checkImage (string name)

Checks whether the image was loaded to the queue or not.

Arguments

  • string name - Name of the image.

Return value

1 if the image is loaded to the file system; otherwise - 0.

int engine.filesystem.checkMesh (string name)

Returns the value indicating if the mesh is loaded to the queue.

Arguments

  • string name - Mesh name.

Return value

1 if the mesh is loaded to the file system successfully; otherwise 0.

void engine.filesystem.clearModifiers ()

Unregister all modifiers in the file system.

int engine.filesystem.findPackage (string name)

Checks if an UNG or ZIP package has been added into the file system.

Arguments

  • string name - Package name. It can be an absolute path or a path relative to data (data_path) directory, if it is inside of it.

Return value

Number of the ZIP or UNG package, or -1 if it is not found.

int engine.filesystem.forceFile (string name)

Loads the pending file immediately after calling the function. (This means that the file will be loaded right after the currently loading file (if any) is processed). All other file system operations are suspended until the forced file is loaded.

Arguments

  • string name - File name.

Return value

1 if the file is successfully loaded; otherwise - 0.

int engine.filesystem.forceImage (string name)

Loads the pending image immediately after calling the function. (This means that the image will be loaded right after the currently loading image (if any) is processed). All other file system operations are suspended until the forced image is loaded.

Arguments

  • string name - Name of the image.

Return value

1 if the image is successfully loaded; otherwise - 0.

int engine.filesystem.forceMesh (string name)

Loads the pending mesh immediately after the function call. This means that the mesh will be loaded right after the currently loading mesh (if any) is processed. All other file system operations are suspended until the forced mesh is loaded.

Arguments

  • string name - Mesh name.

Return value

1 if the mesh is loaded successfully; otherwise 0.

string engine.filesystem.getFileName (string name)

Returns the absolute path to the file by the given partial one.

Arguments

  • string name - File name or the partial path to it.

Return value

Absolute file path.

void engine.filesystem.getFileNames (int names)

Returns the list of unarchived files cached by the file system.

Arguments

  • int names - ID of return array with file names.

Image engine.filesystem.getImage (string name)

Checks whether the image is placed to the loading queue and return it if it is placed.

Arguments

  • string name - Name of the image.

Return value

The image if it is in the queue, otherwise - 0.

long engine.filesystem.getMTime (string n)

Returns the time of the file last modification.

Arguments

  • string n - File name.

Return value

Time of the last modification. If no modifications are made, -1 will be returned.

Mesh engine.filesystem.getMesh (string name)

Checks whether the mesh is placed to the loaded queue and return it if it is placed.

Arguments

  • string name - Mesh name.

Return value

The mesh if it is in the queue; otherwise 0.

string engine.filesystem.getModifier (int num)

Returns the name of the given modifier.

Arguments

  • int num - ID number of the modifier.

Return value

Modifier name.

int engine.filesystem.getNumFiles ()

Returns the number of files cached by the file system.

Return value

Number of cached files.

int engine.filesystem.getNumModifiers ()

Returns the total number of file modifiers registered in the file system.

Return value

Number of modifiers.

int engine.filesystem.getNumPackageFiles (int num)

Returns the number of files inside of a given ZIP or UNG package.

Arguments

  • int num - Number of the ZIP or UNG package.

Return value

Number of files inside a package.

int engine.filesystem.getNumPackages ()

Returns the number of ZIP and UNG packages inside data_path directory.

Return value

Number of packages.

int engine.filesystem.getNumQueuedData ()

Returns the number of queued file system data waiting for background loading. The return value also includes the currently processed data.

Return value

Number of queued file system data including the currently processed data.

int engine.filesystem.getNumQueuedFiles ()

Returns the number of queued files waiting for the background loading. The return value also includes the currently processed file.

Return value

Number of queued files including the currently processed file.

int engine.filesystem.getNumQueuedImages ()

Returns the number of queued images waiting for the background loading. The return value also includes the currently processed image.

Return value

Number of queued images including the currently processed image.

int engine.filesystem.getNumQueuedMeshes ()

Returns the number of queued meshes waiting for the background loading. The return value also includes the currently processed mesh.

Return value

Number of queued meshes including the currently processed mesh.

int engine.filesystem.getNumQueuedResources ()

Returns the number of queued file system resources waiting for the background loading. The return value represents the sum of the queued and the currently processed data, files, images and meshes.

Return value

Number of queued file system resources including the currently processed resources.

string engine.filesystem.getPackageFileName (int num, string name)

Returns the full path with a file name relative to the package root directory given only the file name.

Arguments

  • int num - Number of the ZIP or UNG package.
  • string name - File name.

Return value

A path.

void engine.filesystem.getPackageFileNames (int num, int names)

Returns the list of files in the specified ZIP or UNG package.

Arguments

  • int num - Number of the ZIP or UNG package.
  • int names - ID of return array with file names.

string engine.filesystem.getPackageName (int num)

Returns a name of a given ZIP or UNG package.

Arguments

  • int num - Number of the ZIP or UNG package.

Return value

Name of the package.

float engine.filesystem.getTotalTime ()

Returns the total time (in milliseconds) of loading a file system resource.

Return value

The total time value, milliseconds.

int engine.filesystem.isBufferFile (string name)

Checks if the given file is loaded into a buffer.

Arguments

  • string name - File to check.

Return value

1 if the file was added into a buffer; otherwise, 0.

int engine.filesystem.isCacheFile (string name)

Checks if the given file is loaded into a cache.

Arguments

  • string name - File to check.

Return value

1 if the file was added into a cache; otherwise, 0.

int engine.filesystem.isFile (string name)

Checks if a given file exists in the file system.

Arguments

  • string name - File name.

Return value

1 if the file is found; otherwise, 0.

int engine.filesystem.isKnownFile (string name)

Checks if the given file is known to the filesystem.

Arguments

  • string name - Name of the file.

Return value

1 if the file is known to the filesystem; otherwise, 0.

int engine.filesystem.isPackageFile (int num, string name)

Checks if the given file exists in the package.

Arguments

  • int num - Number of the ZIP or UNG package.
  • string name - File name.

Return value

1 if the file exists; otherwise, 0.

int engine.filesystem.loadFile (string name, int priority, float weight)

Adds a file to the background loading queue. Files with identical priorities and weights are loaded in the alphabetical order.

Arguments

  • string name - File name.
  • int priority - Group of the priority, 0 by default. Greater priority means faster loading.
  • float weight - Greater weight means faster loading inside the same priority group. Default value is 0.

Return value

1 if the file was successfully appended to the queue, 0 if the operation failed.

int engine.filesystem.loadImage (string name, int priority, float weight)

Adds an image to the background loading queue. Images with the identical groups and weights are loaded in the alphabetical order.

Arguments

  • string name - Name of the image.
  • int priority - Group of the priority, 0 by default. Greater priority means faster loading.
  • float weight - Greater weight means faster loading inside the same priority group. Default value is 0.

Return value

1 if the image was successfully appended to the queue, otherwise - 0.

int engine.filesystem.loadMesh (string name, int group, float weight)

Adds a mesh to the loading queue. Meshes with the identical groups and weights are loaded in the alphabetical order.

Arguments

  • string name - Mesh name.
  • int group - Group of the loading priority. Greater priority means faster loading.
  • float weight - Weight of the priority inside the group. Greater weight means faster loading inside the same priority group.

Return value

1 if the mesh was successfully appended to the queue; otherwise 0.

int engine.filesystem.loadPackage (string name, string extension)

Loads an UNG or ZIP package into the file system. An archive can be located outside data directory if an absolute path is specified.

Arguments

  • string name - Package name. It can be an absolute path or a path relative to data (data_path) directory, if it is inside of it.
  • string extension - ung or zip package extension.

Return value

1 if the package is loaded; otherwise, 0.

int engine.filesystem.removeBufferFile (string name)

Removes a buffer with a file from the memory. Buffering can be used for files that are frequently modified in run-time (for example, images). After such file is loaded from a disk and written into a buffer in the memory, its modifications can be saved fast into this buffer.

Arguments

  • string name - File to be removed from a buffer.

Return value

1 if the file is successfully removed from a buffer; otherwise, 0.

int engine.filesystem.removeCacheFile (string name)

Removes a cache with a file from the memory. Caching can be used for files that are accessed multiple times in run-time (for example, textures are read two times in a row). Such files are loaded into the memory for faster reading.

Arguments

  • string name - File to be removed from a cache.

Return value

1 if the file is successfully removed from a cache; otherwise, 0.

int engine.filesystem.removeFile (string name)

Removes a pending file from the loading queue.

Arguments

  • string name - File name.

Return value

1 if the file was successfully removed, otherwise - 0.

int engine.filesystem.removeImage (string name)

Removes a pending image from the loading queue.

Arguments

  • string name - Name of the image.

Return value

1 if the image was successfully removed, otherwise - 0.

int engine.filesystem.removeMesh (string name)

Removes a pending mesh from the loading queue.

Arguments

  • string name - Mesh name.

Return value

1 if the mesh is removed successfully; otherwise 0.

void engine.filesystem.removeModifier (string name)

Unregisters a given modifier in the file system.

Arguments

  • string name - Modifier name.

int engine.filesystem.removePackage (string name)

Unloads an UNG or ZIP package from the file system. An archive can be located outside data directory if an absolute path is specified.

Arguments

  • string name - Package name. It can be an absolute path or a path relative to data (data_path) directory, if it is inside of it.

Return value

1 if the package is removed; otherwise, 0.

int engine.filesystem.setMTime (string name, long time)

Sets the time of the file last modification.

Arguments

  • string name - File name.
  • long time - Time stamp to set.

Return value

1 if the time stamp is set successfully; otherwise, 0.

Examples

Source code (UnigineScript)
// specify a name of a file located under the data directory
string name = "test.cpp";
// assign the current time stamp value to the variable
long time = engine.filesystem.getMTime(name);
// print the updated time stamp of the test.cpp
log.message("engine.filesystem.setMTime() return value: %d\n",engine.filesystem.setMTime(name,10L));
// print the saved and current time stamps to compare
log.message("Saved time stamp: %d\nUpdated time stamp: %d\n",time,engine.filesystem.getMTime(name));
		
Output
engine.filesystem.setMTime() return value: 1
Saved time stamp: 1404213050
Updated time stamp: 10
		

int engine.filesystem.validateFile (string name)

Checks whether the pending file placed in the loading queue has been loaded.

Arguments

  • string name - File name.

Return value

1 if the file has been loaded; 0 if it is still pending in the queue.
Last update: 2017-07-03
Build: ()