Перейти к основному содержанию

FileTools

Module that provides methods to work with file system.

Index

Variables

constmntdir

mntdir: string

Defines path to mounted devices directory (e.g. /mnt).

constmoddir

moddir: string

Defines in-pack directory where modders alives with trailing slash (e.g. /storage/emulated/0/games/horizon/packs/Inner_Core_Test/innercore/mods/, /storage/emulated/0/Android/data/com.zheka.horizon/files/games/horizon/packs/Inner_Core_Test/innercore/mods/).

constroot

root: string

Defines external user directory path with trailing slash (e.g. /sdcard/, /storage/emulated/0/).

Functions

GetListOfDirs

  • GetListOfDirs(path: string): java.io.File[]
  • Lists children directories for the specified path.


    Parameters

    • path: string

      home-relative or absolute path to the file

    Returns java.io.File[]

    JArray of java.io.File instances of listed directories.

GetListOfFiles

  • GetListOfFiles(path: string, ext?: string): java.io.File[]
  • Lists files in the specified directory.


    Parameters

    • path: string

      path to directory to look for files in

    • optionalext: string

      extension of the files to include to the output

    Returns java.io.File[]

    JArray of java.io.File instances that match specified extension.

ReadBytesAsset

  • Reads bytes array from assets.


    Parameters

    • name: string

      asset name

    Returns Nullable<native.Array<jbyte>>

    JArray of bytes read from assets or null if asset doesn't exist.

ReadImage

  • ReadImage(file: string): Nullable<android.graphics.Bitmap>
  • Reads high-resolution (as-is) bitmap from file.


    Parameters

    • file: string

      home-relative or absolute path to the file

    Returns Nullable<android.graphics.Bitmap>

    object of the bitmap that was read from file or null if file does not exist or is not accessible.

ReadImageAsset

  • ReadImageAsset(name: string): Nullable<android.graphics.Bitmap>
  • Reads high-resolution (as-is) bitmap from asset by it's full name.


    Parameters

    • name: string

      asset name

    Returns Nullable<android.graphics.Bitmap>

    Object of the bitmap that was read from asset or null, if asset doesn't exist.

ReadJSON

  • ReadJSON(dir: string): object
  • Reads JSON file without comments as object.


    Parameters

    • dir: string

      home-relative or absolute path to the file

    Returns object

    Object represents JSON value read from JSON file.

ReadKeyValueFile

  • ReadKeyValueFile(dir: string, specialSeparator?: string): {}
  • Reads file as <key>:<value> pairs.


    Parameters

    • dir: string

      home-relative or absolute path to the file

    • optionalspecialSeparator: string

      separator between key and value, ":" by default

    Returns {}

    Object containing <key>:<value> pairs from file.

    • [key string]: string

ReadText

  • ReadText(file: string): Nullable<string>
  • Reads text as-is from file, append ?.trim() to drop trailing newlines.


    Parameters

    • file: string

      home-relative or absolute path to the file

    Returns Nullable<string>

    File contents or null if file does not exist or not accessible.

ReadTextAsset

  • ReadTextAsset(name: string): Nullable<string>
  • Reads string from asset by it's full name.


    Parameters

    • name: string

      asset name

    Returns Nullable<string>

    Asset contents or null if asset doesn't exist.

WriteImage

  • WriteImage(file: string, bitmap: Bitmap): void
  • Writes bitmap to PNG (lossless and transparent extension) file.


    Parameters

    • file: string

      home-relative or absolute path to the file

    • bitmap: Bitmap

      android.graphics.Bitmap to be written to the file

    Returns void

WriteJSON

  • WriteJSON(dir: string, obj: object, beautify?: boolean): void
  • Writes object to file as JSON.


    Parameters

    • dir: string

      home-relative or absolute path to the file

    • obj: object

      object to be written to the file as JSON

    • optionalbeautify: boolean

      if true, output JSON is beautified with tabs

    Returns void

WriteKeyValueFile

  • WriteKeyValueFile(dir: string, data: object, specialSeparator?: string): void
  • Writes <key>:<value> pairs to the file.


    Parameters

    • dir: string

      home-relative or absolute path to the file

    • data: object

      object to be written to the file as a set of key:value pairs

    • optionalspecialSeparator: string

      separator between key and value, ":" by default

    Returns void

WriteText

  • WriteText(file: string, text: string, add?: boolean): void
  • Writes text to the file.


    Parameters

    • file: string

      home-relative or absolute path to the file

    • text: string

      text to be written to the file

    • optionaladd: boolean

      if true, appends text to the file, overrides it otherwise

    Returns void

getFullPath

  • getFullPath(path: string): string
  • Converts home-relative path to absolute.


    Parameters

    • path: string

      input path

    Returns string

    Same string if input string is an absolute path, an absolute path if input string is a home-relative path.

isExists

  • isExists(path: string): boolean
  • Verifies if specified home-relative or absolute path exists.


    Parameters

    • path: string

      path to be verified

    Returns boolean

    true, if specified path exists, false otherwise.

mkdir

  • mkdir(dir: string): void
  • Creates directory by it's home-relative or absolute path, if one of the parent directories doesn't exist, creates them.


    Parameters

    • dir: string

      path to the new directory

    Returns void

mkworkdirs

  • mkworkdirs(): void
  • internal

    Creates Core Engine working directories.


    Returns void